Download the PHP package struggle-for-php/sfp-phpstan-psr-log without Composer
On this page you can find all versions of the php package struggle-for-php/sfp-phpstan-psr-log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download struggle-for-php/sfp-phpstan-psr-log
More information about struggle-for-php/sfp-phpstan-psr-log
Files in struggle-for-php/sfp-phpstan-psr-log
Package sfp-phpstan-psr-log
Short Description Extra strict and opinionated psr/log (psr-3) rules for PHPStan
License MIT
Informations about the package sfp-phpstan-psr-log
psr/log(PSR-3) extensions for PHPStan
[!IMPORTANT] The next version
0.25.0
will have a BC break. Please referStubs
section.
struggle-for-php/sfp-phpstan-psr-log
is extra strict and opinionated psr/log (psr-3) rules for PHPStan.
Recommendation Settings
Write these parameters to your project's phpstan.neon
.
Stubs
[!IMPORTANT] include psr/log stub be planned to dropped in next release.
To try out the changes in the next version,
DELETE vendor/struggle-for-php/sfp-phpstan-psr-log/extension.neon
line from your phpstan.neon
and, set parameters enableLogLevelMethodRule
and enableContextTypeRule
About stub
Currently, this extension depends on our psr/log stub to serve strictness.
- eg.
@param LogLevel::* $level
atlog()
method@param array{exception?: \Throwable} $context
See psr/log stub repository page to get more detail.
Rules
This package provides the following rules.
PlaceholderCharactersRule
Placeholder names SHOULD be composed only of the characters A-Z, a-z, 0-9, underscore _, and period .
:pushpin: error identifier |
---|
sfpPsrLog.placeholderCharactersInvalidChar |
- reports when placeholder in
$message
characters are not,A-Z
,a-z
,0-9
, underscore_
, and period.
:pushpin: error identifier |
---|
sfpPsrLog.placeholderCharactersDoubleBraces |
- reports when double braces pair
{{
}}
are used.
PlaceholderCorrespondToKeysRule
Placeholder names MUST correspond to keys in the context array.
:pushpin: error identifier |
---|
sfpPsrLog.placeholderCorrespondToKeysMissedContext |
- reports when placeholder exists in message, but
$context
parameter is missed.
:pushpin: error identifier |
---|
sfpPsrLog.placeholderCorrespondToKeysMissedKey |
- reports when placeholder exists in message, but key in
$context
does not exist against them.
ContextKeyRule
[!NOTE] PSR-3 has no provisions for array keys, but this is useful in many cases.
:pushpin: error identifier |
---|
sfpPsrLog.contextKeyNonEmptyString |
- reports when context key is not non-empty-string.
:pushpin: error identifier |
---|
sfpPsrLog.contextKeyOriginalPattern |
- reports when context key is not matched you defined pattern.
- if
contextKeyOriginalPattern
parameter is not set, this check would be ignored.
- if
Configuration
- You can set specific key pattern by regex.(
preg_match()
)
ContextRequireExceptionKeyRule
[!NOTE] This is not a rule for along with PSR-3 specification, but provides best practices.
:pushpin: error identifier |
---|
sfpPsrLog.contextRequireExceptionKey |
- It forces
exception
key into context parameter when current scope has\Throwable
object.
Example
Configuration
- You can set the minimum required level to report. (default level is
debug
)
Then, debug
| info
| notice
LogLevel is ignored for report.
- If you want to enable this rule, please add
enableContextRequireExceptionKeyRule
as true.
MessageStaticStringRule
:pushpin: error identifier |
---|
sfpPsrLog.messageNotStaticString |
- reports when $message is not static string value.
Configuration
- If you want to disable this rule, please add
enableMessageStaticStringRule
as false.
Installation
To use this extension, require it in Composer:
Manual installation
include extension.neon & rules.neon in your project's PHPStan config:
All versions of sfp-phpstan-psr-log with dependencies
phpstan/phpstan Version ^1.12 || ^2.0
struggle-for-php/sfp-stubs-psr-log Version ^1.0.1 || ^2 || ^3.0.1