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

Convert level/levelName to enums #1656

Merged
merged 2 commits into from Apr 19, 2022
Merged

Convert level/levelName to enums #1656

merged 2 commits into from Apr 19, 2022

Conversation

Seldaek
Copy link
Owner

@Seldaek Seldaek commented Apr 18, 2022

Refs #1648

See Monolog\Level & Monolog\LevelName

@Seldaek Seldaek added this to the 3.x milestone Apr 18, 2022
@Seldaek Seldaek mentioned this pull request Apr 18, 2022
8 tasks
@@ -30,11 +28,11 @@
'cast_spaces' => ['space' => 'single'],
'header_comment' => ['header' => $header],
'include' => true,
'class_attributes_separation' => ['elements' => ['method']],
'class_attributes_separation' => array('elements' => array('method' => 'one', 'trait_import' => 'none')),
Copy link
Contributor

Choose a reason for hiding this comment

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

why not keeping short arrays ?

Logger::ALERT => 'error',
Logger::EMERGENCY => 'error',
];
protected function toWildfireLevel(Level $level): string
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it protected while it was private before ?

@@ -203,16 +203,12 @@ public function getSlackData(LogRecord $record): array
*/
public function getAttachmentColor(int $level): string
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this get a Level as argument ?

public function toPsrLogLevel(): string
{
return match ($this) {
self::Debug => 'debug',
Copy link
Contributor

Choose a reason for hiding this comment

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

why not using the LogLevel constants there ?

// avoid returning readonly props by ref as this is illegal
$copy = $this->{$offset};

return $copy->value;
Copy link
Contributor

Choose a reason for hiding this comment

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

should you return the value of an enum by ref ?

{
$recordInitialized = count($this->processors) === 0;

$record = new LogRecord(
message: $message,
context: $context,
level: $level,
level: $level instanceof Level ? $level : self::toMonologLevel($level),
Copy link
Contributor

Choose a reason for hiding this comment

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

toMonologLevel already handles the case of instanceof Level

@@ -494,7 +474,7 @@ public function getExceptionHandler(): ?callable
*/
public function log($level, string|\Stringable $message, array $context = []): void
{
if (!is_int($level) && !is_string($level)) {
if (!is_string($level) && !is_int($level) && !$level instanceof Level) {
throw new \InvalidArgumentException('$level is expected to be a string or int');
Copy link
Contributor

Choose a reason for hiding this comment

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

or a Level

@Seldaek
Copy link
Owner Author

Seldaek commented Apr 19, 2022

Thanks @stof for the review 👍🏻 Will merge now then.

@Seldaek Seldaek merged commit 2d006a8 into main Apr 19, 2022
@Seldaek Seldaek deleted the enums branch April 19, 2022 19:49
@lyrixx lyrixx mentioned this pull request Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants