samlitowitz / phpstan-opinionated-nomenclature
Opinionated PHPStan rules for naming things
Installs: 5
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:phpstan-extension
Requires
- php: ^7.4 || ^8.0
- phpstan/phpstan: ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.11
This package is auto-updated.
Last update: 2024-11-29 16:28:06 UTC
README
Opinionated PHPStan rules for naming things.
Table of Contents
Installation
Install the extension via Composer.
composer require --dev samlitowitz/phpstan-opinionated-nomenclature
This extension requires PHPStan to use.
PHPStan Extension Installer
Use the PHPStan Extension Installer to automatically install PHPStan extensions.
Manual Installation
Add vendor/samlitowitz/phpstan-opinionated-nomenclature/extension.neon
to the includes
section of
your phpstan.neon
or phpstan.neon.dist
file, i.e.
includes: - vendor/samlitowitz/phpstan-opinionated-nomenclature/extension.neon
Rules
Namespace
-
Namespace names MUST NOT be equal to or end in
DTO
of any case (case-insensitive)<?php namespace DTO; // bad namespace Client\Dto; // bad
-
Namespace names MUST NOT be equal to
Helper
of any case (case-insensitive)<?php namespace Helper; // bad namespace Client\helper; // bad
Class Like (Class, Interface, Trait)
-
Class like names MUST NOT be equal to or end in
DTO
of any case (case-insensitive)<?php class DTO {} // bad class ClientDTO {} // bad
-
Class like names MUST NOT be equal to
Helper
of any case (case-insensitive)<?php class Helper {} // bad
-
Class like names MUST NOT be equal to or start with any case (case-insensitive) of the namespace name it resides in
<?php namespace Client; class ClientRequest {} // bad namespace Client\Request; class Request {} // bad
-
Class like names MUST NOT end with their type name of any case (case-insensitive)
<?php class ClientClass {} // bad interface FileInterface {} // bad trait TransactionTrait {} // bad
Class
-
No non-final classes without children
<?php class NonFinalNoChildren {} // bad
Interface
-
Interface names MUST NOT be prefixed with
I
<?php interface IWriter {} // bad