Assuring code quality with GrumPHP - PHPLEUVEN12

Assuring code quality with GrumPHP - PHPLEUVEN12

Sick and tired of defending code quality over and over again? GrumPHP will do it for you! This composer plugin will register some git hooks in your package repository. When somebody commits changes, GrumPHP will run some tests on the committed code. If the tests fail, you won't be able to commit your changes. This handy tool will not only improve your codebase, it will also teach your co-workers to write better code following the best practices you've determined as a team.

6c18f9874bd8dd408e41d77518987a0e?s=128

Toon Verwerft

February 24, 2016
Tweet

Transcript

  1. 6.
  2. 17.

    /** *  Interface  TaskInterface * *  @package  GrumPHP\Task */ interface

     TaskInterface { public  function  getName(); }
  3. 18.

    /** *  Interface  TaskInterface * *  @package  GrumPHP\Task */ interface

     TaskInterface { public  function  getName(); public  function  getConfiguration(); }
  4. 19.

    /** *  Interface  TaskInterface * *  @package  GrumPHP\Task */ interface

     TaskInterface { public  function  getName(); public  function  getConfiguration(); public  function  getConfigurableOptions(); }
  5. 20.

    /** *  Interface  TaskInterface * *  @package  GrumPHP\Task */ interface

     TaskInterface { public  function  getName(); public  function  getConfiguration(); public  function  getConfigurableOptions(); public  function  canRunInContext(ContextInterface$context); }
  6. 21.

    /** *  Interface  TaskInterface * *  @package  GrumPHP\Task */ interface

     TaskInterface { public  function  getName(); public  function  getConfiguration(); public  function  getConfigurableOptions(); public  function  canRunInContext(ContextInterface$context); public  function  run(ContextInterface$context); }
  7. 25.

    Event  name Event  class Triggered grumphp.runner.run RunnerEvent before  the  tasks

     are  executed grumphp.runner.failed RunnerFailedEvent when  one  task  failed grumphp.runner.complete RunnerEvent when  all  tasks  succeed
  8. 26.

    Event  name Event  class Triggered grumphp.task.run TaskEvent before  a  task

     is  executed grumphp.task.failed TaskFailedEvent when  a  task  fails grumphp.task.complete TaskEvent when  a  task  succeeds
  9. 27.

    Event  name Event  class Triggered console.command ConsoleCommandEvent before  a  CLI

     command  is  ran console.terminate ConsoleTerminateEvent before  a  CLI  command   terminates console.exception ConsoleTerminateEvent when  a  CLI  command  throws  an   unhandled  exception
  10. 29.

    class  MyEventSubscriber implements  EventSubscriberInterface { public  static  function  getSubscribedEvents() {

    return  [RunnerEvents::RUNNER_FAILED  => 'onRunnerFailed']; } public  function  onRunnerFailed(RunnerEvent$event) { //  Some  actions } }
  11. 33.

    /** *  Interface  ExtensionInterface * *  @package  GrumPHP\Extension */ interface

     ExtensionInterface { public  function  load(ContainerBuilder$container); }
  12. 34.

    class  CustomExtensionimplements  ExtensionInterface { public  function  load(ContainerBuilder$container) { $loader  =

    new  YamlFileLoader($container,  new  FileLocator(__DIR__)); $loader-­‐>load('custom.yml'); } }
  13. 35.

    class  CustomExtensionimplements  ExtensionInterface { public  function  load(ContainerBuilder$container) { $customTask =

    new  Definition(MyTask::class,  ['@config']); $customTask-­‐>addTag('grumphp.task',  ['config'  => 'myTask']); $container-­‐>setDefinition('task.myTask',  $customTask); } }
  14. 37.

    class  CustomExtensionimplements  ExtensionInterface { public  function  load(ContainerBuilder$container) { $customListener =

    new  Definition(MyListener::class,  ['@config']); $customListener-­‐>addTag('grumphp.event_subscriber'); $container-­‐>setDefinition('listener.mySubscriber',  $customSubscriber); } }
  15. 40.
  16. 42.
  17. 44.
  18. 48.