alister / phpstan-rules

Custom PHPStan rules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

phpstan-rules

Integrate Prune Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads

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

đź’ˇ You probably want to use these rules on top of the rules provided by:

Rules

This package provides the following rules for use with phpstan/phpstan:

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).

About

Custom PHPStan rules

License:MIT License


Languages

Language:PHP 86.0%Language:Makefile 14.0%