struggle-for-php / sfp-psalm-psr-log-plugin
Stubs to let Psalm understand psr/log (PSR-3) strictly
Installs: 227
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Language:Gherkin
Type:psalm-plugin
Requires
- php: ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0
- ext-simplexml: *
- vimeo/psalm: ^5
Requires (Dev)
- psr/log: ^1.1
- squizlabs/php_codesniffer: ^3.7
- weirdan/codeception-psalm-module: ^0.14.0
README
PSR-3 (psr/log) plugin for Psalm
Installation:
$ composer require --dev struggle-for-php/sfp-psalm-psr-log-plugin $ vendor/bin/psalm-plugin enable struggle-for-php/sfp-psalm-psr-log-plugin
Example
<?php use Psr\Log\LoggerInterface; class FooController { /** @var LoggerInterface */ private $logger; public function anyAction() { try { // do something } catch (\Exception $e) { $this->logger->error('error happened.', ['exception' => $e->getMessage()]); } } }
would be ERROR output:
ERROR: InvalidArgument - src/Foo.php:14:45 - Argument 2 of Psr\Log\LoggerInterface::error expects array{exception?: Exception}, array{exception: string} provided $this->logger->error('error happened.', ['exception' => $e->getMessage()]);
Configure
If you want to allow Throwable
to pass logger context's exception
.
<plugins> <pluginClass class="Sfp\Psalm\PsrLogPlugin\Plugin"> <throwable>1</throwable> </pluginClass> </plugins>