Break Off SunPHP20

3d55a954b25a01f3f895eb20f7c48714?s=47 Omni Adams
February 07, 2020

Break Off SunPHP20

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.

3d55a954b25a01f3f895eb20f7c48714?s=128

Omni Adams

February 07, 2020
Tweet

Transcript

  1. Break Off A Piece of That Monolith

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

    When I Work — Sunshine PHP 2020 lith
  3. https://commons.wikimedia.org/wiki/File:Spaghetti,_cooked,_in_bowl.jpg

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

  5. https://www.flickr.com/photos/tambako/3589021887

  6. https://www.flickr.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 definition 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. Static Analysis PHP_CodeSniffer PHPStan

  22. ------ ---------------------------------------------------------------------- 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 undefined method Error::new_error(). 36 Constant APP_ROOT not found. 199 Constant REQ_TERM_FULL_TIME not found.
  23. Refactoring Breaking up big pieces of code Pulling procedural code

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

  25. Refactoring: Small for the win?

  26. Refactoring: Just right

  27. The Strangler Pattern

  28. https://www.flickr.com/photos/vancouver-archives/8229393567

  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. None
  47. None
  48. Microservices

  49. /users /customers /sales /weather

  50. https://speakerdeck.com/omnicolor/break-off-sunphp20 https://twitter.com/omnicolor Omni Adams omni@digitaldarkness.com When I Work https://joind.in/talk/a79da