Posts tagged with refactor
It’s not legacy code — it’s PHP
"When it feels safe to make changes to code, it’s not really legacy code any longer".
Read more [medium.com]
Join thousands of developers
Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.
No spam. Unsubscribe anytime. You can also follow me on X.
Splitting a large Laravel Livewire Component
– www.csrhymes.com - submitted by Chris Rhymes
Splitting up a large Laravel Livewire component into more manageable and maintainable chunks
Read more [www.csrhymes.com]
Unconventional Laravel: Responsable Classes
– ryangjchandler.co.uk - submitted by Ryan Chandler
Sometimes your controllers can get rather large, especially if you have lots of conditions and data formatting. Have you ever considered moving some of that complexity out into a dedicated response class?
Read more [ryangjchandler.co.uk]
Going deep
Seb makes the case that subtracting things can be better than adding things.
Read more [sebastiandedeyne.com]
Gracefully deprecating foreign keys for a polymorphic relationship
– timacdonald.me - submitted by Tim Mac
Here's how to handle moving from a classic foreign key constrained relationship, to a polymorphic relationship in Eloquent, without impacting the end user.
Read more [timacdonald.me]
Unconventional Laravel: Custom Pipeline Classes
– ryangjchandler.co.uk - submitted by Ryan Chandler
Laravel makes use of the internal Pipeline class and it's more common in userland too, but have you ever considered tidying up these pipeline processes with custom pipeline classes?
Read more [ryangjchandler.co.uk]
Refactoring PHP: 4 actionable tips
Christop Rumpel shares some good tips on how to refactor code.
Read more [christoph-rumpel.com]
Legacy to Laravel: How to Modernize an Aging PHP Application
– tighten.co - submitted by Jamison Valenta
Here's how Tighten modernizes a legacy PHP application.
Read more [tighten.co]
Refactoring to Livewire polling
– johnbraun.blog - submitted by John Braun
John Braun shares why and how he refactored to Livewire polling and replaced the event-driven WebSockets approach.
Read more [johnbraun.blog]
Grandfathering in legacy
Here's a nice technique that you can use in legacy projects.
Read more [madewithlove.com]
Refactoring: Demeter-Wrapping
Geepaw Hill explains a way to avoid demeter violations.
Read more [www.geepawhill.org]
Directly assigning view variable
🔥 Applications often have the most lines of code within controller actions.
— Jason McCreary (@gonedark) April 13, 2020
One practice to streamline your code is directly assigning view variables.
This also limits the use of temporarily variables and promotes abstractions which make the code more readable. pic.twitter.com/m0JGsybQ9k
Writing readable PHP: decrease indentation by returning early
In this short post, I'd like to give you a tip on writing readable PHP.
Lazy Collections in Laravel Excel
– stefanzweifel.io - submitted by Stefan Zweifel
Stefan Zweifel recently had to refactor an Excel export which deals with thousands of rows. Lazy Collections helped solve all performance problems.
Read more [stefanzweifel.io]
How to refactor complex if statements
Have you every come across confusing if statements with complex conditionals such as this? I bet you did!
// please kill me 🤯
if (!(($this->shipping_country == "GB" || (strcmp($this-status, "Valid") !== 0)) {
To me, this is completely unreadable.
In the video below I show how I deal with this situation. Spoiler: add some tests around it and break the conditionals apart.
This video is part of the Mailcoach video course. It contains many more videos on how to write clear code. You can use this coupon code to get a nice discount of $10.
YES-I-WANT-TO-WRITE-READABLE-CODE
The Wall of Technical Debt
Mattias Verraes explains a method for making technical debt visible and negotiable.
Read more [verraes.net]
Automatically convert your code to PHP 7.4 syntax using Rector
In PHP 7.4, two new features were introduced that I'd like to use in my packages and projects: short closures and typed properties. Even though an IDE can help with converting to the new syntax, I'd don't want to manually hunt down all the places where the new syntax can be used. Lucky there's a tool that can do this work automatically.
Getting started with Domain Oriented Laravel
A couple of days ago my colleague Brent published a blogpost on Domain Oriented Laravel. In short, he makes the case for organising your code around business concepts or features. That might sound very "heavy" or daunting, but it's actually for easy to get started with.
In this short video I explain how you can use PhpStorm to refactor your code. Make up your own mind if you need this in your projects.
Extracting doesn’t guarantee simplicity
Extracting doesn’t guarantee simplicity. Sometimes extracting code into another module means I’ve smeared one “conceptual module” in my brain into two physical files. Now I can’t look at the whole thing at once, and their internal wiring is more prominent than it deserves. Oops.
— Dan Abramov (@dan_abramov) September 25, 2019
Read more [twitter.com]