Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small...
Transcript of Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small...
![Page 1: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/1.jpg)
Clean Code in Small Companies
![Page 2: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/2.jpg)
![Page 3: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/3.jpg)
Stock photo, not actual developer
![Page 4: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/4.jpg)
Stock photo, not actual developer
![Page 5: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/5.jpg)
![Page 6: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/6.jpg)
Stock photo, not actual developer
![Page 7: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/7.jpg)
Robert C. Martin“Uncle Bob”
![Page 8: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/8.jpg)
![Page 9: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/9.jpg)
1. Reading code is hard
![Page 10: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/10.jpg)
1. Reading code is hard
2. We all have to read code
![Page 11: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/11.jpg)
1. Reading code is hard
2. We all have to read code
3. Surprises are bad
![Page 12: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/12.jpg)
Code in these Slides
![Page 13: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/13.jpg)
$iAmAVariable
![Page 14: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/14.jpg)
class UserController extends Controller {}
Class name Parent class name
![Page 15: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/15.jpg)
class UserController extends Controller { private $memberVariable;}
Access modifier
![Page 16: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/16.jpg)
class UserController extends Controller { public function someMethod( Request $request ) { }}
Method name
Parameter type hint
![Page 17: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/17.jpg)
https://pasztor.at
![Page 18: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/18.jpg)
A few words on testing...More on this later
![Page 19: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/19.jpg)
class UserController { public function __construct( UserBusinessLogic $userBusinessLogic ) {
}}
![Page 20: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/20.jpg)
function testRegistration() {
}
![Page 21: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/21.jpg)
function testRegistration() { $userBusinessLogic = new UserBusinessLogicFake();
}
![Page 22: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/22.jpg)
function testRegistration() { $userBusinessLogic = new UserBusinessLogicFake(); $userController = new UserController( $userBusinessLogic );
}
![Page 23: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/23.jpg)
function testRegistration() { $userBusinessLogic = new UserBusinessLogicFake(); $userController = new UserController( $userBusinessLogic ); //Test the user controller}
![Page 24: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/24.jpg)
Dependency InjectionDon’t look for things!
![Page 25: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/25.jpg)
class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}
![Page 26: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/26.jpg)
class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}
![Page 27: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/27.jpg)
$this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN')
![Page 28: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/28.jpg)
$this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN')
![Page 29: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/29.jpg)
$this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN')
![Page 30: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/30.jpg)
$this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN')
![Page 31: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/31.jpg)
UserController
![Page 32: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/32.jpg)
UserController
Magic?
![Page 33: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/33.jpg)
UserController
Magic?
security.authorization_checker
![Page 34: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/34.jpg)
![Page 35: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/35.jpg)
class UserController extends Controller {
}
![Page 36: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/36.jpg)
class UserController extends Controller {
}
![Page 37: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/37.jpg)
class UserController { public function __construct( ) { }
}
![Page 38: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/38.jpg)
class UserController {
public function __construct( SecurityAuthorizationChecker $securityAuthorizationChecker ) { }
}
![Page 39: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/39.jpg)
class UserController { private $securityAuthorizationChecker; public function __construct( SecurityAuthorizationChecker $securityAuthorizationChecker ) { $this->securityAuthorizationChecker = $securityAuthorizationChecker ; }
}
![Page 40: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/40.jpg)
class UserController { private $securityAuthorizationChecker; public function __construct( SecurityAuthorizationChecker $securityAuthorizationChecker ) { $this->securityAuthorizationChecker = $securityAuthorizationChecker; }
/** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ($this->securityAuthorizationChecker->isGranted('ROLE_SUPER_ADMIN')) { return $this->redirectToRoute( 'admin_dashboard'); } }}
![Page 41: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/41.jpg)
class UserController { private $securityAuthorizationChecker; public function __construct( SecurityAuthorizationChecker $securityAuthorizationChecker ) { $this->securityAuthorizationChecker = $securityAuthorizationChecker; }
/** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ($this->securityAuthorizationChecker->isGranted('ROLE_SUPER_ADMIN')) { return $this->redirectToRoute( 'admin_dashboard'); } }}
![Page 42: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/42.jpg)
Dependency InjectorsMoving the Magic out of your Program
![Page 43: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/43.jpg)
UserController
UserBusinessLogic
UserStorage
![Page 44: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/44.jpg)
class UserController { public function __construct( UserBusinessLogic $userBusinessLogic ) { }}
![Page 45: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/45.jpg)
class UserController { public function __construct( UserBusinessLogic $userBusinessLogic ) { }}class UserBusinessLogic { public function __construct( UserStorage $userStorage ) { }}
![Page 46: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/46.jpg)
class UserController { public function __construct( UserBusinessLogic $userBusinessLogic ) { }}class UserBusinessLogic { public function __construct( UserStorage $userStorage ) { }}class UserStorage {}
![Page 47: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/47.jpg)
$uc = new UserController( new UserBusinessLogic( new UserStorage() ));
![Page 48: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/48.jpg)
$injector = new Injector();
![Page 49: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/49.jpg)
$injector = new Injector();
$uc = $injector->make(UserController::class);
![Page 50: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/50.jpg)
class MySQLConnection { public function __construct( string $server, string $username, string $password, string $db ) { }}
![Page 51: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/51.jpg)
$injector->define(MySQLConnection::class, [ 'server' => 'localhost', 'user' => 'root', 'password' => 'changeme', 'db' => 'app']);
![Page 52: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/52.jpg)
● PHP: Auryn, Laravel Service Container, Symfony Service Container
● Java: Gource, Dagger, Dagger2, Opsbears Web Components DIC
● Python: dependency_injector
● Javascript: InversifyJS
![Page 53: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/53.jpg)
class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}
![Page 54: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/54.jpg)
class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->container ->get('security.authorization_checker') ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}
![Page 55: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/55.jpg)
class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->injector ->make(SecurityAuthorizationChecker::class) ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}
![Page 56: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/56.jpg)
class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->injector ->make(SecurityAuthorizationChecker::class) ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}
![Page 57: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/57.jpg)
Static Function CallsMight Be Bad For Your Code Quality
![Page 58: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/58.jpg)
class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( $this->injector ->make(SecurityAuthorizationChecker::class) ->isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}
![Page 59: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/59.jpg)
class UserController extends Controller { /** * @Route("/user/account", name="user_account") */ public function accountAction(Request $request) { if ( SecurityAuthorizationChecker ::isGranted('ROLE_SUPER_ADMIN') ) { return $this->redirectToRoute('admin_dashboard'); } // Other stuff here }}
![Page 60: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/60.jpg)
$uc = new UserController();
![Page 61: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/61.jpg)
Immutable ObjectsAvoiding Surprises
![Page 62: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/62.jpg)
class User { private $id; public function setId($id) { $this->id = $id; } public function getId() { return $this->id; }}
![Page 63: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/63.jpg)
new User()
![Page 64: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/64.jpg)
class User { private $id; public function setId($id) { $this->id = $id; } public function getId() { return $this->id; }}
![Page 65: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/65.jpg)
class User { private $id; public function setId($id) { $this->id = $id; } public function getId() { return $this->id; }}
![Page 66: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/66.jpg)
class User { private $id; public function __construct($id) { $this->id = $id; } public function getId() { return $this->id; }}
![Page 67: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/67.jpg)
class UserStorage { private $users = []; public function store(User $user) { $this->users[$user->getId()] = $user; } }
![Page 68: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/68.jpg)
class UserStorage { private $users = []; public function store(User $user) { $this->users[$user->getId()] = $user; } public function retrieve($id) { if (isset($this->users[$id])) { return $this->users[$id]; } else { throw new UserNotFoundException($id); } }}
![Page 69: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/69.jpg)
Less Code in One ClassYour All-In-One Weightloss Program
![Page 70: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/70.jpg)
class UserController { public function register() {}
public function search() {}
public function get() {}
public function update() {}
public function delete() {}}
![Page 71: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/71.jpg)
Route::get( '/users', function (
) { return 'User list'; });
![Page 72: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/72.jpg)
Route::get( '/users', function ( UserBusinessLogic $userBusinessLogic ) { return 'User list'; });
![Page 73: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/73.jpg)
class UserRegisterController { public function __construct( UserBusinessLogic $userBusinessLogic ) { }
public function register() { }}
![Page 74: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/74.jpg)
Static TypingSaves you from a **** ton of issues
![Page 75: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/75.jpg)
function search( $needle, $haystack) {
}
![Page 76: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/76.jpg)
function search( string $needle, array $haystack) {
}
![Page 77: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/77.jpg)
mypyPythonbuiltinJava
phpstanPHP
JavaScript Typescript
![Page 78: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/78.jpg)
Strict TypingBecause your String is not an Integer
![Page 79: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/79.jpg)
<?php
declare(strict_types=1);PHP
![Page 80: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/80.jpg)
<?php
declare(strict_types=1);
Typescript
PHP
JavaScript
![Page 81: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/81.jpg)
Structuring your CodeBecause your Code is not a Clown Car
![Page 82: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/82.jpg)
/controller
UserRegisterController.php
UserListController.php
…
/model
/view
![Page 83: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/83.jpg)
/user
/controller
UserRegisterController.php
UserListController.php
…
/business
/storage
/blog
/controller
/business
/storage
![Page 84: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/84.jpg)
TestingYou test your code, right?
![Page 85: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/85.jpg)
Application
![Page 86: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/86.jpg)
User Interface
Application
![Page 87: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/87.jpg)
User Interface
Application
Test Code
![Page 88: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/88.jpg)
User Interface
ApplicationDatabase Connector
Test Code
![Page 89: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/89.jpg)
User Interface
ApplicationDatabase Connector
Test Database
Test Code
![Page 90: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/90.jpg)
User Interface
ApplicationDatabase Connector
Test Database
Test Code
![Page 91: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/91.jpg)
Application
![Page 92: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/92.jpg)
Application
Test Code
![Page 93: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/93.jpg)
Application
Test Code
Fake Database Connector
![Page 94: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/94.jpg)
Application
Test Code
Fake Database Connector
![Page 95: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/95.jpg)
Test Code
Fake Application
User Interface
![Page 96: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/96.jpg)
function testGetShouldReturnUser(){ //region Setup $userStorage = new UserStorageFake(); $userStorage->backingStorage['test-user'] = UserFactory::create( "test-user", "Test User", "[email protected]", "*" ); $business = new UserGetBusinessLogicImpl($userStorage); //endregion
//region Execute...
//region Asset...}
![Page 97: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/97.jpg)
function testGetShouldReturnUser(){ //region Setup...
//region Execute $user = $business->getById("test-user"); //endregion
//region Assert assertEquals("test-user", $user->getId()); //endregion}
![Page 98: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/98.jpg)
Putting it togetherBuilding an actual system
![Page 99: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/99.jpg)
Many thanks to: Cristina Laskar
![Page 100: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/100.jpg)
![Page 101: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/101.jpg)
![Page 102: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/102.jpg)
![Page 103: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/103.jpg)
API
Business Logic
Storage
MySQL or HSQLDB
Single Page Application
HTT
P
![Page 104: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/104.jpg)
API
Business Logic
Storage
DataMapper / ORM
Routing / Object Decoding
MySQL or HSQLDB
Single Page Application
HTT
P
![Page 105: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/105.jpg)
![Page 106: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/106.jpg)
Non-technical WaysCustomer Communication is Important
![Page 107: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/107.jpg)
UX design by @gogospaso
![Page 108: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/108.jpg)
More informationBecause one talk is not enough
![Page 109: Clean Code in Small Companies - pasztor.at Code in Small Companies.pdf · Clean Code in Small Companies. Stock photo, not actual developer. Stock photo, not actual developer. Stock](https://reader034.fdocuments.in/reader034/viewer/2022042803/5f4f2d9a2ffed124d511e1d7/html5/thumbnails/109.jpg)