Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed IStrategy to StrategyInterface updated Truncation #580

Merged
merged 1 commit into from
Nov 18, 2022

Conversation

danielmorell
Copy link
Collaborator

The previous IStrategy interface suffers from a few issues.

  1. It does not fit our current naming convention. We use <name>Interface for all other interfaces while it uses I<name>.
  2. The type definitions in the method PHPDoc were incorrect. For example the @return tag for IStrategy::applies() specifies the return type as array. However, all the classes that implement the interface a bool is returned. Additionally, a bool is clearly expected when the applies() method is called...
    if (!$strategy->applies($payload)) {
  3. The interface is missing any documentation explaining the expected behavior and use of the methods it describes.

Description of the change

These core issues perpetuated themselves through the implementations of the IStrategy interface. To resolve all of this, I have done the following...

  1. Renamed IStrategy to StrategyInterface.
  2. Added type annotations to the interface method signatures.
  3. Updated the PHPDoc for the interface methods so that the expected behavior is documented and the types match.
  4. Updated the type annotations on all implementations of the StrategyInterface starting with the AbstractStrategy.

The updates to the interface would cause a BC since some user's custom truncation classes may not be complient with the interface anymore.

I also took the opportunity to clean up and document what each truncation strategy does and how payload truncation itself works. While doing so I also cleaned up some minor code quality issues. (This PR is mostly adding method PHPDocs). However, there are a few important code changes...

  1. Custom truncation strategy validation was changed from requiring a custom strategy class extend the AbstractStrategy to now require it implement StrategyInterface. Any class that extends AbstractStrategy will still pass the validation.
  2. FramesStrategy::selectFrames() is now a static method. This change was introduced because an instance of FramesStrategy was being instantiated by MinBodyStrategy just so selectFrames() could be called.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Maintenance
  • New release

Related issues

None

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers assigned
  • Issue from task tracker has a link to this pull request
  • Changes have been reviewed by at least one other engineer

@danielmorell danielmorell added the Type: Maintenance General up-keep, or changes that tidy an existing component or process. label Nov 17, 2022
@danielmorell danielmorell added this to the v4.0.0 milestone Nov 17, 2022
Copy link
Contributor

@waltjones waltjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice to see tech debt paid down.

@danielmorell danielmorell merged commit a221249 into next/4.0/main Nov 18, 2022
@danielmorell danielmorell deleted the next/4.0/update-truncation branch November 18, 2022 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Maintenance General up-keep, or changes that tidy an existing component or process.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants