Slide 1

Slide 1 text

insight.symfony.com | July 9th 2020 | Titouan Galopin Setting up quality processes with Symfony Using the experience of the framework in your applications

Slide 2

Slide 2 text

2 Titouan Galopin Product Manager SymfonyInsight

Slide 3

Slide 3 text

Agenda 1. Let’s talk about quality 2. OOP principles 3. Symfony processes 4. Using SymfonyInsight to monitor quality 3

Slide 4

Slide 4 text

4 1. Let’s talk about quality

Slide 5

Slide 5 text

5 What defines good code?

Slide 6

Slide 6 text

6 The ability to handle change

Slide 7

Slide 7 text

7 Good code is able to handle change Code change over time Change in the execution environment

Slide 8

Slide 8 text

8 How do you write code able the handle change?

Slide 9

Slide 9 text

9 Handling change = Being able to update the code efficiently to apply a change

Slide 10

Slide 10 text

10 Handling change = Having as less code as possible to update to apply a change

Slide 11

Slide 11 text

11 That’s where OOP is great

Slide 12

Slide 12 text

12 OOP helps you to create independent components inside your architecture, thus improving your code’s ability to handle change

Slide 13

Slide 13 text

13 By designing a good architecture, you will be able to update a class without changing the others

Slide 14

Slide 14 text

14 2. OOP principles

Slide 15

Slide 15 text

15 Ability to handle change Without OOP principles Difficult Updating the implementation Difficult Adding new features Difficult Removing features

Slide 16

Slide 16 text

16 Object Composition

Slide 17

Slide 17 text

17 In computer science, object composition (or encapsulation) is a way to combine simple objects or data types into more complex ones. — wikipedia.com

Slide 18

Slide 18 text

18 interface PersisterInterface { /* ... */ } interface MailerInterface { /* ... */ } class RegistrationManager { private $persister; private $mailer; public function __construct( PersisterInterface $persister, MailerInterface $mailer ) { $this->persister = $persister; $this->mailer = $mailer; } public function register() {/* ... */} }

Slide 19

Slide 19 text

19 Mailer Persister RegistrationManager Swiftmailer Twig Doctrine

Slide 20

Slide 20 text

20 Mailer Persister RegistrationManager Swiftmailer Twig Doctrine Contracts (interfaces) to express the need, not the implementation

Slide 21

Slide 21 text

21 SymfonyInsight monitors the usage of Symfony services to ensure you are using the proper contract

Slide 22

Slide 22 text

22 Dependency Injection

Slide 23

Slide 23 text

23 Dependency Injection is where components are given their dependencies through their constructors, methods, or directly into fields. Those components do not get their dependencies themselves, or instantiate them directly. — picocontainer.com/injection.html

Slide 24

Slide 24 text

24 A dependency injection container is an object that enables to standardize and centralize the way objects are constructed and configured in an application. — symfony.com

Slide 25

Slide 25 text

25 SymfonyInsight helps you use Dependency Injection correctly

Slide 26

Slide 26 text

26 Object composition and Dependency Injection help you create modular architectures

Slide 27

Slide 27 text

27 interface MailerInterface { /* ... */ } class RegistrationManager { private $persister; private $mailer; public function __construct( PersisterInterface $persister, MailerInterface $mailer ) { $this->persister = $persister; $this->mailer = $mailer; } public function register() {/* ... */} }

Slide 28

Slide 28 text

28 interface MailerInterface { /* ... */ } class RegistrationManager { private $persister; private $mailer; public function __construct( PersisterInterface $persister, MailerInterface $mailer ) { $this->persister = $persister; $this->mailer = $mailer; } public function register() {/* ... */} } Updating the code of the Mailer will not require you to change the RegistrationManager (if you keep the interface)

Slide 29

Slide 29 text

29 Ability to handle change Without OOP principles With OOP principles Difficult Easy Updating the implementation Difficult Difficult (requires interface change) Adding new features Difficult Difficult (requires interface change) Removing features

Slide 30

Slide 30 text

30 3. Symfony processes

Slide 31

Slide 31 text

31 How to ease interface changes over time?

Slide 32

Slide 32 text

32 Semantic versioning

Slide 33

Slide 33 text

33 Version 5.1.8

Slide 34

Slide 34 text

34 Version 5.1.8 ● Increase the Major number when... ○ making incompatible API changes (interface updated)

Slide 35

Slide 35 text

35 Version 5.1.8 ● Increase the Major number when... ○ making incompatible API changes (interface updated) ● Increase the Minor number when... ○ adding features (interface added)

Slide 36

Slide 36 text

36 Version 5.1.8 ● Increase the Major number when... ○ making incompatible API changes (interface updated) ● Increase the Minor number when... ○ adding features (interface added) ● Increase the Patch number when... ○ fixing bugs (no interface change)

Slide 37

Slide 37 text

37 Semantic versioning groups breaking changes together making them easier to apply

Slide 38

Slide 38 text

38 Humans are better at focusing than remembering In your applications, try to group breaking changes together in time (a single PR)

Slide 39

Slide 39 text

39 Deprecations

Slide 40

Slide 40 text

40 Symfony releases are predictable 1 minor every 6 months 2 major every 2 years

Slide 41

Slide 41 text

41 Predictability is great to plan when you are going to need to upgrade

Slide 42

Slide 42 text

42 But it also means major versions contains 2 years of breaking changes at once => more complex upgrade path

Slide 43

Slide 43 text

43 Deprecations = Messages in minor versions about features that are going to be removed in the next major

Slide 44

Slide 44 text

44 /** * @deprecated since Symfony 4.3, use * "Symfony\Contracts\EventDispatcher\Event" instead. */ class Event { }

Slide 45

Slide 45 text

45 Find usages of deprecated features in your applications with SymfonyInsight

Slide 46

Slide 46 text

46 Sometimes, refactorings are too large to be done at once In your applications, use deprecations to keep legacy code running and allow tools to help you remove its usages over time

Slide 47

Slide 47 text

47 Ability to handle change Without OOP principles With OOP principles Difficult Easy Updating the implementation Difficult Difficult (requires interface change) Adding new features Difficult Difficult (requires interface change) Removing features With Symfony processes Easy Easier Easier

Slide 48

Slide 48 text

48 4. Using SymfonyInsight to monitor quality

Slide 49

Slide 49 text

SymfonyInsight is a static and dynamic code analyzer

Slide 50

Slide 50 text

SymfonyInsight is a static and dynamic code analyzer Analyse the code without executing it

Slide 51

Slide 51 text

SymfonyInsight is a static and dynamic code analyzer Analyse the code without executing it Run the code to better understand it

Slide 52

Slide 52 text

It analyzes your code on each commit to help you maintain a high quality and upgrade your dependencies more easily

Slide 53

Slide 53 text

SymfonyInsight has 3 mains aims Providing suggestions, validating your quality Monitoring quality and velocity Creating upgrade plans

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

Interested to learn more? Schedule a demo on https://insight.symfony.com/request-demo

Slide 58

Slide 58 text

Webinar attendee promo code To thank you for attending our SymfonyInsight webinar, get -20% on any new yearly plan: SFI-WEBINAR-0907 Use this coupon during the payment process

Slide 59

Slide 59 text

Need help applying these architectural concepts? Find a training program with our partner SensioLabs University: https://university.sensiolabs.com/e-learning-platform Use the promo code SLUINSIGHT30 to get -30% on the e-Learning Platform

Slide 60

Slide 60 text

Thanks! 60 Follow us on Twitter: @symfonyinsight symfony.com/support symfony.com/slack