Show Menu

Clean Code Cheat Sheet by

coding

Design Rules

SRP single respon­sib­ility principe
OCP open closed principe
LSP Derived class should be substi­tutable for the base class.

Sandi Metz's Rules (copy)

100 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 instan­tiate only 1 object

Basic Rules (copy)

meaningful name for class, method, variable and constant
avoid using suffix for service name
remove the unused method and variable
remove the unnece­ssary variable and constant
prefer to use DateTi­meI­mmu­table 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 inform­ation
declare always the return value for method
avoid to use @template annota­tion, prefer to use $this-­>render
prefer to use $this-­>re­nde­r('­@Ap­pBu­ndl­e/i­nde­x.h­tml­,tw­ig');
define route in routin­g.yml file
define the Permission via @IsGra­nted(), @Secur­ity­("is­_gr­ant­ed(­)")
prefer to use @Cache­(sm­axa­ge=­"­300­") for caching
do NOT repeat yoursefl
 

DTO/DAO Object

validate the property with constraint annotation
always final class definition

Doctrine

Read operation via Repository
Write operation via Entity­Manager
Remove default value from doctrine annotation in Entity (Example: default values like type="s­­tr­i­n­g", length­­=255, nullab­­le­=­f­alse)
define public setter­/getter if really necessary

Migration

Remove the auto-g­ene­rated comments
Do not handle invalid platform, if MySQL is assumed due to full control of enviro­nment

Tests

Entity, ValueO­bject, DTO, DAO will not be mocked
Use Alice & faker for complex object
validation should not be mocked, prefer to use Valida­tio­nBu­ilder

Design

Infr­ast­ruc­ture consists of validator, EventL­ist­ener, DBAL EnumType
Busi­nes­sPr­ocess consists of essential operations in business flows
Symfony classic direct­ories: Contro­ller, Command, Entity, Form

Domains

Cart
Customer
Debitbook
Export
Marketing
Monitoring
Order
Produc­tFeed
Schedule
Stock
Subscr­iption
Voucher

Download the Clean Code Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/vikbert_clean-code.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          FREQUENTLY USED DX CODES Cheat Sheet
          C Reference Cheat Sheet