struggle-for-php / sfp-stubs-psr-log
Stubs to let Static Analysis understand psr/log (PSR-3)
Installs: 67 834
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 1
Open Issues: 0
Language:Gherkin
Requires
- php: >=8.0.0
Requires (Dev)
- ext-simplexml: *
- psr/log: ^3
- rector/rector: 0.15.21
- squizlabs/php_codesniffer: ^3.7
- symfony/console: ^5
- vimeo/psalm: ^5.8
- weirdan/codeception-psalm-module: ^0.14.0
Conflicts
- psr/log: ^1 || ^2 || >=4
README
This repository is aimed for used by these.
- https://github.com/struggle-for-php/sfp-psalm-psr-log-plugin
- https://github.com/struggle-for-php/sfp-phpstan-psr-log
But, You can use this for individual purpose. Add the following files to your stub settings.
stubs-for-throwable/LoggerInterface.phpstub
Features
Typed context array, in order to force exception
key is only Throwable object.
Example
<?php /** @var Psr\Log\LoggerInterface $logger */ $logger->error('error happen.', ['exception' => $exception->getMessage()]);
Your Static analysis would points like this message.
Parameter #2 $context of method Psr\Log\LoggerInterface::error() expects array()|array('exception' => Exception),
Refs.
Implementors MUST still verify that the 'exception' key is actually an Exception before using it as such, as it MAY contain anything.
https://www.php-fig.org/psr/psr-3/#13-context
The PSR-3 specification states Exception
but we have confirmed with PHP-FIG that Throwable
is allowed for PHP 7 and later.
https://groups.google.com/g/php-fig/c/nnwDWSFmij8
level
parameter of log
method is a constant enum of LogLevels::*.
/** * @param LogLevel::* $level */ public function log($level, $message, array $context = array())
Not Support (Not planned)
- Stub
LoggerAwareTrait