php[architect] November 2018

(singke) #1
8 \ November 2018 \ http://www.phparch.com

FEATURE

Maintaining Laravel Applications


Jason McCreary


As the creator of Laravel Shift^1 I have a unique insight into Laravel applications. I’m


super sensitive about sounding like a sale pitch. So, I don’t want to talk about Shift
itself. I want to talk about the data derived from Shift and how that can be used to
help you write more maintainable Laravel applications.

1 Laravel Shift: https://laravelshift.com


At the time of this writing, Shift has
upgraded over 9,000 Laravel applica-
tions. Every time a Shift runs a log file
is created. Initially, these log files were
for debugging; a way for me to not only
offer support but log events that let me
know how I might improve its automa-
tion.
For full transparency, here’s an exam-
ple of one of the log files. Other than
the Shift number, the data is completely
anonymous. No copied code. No API
tokens. Just simple log messages (see
Output 1).
Now, this doesn’t seem like much.
But a lot of information can be derived
from these simple messages. What files
were upgraded? What features were
used? What packages were used? What
versions were used?
I mined these log files for metrics
and combined them with my own
insights and those from the community.
I offer these as advice for you to craft
conventional, maintainable Laravel
applications and hopefully discover
new ways to use Laravel.

Maintainable Conventions
There is such a thing as “The Laravel
Way,” and it’s not just the way Taylor
Otwell or Jeffrey Way write their
applications. A majority of Laravel
applications adopt the conventions set
by the framework. There are always
outliers, but I assure you things get very
difficult when it comes time to upgrade
those applications. The conventions
outlined here are driven by the data
derived from upgrading thousands of
Laravel applications. They have been
put into practice not only by Shift


through automation, but personally in
my own applications and those I work
on.

Avoid Overwriting Config Values
Config files are the most changed files.
While this makes sense, it can be pain-
ful when time to upgrade. Every major
release, and even a few minor releases,
include changes to the config files. Of

course, these config files are where
you set different options and values to
customize your application. Shouldn’t
you change them?
The short answer is yes. But the longer
answer is you should do so in a way that
you don’t edit the config file directly.
It sounds odd, but Laravel provides a
way for you to do this with environ-
ment variables. Unfortunately, many

Output 1


  1. *** Shift version: 0281cff03fee62f250253f1e485dc7a

  2. *** Cloning application...







  3. Shift 5.2: application did not contain references to SelfHandling










  4. Shift 5.2: could not upgrade middleware Data:






  5. ["application\/Http\/Middleware\/Authenticate.php",

  6. "application\/Http\/Middleware\/EncryptCookies.php",

  7. "application\/Http\/Middleware\/RedirectIfAuthenticated.php"]





  8. Shift 5.2: could not upgrade application/Providers/RouteServiceProvider.php










  9. Shift 5.2: could not patch application/Providers/RouteServiceProvider.php










  10. Shift 5.2: could not find User model path










  11. Shift 5.2: found additional uses of Event names










  12. Shift 5.2: matched core file: phpunit.xml with version: 5.1.










  13. Shift 5.2: matched core file: tests/TestCase.php with version: 5.1.










  14. Shift 5.2: matched core file:






  15. database/migrations/2014_10_12_100000_create_password_resets_table.php

  16. with version: 5.1.





  17. Shift 5.2: matched core file: public/.htaccess with version: 5.1.










  18. Shift 5.2: matched core file: config/broadcasting.php with version: 5.1.










  19. Shift 5.2: matched core file: config/cache.php with version: 5.1.










  20. Shift 5.2: matched core file: config/compile.php with version: 5.1.










  21. Shift 5.2: matched core file: config/database.php with version: 5.1.










  22. Shift 5.2: matched core file: config/filesystems.php with version: 5.1.










  23. Shift 5.2: matched core file: config/queue.php with version: 5.1.










  24. Shift 5.2: matched core file: config/view.php with version: 5.1.










  25. Shift 5.2: could not upgrade config files Data: {"1":"config\/auth.php",






  26. "2":"config\/mail.php","3":"config\/services.php","4":"config\/session.php"}





  27. Shift 5.2: could not upgrade package.json










  28. Shift 5.2: application contained phpspec/phpspec requirement of ~2.










  29. Shift 5.2: found customized namespace








  30. *** Shift ran in: 212.

Free download pdf