Refactoring PHP/Symfony2 apps

download Refactoring PHP/Symfony2 apps

of 51

  • date post

    18-Dec-2014
  • Category

    Technology

  • view

    5.404
  • download

    0

Embed Size (px)

description

Slides for deSymfony 2013

Transcript of Refactoring PHP/Symfony2 apps

  • 1. REFACTORINGPHP/SYMFONY2APPS
  • 2. Thank you to all our sponsors!
  • 3. Ral Fraile Software developer at PHP 5.3 Zend Certied Engineer Symfony Certied Developer LadybugPHPraulfraile
  • 4. 1. Refactoring 1012. Coding Standard3. IDE4. Code/Data separation5. Environment coupling6. Dont Repeat Yourself7. Fat controllersAgenda
  • 5. Test project
  • 6. APIJokes (I)GET /api/listGet the jokes list in JSONPOST /api/addAdd a new jokePOST /api/editEdit an existing jokeGET /Public website with the joke list in HTML
  • 7. APIJokes (II)Special casesEvery time a joke is added or edited,an email is sent to the administrator.We dont allow jokes about Java.
  • 8. raulfraile/apijokesThere are tags for each step!
  • 9. Refactoring 101
  • 10. Rewrite VS Refactor
  • 11. Rewritehttp://www.ickr.com/photos/meliah/2601885140/
  • 12. http://www.ickr.com/photos/90692443@N05/8239219385/Refactor
  • 13. Refactoring is acontinuous process
  • 14. Always taking a softwarethat works...
  • 15. ...and which has tests
  • 16. Coding Standard
  • 17. http://www.ickr.com/photos/zpeckler/2835570492/Change my CS?!
  • 18. Important: Choose a CSand be consistent
  • 19. Open source projects:share the same CS
  • 20. PSR-1/2
  • 21. http://cs.sensiolabs.org
  • 22. php-cs-fixer fix ApiJokesBundle/ --level=all --dry-run --diff -v1) Controller/WebsiteController.php (braces, return)---------- begin diff ------------- Original+++ New@@ @@-class WebsiteController extends Controller {- public function indexAction() {+class WebsiteController extends Controller+{+ public function indexAction()+ {$em = $this->getDoctrine()->getManager();$jokes = $em->getRepository(...)->findAll();+return $this->render(..., array(jokes => $jokes));}}---------- end diff ----------
  • 23. IDE
  • 24. Problems: DIC, foreach,repositories...
  • 25.