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

Break Off - Midwest

Break Off - Midwest

Most of the PHP that still exists today was written long ago by developers lost to the sands of time. It was written in an era where we didn't have the tools we do today such as Composer, type safety, unit testing, and code standards. Even code that was written recently frequently ignores best practices in order to "get things done". You've been tasked with maintaining a legacy application and would like to modernize it, but the powers that be won't let you rewrite it. This talk will discuss strategies for bringing ancient codebases into the modern age piece-by-piece.

Given at Midwest PHP 2021.

Omni Adams

April 22, 2021
Tweet

More Decks by Omni Adams

Other Decks in Programming

Transcript

  1. Break Off A Piece Of That Monolith

  2. Break Off A Piece Of That Mono Omni Adams —

    Givelify — Midwest PHP April 2021 lith
  3. https://commons.wikimedia.org/wiki/File:Spaghetti,_cooked,_in_bowl.jpg

  4. https://www. fl ickr.com/photos/wagner-machado-carlos-lemes/2987599021

  5. https://www. fl ickr.com/photos/tambako/3589021887 https://www.hyrumslaw.com/

  6. https://www. fl ickr.com/photos/nachof/2482912078

  7. https://www.pxfuel.com/en/free-photo-ozrrp

  8. None
  9. https://www.geograph.org.uk/photo/5846712

  10. –DHH “You don’t want to hear that the reason your

    monolith is a spaghetti monster is because you let it become that way, one commit at the time, due to weak habits, pressurized deadlines, or simply sheer lack of competence.” https://m.signalvnoise.com/integrated-systems-for-integrated-programmers/
  11. It’s REALLY hard

  12. Plan of Attack Testing Tools Refactoring

  13. https://commons.wikimedia.org/wiki/File:PHPUnit_Logo.svg

  14. PHPUnit 8.5.0 by Sebastian Bergmann and contributors. ............................................................... 63 /

    281 ( 22%) ............................................................... 126 / 281 ( 44%) ............................................................... 189 / 281 ( 67%) ............................................................... 252 / 281 ( 89%) ............................. 281 / 281 (100%) Time: 2.83 seconds, Memory: 24.00 MB OK (281 tests, 6 assertions) Code Coverage Report: Summary: Classes: 51.72% (15/29) Methods: 75.83% (91/120) Lines: 55.95% (941/1682)
  15. None
  16. None
  17. Testing Unit tests Functional tests

  18. Static Analysis PHP_CodeSniffer PHPStan

  19. Style Guides

  20. FILE: /home/omni/code/object/src/Nether/Object/Datastore.php --------------------------------------------------------------------------------------------------------- FOUND 891 ERRORS AND 2 WARNINGS AFFECTING

    569 LINES --------------------------------------------------------------------------------------------------------- 1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n" 3 | ERROR | [x] Header blocks must be separated by a single blank line 4 | ERROR | [ ] Import statements must not begin with a leading backslash 4 | ERROR | [x] Header blocks must not contain blank lines 6 | ERROR | [ ] Import statements must not begin with a leading backslash 7 | ERROR | [ ] Import statements must not begin with a leading backslash 8 | ERROR | [ ] Import statements must not begin with a leading backslash 11 | ERROR | [x] The implements keyword must be on the same line as the class name 11 | ERROR | [x] Opening brace of a class must be on the line after the de fi nition 13 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed 13 | ERROR | [x] Scope keyword "protected" must be followed by a single space; found newline 14 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed 15 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed 16 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
  21. Reading code is at least twice as hard as writing

    code.
  22. Static Analysis PHP_CodeSniffer PHPStan

  23. ------ ---------------------------------------------------------------------- Line requisition.edit.php ------ ---------------------------------------------------------------------- 21 Class Error referenced

    with incorrect case: error. 24 Instantiated class requisition not found. 25 Call to method load_from_database() on an unknown class requisition. 27 Class Error referenced with incorrect case: error. 28 Constant ERR_RECORD_NOT_FOUND not found. 29 Call to an unde fi ned method Error::new_error(). 36 Constant APP_ROOT not found. 199 Constant REQ_TERM_FULL_TIME not found.
  24. Refactoring Breaking up big pieces of code Pulling procedural code

    out to objects Pulling large pieces of functionality out
  25. Refactoring: Bigger is better?

  26. Refactoring: Small for the win?

  27. Refactoring: Just right

  28. The Strangler Pattern

  29. Example: Calendar PHP3ish code Interspersed PHP and HTML No style

    guide No composer No tests
  30. None
  31. None
  32. None
  33. None
  34. None
  35. None
  36. None
  37. None
  38. None
  39. None
  40. None
  41. None
  42. None
  43. None
  44. None
  45. /calendar.add.php —> {old crusty code} /calendar —> {new framework}

  46. https://pixabay.com/vectors/zombie-undead-monster-frankenstein-156055/ https://slides.com/andysnell/zombie-hunt

  47. None
  48. None
  49. Microservices

  50. Microservices (+ the monolith)

  51. Microservice S

  52. "Micro"services

  53. /users /customers /sales /weather

  54. https://speakerdeck.com/omnicolor/break-off-midwest https://twitter.com/omnicolor Omni Adams omni@digitaldarkness.com Givelify