Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Developing CakePHP Plugins

Developing CakePHP Plugins

Mark Sch.

May 29, 2016
Tweet

More Decks by Mark Sch.

Other Decks in Technology

Transcript

  1. 2016 Spryker Systems GmbH 2 Developing CakePHP Plugins About me

    • @dereuromark • Open Source developer since 2007 • CakePHP developer since 1.2 (2006) • Core developer since 5+ years. • www.dereuromark.de
  2. 2016 Spryker Systems GmbH 3 Developing CakePHP Plugins Agenda •

    Clean Code: SOLID and Package Principles • Basics of plugin development • Examples Details @ www.dereuromark.de/2016/01/29/developing-cakephp-3-plugins-its-fun/
  3. 2016 Spryker Systems GmbH 5 Developing CakePHP Plugins S -

    Single responsibility • Keep classes simple, doing a specific task. • Watch out for constructor argument count.
  4. 2016 Spryker Systems GmbH 6 Developing CakePHP Plugins O -

    Open/closed principle • Your code should be open for extension, but closed for modification. • Code against abstract not concrete classes (interfaces in PHP).
  5. 2016 Spryker Systems GmbH 7 Developing CakePHP Plugins L -

    Liskov substitution principle • Every subclass or derived class should be substitutable for their base/parent class. • Only narrow, never widen, the input for sub classes
  6. 2016 Spryker Systems GmbH 8 Developing CakePHP Plugins I -

    Interface segregation principle • Don’t create one interface containing too many different method stubs
  7. 2016 Spryker Systems GmbH 9 Developing CakePHP Plugins D -

    Dependency inversion principle • Enforce class dependencies via constructor argument (dependency injection).
  8. 2016 Spryker Systems GmbH 10 Developing CakePHP Plugins Principles of

    package cohesion • Reuse-release equivalence principle • Common-reuse principle • Common-closure principle Principles of package coupling • Acyclic dependencies principle • Stable-dependencies principle • Stable-abstractions principle
  9. Developing CakePHP Plugins 2016 Spryker Systems GmbH 11 Reuse-release equivalence

    principle • Release as much code as can be reused • You can only reuse the amount of code you can actually release
  10. Developing CakePHP Plugins 2016 Spryker Systems GmbH 13 Building a

    plugin • Check awesome list first! https://github.com/FriendsOfCake/awesome-cakephp • cake bake plugin • Skeleton builder for composer: https://github.com/usemuffin/skeleton
  11. Developing CakePHP Plugins 2016 Spryker Systems GmbH 14 Releasing a

    plugin • Version control • Package definition file • SemVer and BC in minor versions • Meta files and documentation • Tests, CI and coverage And don’t forget to maintain it :-)
  12. Developing CakePHP Plugins 2016 Spryker Systems GmbH 15 Common-reuse principle

    • Code that is used together, should be ideally in the same package Common-closure principle • A package should not have more than one reason to change.
  13. Developing CakePHP Plugins 2016 Spryker Systems GmbH 17 Refactoring •

    dereuromark/cakephp-shim • dereuromark/cakephp-ajax • dereuromark/cakephp-geo • dereuromark/cakephp-feed • dereuromark/cakephp-tinyauth • dereuromark/cakephp-meta • dereuromark/cakephp-flash • dereuromark/cakephp-mobile On top of dereuromark/cakephp-tools now 6 extracted 3.x plugins with clear groups
  14. Developing CakePHP Plugins 2016 Spryker Systems GmbH 18 Package coupling

    (ADP, SDP, SAP) • Prevent cycling dependencies • Change is easiest when a package has not many dependencies (stable), so make sure if it does those are also not blocked for change. • Stable packages ideally have a lot of abstraction (interface, …) exposed to the depending parts so their stability does not prevent them from being extended.