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. Hello  all!

  2. I  am  a  regular  programmer…

  3. …  who  hates  BAD  CODE!

  4. You  want  to  see  me  angry?

  5. I  don’t  think  you  are  going  to  like  me, WHEN

     I  AM  ANGRY!
  6. None
  7. UNDER  THE  CAP

  8. UNDER  THE  BEARD PHP-­‐CS PHP-­‐CS-­‐Fixer Blacklist Commit-­‐Message Matcher

  9. JAMS  WITH  COMPOSER

  10. WEARS  LINTERS

  11. STANDS  FOR  SECURITY

  12. MEETS  FRONT-­‐END

  13. CONTINUOUS  INTEGRATION

  14. I  will  look  for  you,  I  will  find  you,  

    AND  I  WILL  KILL  YOU!
  15. BECOMING  A  NINJA

  16. YO  DAWG,  I  HEAR  YOU  LIKE TASKS  …

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

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

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

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

     TaskInterface { public  function  getName(); public  function  getConfiguration(); public  function  getConfigurableOptions(); public  function  canRunInContext(ContextInterface$context); }
  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); }
  22. #  grumphp.yaml services: task.myCustomTask: class: My\Custom\Task arguments: -­‐ '@config' tags:

    -­‐ {name:grumphp.task,  config: myCustomTask}
  23. #  grumphp.yaml parameters: tasks: myCustomTask: option1: value

  24. EVENTS  …

  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
  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
  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
  28. class  MyEventSubscriber implements  EventSubscriberInterface { public  static  function  getSubscribedEvents() {

    return  [RunnerEvents::RUNNER_FAILED  => 'onRunnerFailed']; } }
  29. class  MyEventSubscriber implements  EventSubscriberInterface { public  static  function  getSubscribedEvents() {

    return  [RunnerEvents::RUNNER_FAILED  => 'onRunnerFailed']; } public  function  onRunnerFailed(RunnerEvent$event) { //  Some  actions } }
  30. #  grumphp.yml services: listener.some_subscriber: class:  MyNamespace\EventSubscriber\MySubscriber tags: -­‐ {  name:

     grumphp.event_subscriber}
  31. #  grumphp.yml services: listener.some_listener: class:  MyNamespace\EventListener\MyListener tags: -­‐ name:  grumphp.event_listener

    event:  grumphp.runner.run method:  customMethod priority:  10
  32. IF  I  COULD  WRITE  MY  OWN  EXTENSION  …

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

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

    new  YamlFileLoader($container,  new  FileLocator(__DIR__)); $loader-­‐>load('custom.yml'); } }
  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); } }
  36. class  CustomExtensionimplements  ExtensionInterface { public  function  load(ContainerBuilder$container) { $container-­‐>setParameter('notifications',  'myemail@mycompany.com');

    } }
  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); } }
  38. #  grumphp.yml parameters: extensions: -­‐ My\CustomExtension

  39. ONE  DOES  NOT  SIMPLY  SUPPORT  ALL  PLATFORMS

  40. None
  41. 53 54 55 56 HHVM 70

  42. None
  43. LET’S  TALK  STATISTICS

  44. STATS

  45. SPECIAL  THANKS

  46. TO  CONTRIBUTE! WE  WANT  YOU

  47. Put  it  where  you  can’t  see  it! PHP-­‐MD PHP-­‐CPD PHP-­‐DCD

    TWIG HUMBUG PHING ANT BLADE PHP-­‐PARSER
  48. None
  49. That  would  be  AWESOME  !!!

  50. ASK QUESTIONS  YOU  SHOULD!

  51. LET THE SOURCE  BE  WITH  YOU! https://joind.in/talk/935a8