Download the PHP package object-calisthenics/phpcs-calisthenics-rules without Composer
On this page you can find all versions of the php package object-calisthenics/phpcs-calisthenics-rules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download object-calisthenics/phpcs-calisthenics-rules
More information about object-calisthenics/phpcs-calisthenics-rules
Files in object-calisthenics/phpcs-calisthenics-rules
Package phpcs-calisthenics-rules
Short Description PHP CodeSniffer Object Calisthenics rules/sniffs
License MIT
Informations about the package phpcs-calisthenics-rules
Object Calisthenics rules for PHP_CodeSniffer
DEPRECATED: PHP_CodeSniffer is great for handling spaces and char positions. Yet these rules are about code architecture and structure. In 2020, there is tool that suits this perfectly - PHPStan.
Saying that, object calisthenics were implemented as PHPStan rules in a symplify/phpstan-rules
package. Use it instead 👇
Object Calisthenics are set of rules in object-oriented code, that focuses of maintainability, readability, testability and comprehensibility. We're pragmatic first - they are easy to use all together or one by one.
Why Should You Use This in Your Project?
Read post by William Durand or check presentation by Guilherme Blanco.
Install
Usage
If you know what you want, jump right to the specific rule:
- 1. Only X Level of Indentation per Method
- 2. Do Not Use "else" Keyword
- 5. Use Only One Object Operator (->) per Statement
- 6. Do not Abbreviate
- 7. Keep Your Classes Small
- 9. Do not Use Getters and Setters
How to quickly check 1 rule?
then
Implemented Rule Sniffs
1. Only X
Level of Indentation per Method
:x:
:+1:
Use Only This Rule?
In PHP_CodeSniffer:
In ECS:
:wrench: Configurable
In PHP_CodeSniffer:
In ECS:
2. Do Not Use "else" Keyword
:x:
:+1:
Use Only This Rule?
In PHP_CodeSniffer:
In ECS:
5. Use Only One Object Operator (->
) per Statement
:x:
:+1:
Use Only This Rule?
In PHP_CodeSniffer:
In ECS:
:wrench: Configurable
In PHP_CodeSniffer:
In ECS:
6. Do not Abbreviate
This is related to class, trait, interface, constant, function and variable names.
:x:
:+1:
Use Only This Rule?
In PHP_CodeSniffer:
In ECS:
:wrench: Configurable
In PHP_CodeSniffer:
In ECS:
7. Keep Your Classes Small
:x:
:+1:
:x:
:+1:
:x:
:+1:
:x:
:+1:
Use Only This Rule?
In PHP_CodeSniffer:
In ECS:
:wrench: Configurable
In PHP_CodeSniffer:
In ECS:
9. Do not Use Getters and Setters
This rules is partially related to Domain Driven Design.
- Classes should not contain public properties.
- Method should represent behavior, not set values.
:x:
:+1:
Use Only This Rule?
In PHP_CodeSniffer:
In ECS:
:wrench: Configurable
In PHP_CodeSniffer:
In ECS:
Not Implemented Rules - Too Strict, Vague or Annoying
While using in practice, we found these rule to be too strict, vague or even annoying, rather than helping to write cleaner and more pragmatic code. They're also closely related with Domain Driven Design.
3. Wrap Primitive Types and Strings - Since PHP 7, you can use define(strict_types=1)
and scalar type hints. For other cases, e.g. email, you can deal with that in your Domain via Value Objects.
4. Use First Class Collections - This rule makes sense, yet is too strict to be useful in practice. Even our code didn't pass it at all.
8. Do Not Use Classes With More Than Two Instance Variables - This depends on individual domain of each project. It doesn't make sense to make a rule for that.
3 Rules for Contributing
- 1 feature per PR
- every new feature must be covered by tests
- all tests and style checks must pass
We will be happy to merge your feature then.
All versions of phpcs-calisthenics-rules with dependencies
nette/utils Version ^3.1
slevomat/coding-standard Version ^6.3
squizlabs/php_codesniffer Version ^3.5