struggle-for-php/sfp-psalm-psr-log-plugin

Stubs to let Psalm understand psr/log (PSR-3) strictly

Installs: 141

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 1

Open Issues: 0

Language:Gherkin

Type:psalm-plugin

0.2.0 2020-04-29 09:00 UTC

This package is auto-updated.

Last update: 2020-10-29 10:00:59 UTC


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>