struggle-for-php/sfp-stubs-psr-log

Stubs to let Static Analysis understand psr/log (PSR-3)

3.0.2 2024-02-12 09:11 UTC

README

This repository is aimed for used by these.

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