phpstan-rules
Provides additional rules for phpstan/phpstan
.
Installation
Run
$ composer require --dev alister/phpstan-rules
Usage
All of the rules provided (and used) by this library are included in src/LoggerContext/rules.neon
.
When you are using phpstan/extension-installer
, rules.neon
will be automatically included (To be confirmed).
Otherwise you need to include rules.neon
in your phpstan.neon
:
includes:
- vendor/alister/phpstan-rules/src/LoggerContext/rules.neon
parameters:
logger_context:
disallowed_namespaces:
- App\Entity
- App\DTOs
Rules
This package provides the following rules for use with phpstan/phpstan
:
Alister\PHPStan\Rules\LoggerContext\KeyDotsRule
Alister\PHPStan\Rules\LoggerContext\ObjectAsValuesRule
Rules
Disallow full stops as part of a logger context key
LoggerContext\KeyDotsRule
// This would not be allowed:
$this->log->notice('The ID of a user:', ['user.id' => $user->getId()]); // key contains '.'
$this->log->notice('Logging this key as user_id is OK', ['user_id' => $user->getId()]);
Disallowing logging of values within a namespace
This rule allows you to specify objects from namespaces should not be logged in their entirety. Scalar values are allowed, but not entire objects.
parameters:
logger_context:
disallowed_namespaces:
- App\Entity
// This would not be allowed:
$this->log->notice('here is a User object', ['user' => $user]); // $user is an object instance from \App\Entity namespace
$this->log->notice('Logging the user id is OK', ['user_id' => $user->getId()]);
Changelog
Please have a look at CHANGELOG.md
.
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.
Credits
The repository layout, workflow & tests, is based on ergebnis/phpstan-rules (originally licensed under MIT).