$30 off During Our Annual Pro Sale. View Details »

SymfonyInsight: How to setup quality processes in Symfony apps

SymfonyInsight: How to setup quality processes in Symfony apps

Titouan Galopin

July 09, 2020
Tweet

More Decks by Titouan Galopin

Other Decks in Programming

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

    View Slide

  2. 2
    Titouan Galopin
    Product Manager
    SymfonyInsight

    View Slide

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

    View Slide

  4. 4
    1.
    Let’s talk
    about quality

    View Slide

  5. 5
    What defines good code?

    View Slide

  6. 6
    The ability to handle change

    View Slide

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

    View Slide

  8. 8
    How do you write code able
    the handle change?

    View Slide

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

    View Slide

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

    View Slide

  11. 11
    That’s where OOP is great

    View Slide

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

    View Slide

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

    View Slide

  14. 14
    2.
    OOP
    principles

    View Slide

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

    View Slide

  16. 16
    Object Composition

    View Slide

  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

    View Slide

  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() {/* ... */}
    }

    View Slide

  19. 19
    Mailer Persister
    RegistrationManager
    Swiftmailer Twig Doctrine

    View Slide

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

    View Slide

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

    View Slide

  22. 22
    Dependency Injection

    View Slide

  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

    View Slide

  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

    View Slide

  25. 25
    SymfonyInsight
    helps you use
    Dependency
    Injection
    correctly

    View Slide

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

    View Slide

  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() {/* ... */}
    }

    View Slide

  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)

    View Slide

  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

    View Slide

  30. 30
    3.
    Symfony
    processes

    View Slide

  31. 31
    How to ease interface
    changes over time?

    View Slide

  32. 32
    Semantic versioning

    View Slide

  33. 33
    Version
    5.1.8

    View Slide

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

    View Slide

  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)

    View Slide

  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)

    View Slide

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

    View Slide

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

    View Slide

  39. 39
    Deprecations

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  45. 45
    Find usages of
    deprecated
    features in your
    applications with
    SymfonyInsight

    View Slide

  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

    View Slide

  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

    View Slide

  48. 48
    4.
    Using
    SymfonyInsight
    to monitor quality

    View Slide

  49. SymfonyInsight is a
    static and dynamic
    code analyzer

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  54. View Slide

  55. View Slide

  56. View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide