Design RulesSRP single responsibility principe | OCP open closed principe | LSP Derived class should be substitutable for the base class. | Layer of abstraction |
Sandi Metz's Rules100 Class can be no longer than 100 lines of code | 5 Method can be no longer than 5 lines of code | 4 Method should have no more than 4 parameters | only 1 Controll should instantiate only 1 object |
Basic Rulesmeaningful name for class, method, variable and constant | avoid using suffix for service name | remove the unused method and variable | remove the unnecessary variable and constant | prefer to use DateTimeImmutable for handling date | return value directly and earlier, if possible | short method, and just do one thing | set the lowest visibility to class, constant, variable, method | docblock must bring additional information | declare always the return value for method | avoid to use @template annotation, prefer to use $this->render | prefer to use $this->render('@AppBundle/index.html,twig'); | define route in routing.yml file | define the Permission via @IsGranted(), @Security("is_granted()") | prefer to use @Cache(smaxage="300") for caching | DRY: do NOT repeat yoursefl | self-documenting code |
TEDT: terse, simple as possible | E: expressive(self-documented) | D: done one thing |
| | DTO/DAO Objectvalidate the property with constraint annotation | always final class definition |
DoctrineRead operation via Repository | Write operation via EntityManager | Remove default value from doctrine annotation in Entity (Example: default values like type="string", length=255, nullable=false) | define public setter/getter if really necessary |
MigrationRemove the auto-generated comments | Do not handle invalid platform, if MySQL is assumed due to full control of environment |
TestsEntity, ValueObject, DTO, DAO will not be mocked | Use Alice & faker for complex object | validation should not be mocked, prefer to use ValidationBuilder |
DesignInfrastructure consists of validator, EventListener, DBAL EnumType | BusinessProcess consists of essential operations in business flows | Symfony classic directories: Controller, Command, Entity, Form |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by vikbert