-
Notifications
You must be signed in to change notification settings - Fork 178
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
Narrow supported log level phpdoc #79
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this makes sense yes.
Can it be merged and released? |
This may require a change in the spec.. |
@Jean85 please see the linked spec in the PR description, citing:
So I belive the spec. allows this change, as the phpdoc in this PR is basically equivalent to the "Calling this method with a level not defined by this specification MUST throw". |
I belive I have prooven what needs to be proven, can this PR be merged, please 🙏? |
This is a breaking change and disallows the valid use case of an implementor adding a custom log level: https://www.php-fig.org/psr/psr-3/#11-basics This could only merge if Edit: To add some more context now that I'm not on mobile, the current method accepts mixed. While implementors can widen the type if they choose to, consumers cannot and so by changing this type we are disallowing the following: function logSomething(LoggerInterface $logger): void
{
try {
$logger->log(new MyCustomLogLevel(), 'foo');
} catch (\InvalidArgumentException $e) {
$logger->log('warning', 'foo'); // Fallback to supported type
}
} To me this is a breaking change even if the error only shows up in static analysis. It seems easy and obvious to simply change the type to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment. To demonstrate my concern, compare these:
- Current
mixed
type: https://psalm.dev/r/b15a7f5725 - PR proposed type: https://psalm.dev/r/8e53dc846d
- My recommendation: https://psalm.dev/r/e4306f884a
@KorvinSzanto please see #79 (comment) - the spec already defines:
that the default interface does not support any other log level by default. Thank to LSP, user can widen the accepted type: working in both/all static analysers. Given these facts, I belive this PR is not violating the spec. |
And so for the purposes of this discussion, in my opinion, the quote you show is effectively the same as "Users MAY use a custom level without knowing ..." and by changing the type here to disallow that use case we're going from
That's not an argument for narrowing the type here though. Most implementors simply inherit the type from the parent, for example symfony:
I disagree. Can you take a second and speak to the value of narrowing this type rather than just using an intersection or union type with |
Only the
LogLevel::*
log levels need to be supported per https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#11-basicsUser can still widen the accepted type like
LogLevel::*|'xxx'
thanks to LSP.