SymfonyInsight: How to setup quality processes in Symfony apps

SymfonyInsight: How to setup quality processes in Symfony apps

364d59ac0b4b4e5eee8aeb27a127d176?s=128

Titouan Galopin

July 09, 2020
Tweet

Transcript

  1. insight.symfony.com | July 9th 2020 | Titouan Galopin Setting up

    quality processes with Symfony Using the experience of the framework in your applications
  2. 2 Titouan Galopin Product Manager SymfonyInsight

  3. Agenda 1. Let’s talk about quality 2. OOP principles 3.

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

  5. 5 What defines good code?

  6. 6 The ability to handle change

  7. 7 Good code is able to handle change Code change

    over time Change in the execution environment
  8. 8 How do you write code able the handle change?

  9. 9 Handling change = Being able to update the code

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

    to update to apply a change
  11. 11 That’s where OOP is great

  12. 12 OOP helps you to create independent components inside your

    architecture, thus improving your code’s ability to handle change
  13. 13 By designing a good architecture, you will be able

    to update a class without changing the others
  14. 14 2. OOP principles

  15. 15 Ability to handle change Without OOP principles Difficult Updating

    the implementation Difficult Adding new features Difficult Removing features
  16. 16 Object Composition

  17. 17 In computer science, object composition (or encapsulation) is a

    way to combine simple objects or data types into more complex ones. — wikipedia.com
  18. 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() {/* ... */} }
  19. 19 Mailer Persister RegistrationManager Swiftmailer Twig Doctrine

  20. 20 Mailer Persister RegistrationManager Swiftmailer Twig Doctrine Contracts (interfaces) to

    express the need, not the implementation
  21. 21 SymfonyInsight monitors the usage of Symfony services to ensure

    you are using the proper contract
  22. 22 Dependency Injection

  23. 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
  24. 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
  25. 25 SymfonyInsight helps you use Dependency Injection correctly

  26. 26 Object composition and Dependency Injection help you create modular

    architectures
  27. 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() {/* ... */} }
  28. 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)
  29. 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
  30. 30 3. Symfony processes

  31. 31 How to ease interface changes over time?

  32. 32 Semantic versioning

  33. 33 Version 5.1.8

  34. 34 Version 5.1.8 • Increase the Major number when... ◦

    making incompatible API changes (interface updated)
  35. 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)
  36. 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)
  37. 37 Semantic versioning groups breaking changes together making them easier

    to apply
  38. 38 Humans are better at focusing than remembering In your

    applications, try to group breaking changes together in time (a single PR)
  39. 39 Deprecations

  40. 40 Symfony releases are predictable 1 minor every 6 months

    2 major every 2 years
  41. 41 Predictability is great to plan when you are going

    to need to upgrade
  42. 42 But it also means major versions contains 2 years

    of breaking changes at once => more complex upgrade path
  43. 43 Deprecations = Messages in minor versions about features that

    are going to be removed in the next major
  44. 44 /** * @deprecated since Symfony 4.3, use * "Symfony\Contracts\EventDispatcher\Event"

    instead. */ class Event { }
  45. 45 Find usages of deprecated features in your applications with

    SymfonyInsight
  46. 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
  47. 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
  48. 48 4. Using SymfonyInsight to monitor quality

  49. SymfonyInsight is a static and dynamic code analyzer

  50. SymfonyInsight is a static and dynamic code analyzer Analyse the

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

    code without executing it Run the code to better understand it
  52. It analyzes your code on each commit to help you

    maintain a high quality and upgrade your dependencies more easily
  53. SymfonyInsight has 3 mains aims Providing suggestions, validating your quality

    Monitoring quality and velocity Creating upgrade plans
  54. None
  55. None
  56. None
  57. Interested to learn more? Schedule a demo on https://insight.symfony.com/request-demo

  58. 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
  59. 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
  60. Thanks! 60 Follow us on Twitter: @symfonyinsight symfony.com/support symfony.com/slack