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

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.

Toon Verwerft

February 24, 2016
Tweet

More Decks by Toon Verwerft

Other Decks in Programming

Transcript

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

     TaskInterface { public  function  getName(); }
  2. /** *  Interface  TaskInterface * *  @package  GrumPHP\Task */ interface

     TaskInterface { public  function  getName(); public  function  getConfiguration(); }
  3. /** *  Interface  TaskInterface * *  @package  GrumPHP\Task */ interface

     TaskInterface { public  function  getName(); public  function  getConfiguration(); public  function  getConfigurableOptions(); }
  4. /** *  Interface  TaskInterface * *  @package  GrumPHP\Task */ interface

     TaskInterface { public  function  getName(); public  function  getConfiguration(); public  function  getConfigurableOptions(); public  function  canRunInContext(ContextInterface$context); }
  5. /** *  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); }
  6. 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
  7. 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
  8. 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
  9. class  MyEventSubscriber implements  EventSubscriberInterface { public  static  function  getSubscribedEvents() {

    return  [RunnerEvents::RUNNER_FAILED  => 'onRunnerFailed']; } public  function  onRunnerFailed(RunnerEvent$event) { //  Some  actions } }
  10. /** *  Interface  ExtensionInterface * *  @package  GrumPHP\Extension */ interface

     ExtensionInterface { public  function  load(ContainerBuilder$container); }
  11. class  CustomExtensionimplements  ExtensionInterface { public  function  load(ContainerBuilder$container) { $loader  =

    new  YamlFileLoader($container,  new  FileLocator(__DIR__)); $loader-­‐>load('custom.yml'); } }
  12. 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); } }
  13. class  CustomExtensionimplements  ExtensionInterface { public  function  load(ContainerBuilder$container) { $customListener =

    new  Definition(MyListener::class,  ['@config']); $customListener-­‐>addTag('grumphp.event_subscriber'); $container-­‐>setDefinition('listener.mySubscriber',  $customSubscriber); } }