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

Removed deprecated log levels and fixed inconsistent use of LevelFactory #578

Merged
merged 2 commits into from
Nov 1, 2022

Conversation

danielmorell
Copy link
Collaborator

@danielmorell danielmorell commented Oct 31, 2022

Description of the change

1. Removed deprecated code from Level

The first major change removes some deprecated constants and the __callStatic() from the Rollbar\Payload\Level class. These have been deprecated since v1.2.0, and it seems like now is a good time to remove them. This means that, although deprecated, a Level instance could be constructed by calling Level::ERROR(). This was very concise but lacked any type annotations or consistency. The LevelTest.php file shows this.

2. Refactored LevelFactory with static methods

The second major change is changing the public LevelFactory methods to be static and replacing the LevelFactory::init() method with the LevelFactory::getLevels() method. This change eliminates the need to instantiate LevelFactory before calling any methods. Creating a valid new Level instance is more verbose than I like. Making the methods static reduces the total code needed to validate and create a new Level. See the examples below.

// v1.2.0
$levelObject = Level::ERROR();
// v1.2.1+
$levelFactory = new LevelFactory();
$levelObject = $levelFactory->fromName(Level::ERROR);
// v4.0.0
$levelObject = LevelFactory::fromName(Level::ERROR);

Perhaps in a PHP 8.1 and above world we can use a backed enum and a few methods with match expressions to eliminate the need for the LevelFactory class entirely.

3. Replaced instances of LevelFactory with static method calls

The third significant change is removing the $levelFactory property from the Rollbar\Config, Rollbar\DataBuilder, and Rollbar\RollbarLogger classes. Since the LevelFactory methods can now be called statically, we no longer need instances of LevelFactory easily accessible on these classes.

This has the possibility to introduce a change in behavior. It was possible for someone to provide their own level factory class when instantiating DataBuilder. However, I don't think this would be likely or work very well since RollbarLogger attempts to validate the level using our LevelFactory class before it gets to DataBuilder.

With only partial support for a custom level factory theoretically available this feels like something that should be cleaned up. We should use one level factory across the codebase. Either provided by the user or our own. Support for a custom level factory is undocumented, partial, and probably just a bad idea anyway. Because of that I have completely removed it.

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 this to the v4.0.0 milestone Oct 31, 2022
@danielmorell danielmorell added the Type: Maintenance General up-keep, or changes that tidy an existing component or process. label Oct 31, 2022
Copy link

@cyrusradfar cyrusradfar left a comment

Choose a reason for hiding this comment

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

gave feedback directly, thank you for cleaning this up and aligning us more w the standard

@danielmorell danielmorell merged commit db0b3f9 into next/4.0/main Nov 1, 2022
@danielmorell danielmorell deleted the updated-level branch November 1, 2022 11:13
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.

None yet

2 participants