Are you...
Stop the madness! Let’s learn how to write readable PHP in this hands-on course.
VAT will be calculated during checkout by Paddle.
We support Purchasing Power Parity.
Buy Writing Readable PHP combined with other courses
and get an extra discount
Buy together with this ebook on cutting edge tactics in PHP 8, accompanied by videos and practical examples.
front-line-php.com
Buy together with this video course to get started with Pest and PHPUnit by Brent Roose & Freek Van der Herten.
testing-laravel.com
In a previous part we've mentioned that grouping code in paragraphs is good for readability. There's another advantage: it visualises the steps a function takes to get to a certain results. It makes sense to order those steps in a way that's natural to you, the programmer.
Our favorite technique of ordering a function's steps is by first handling all edge cases, and keep the last step in a function for the most important part: the "happy path". Here's an example where the happy path is handled first. Try to read it: you'll notice that, besides some code overhead, it's also more confusing to understand what this code does from a first read.
// core functionality comes first, special cases handled at the end
public function sendMail(User $user, Mail $mail)
{
if ($user->hasSubscription() && $mail->isValid()) {
$mail->send();
}
if (! $user->hasSubscription()) {
// throw exception
}
if (! $mail->isValid()) {
// throw exception
}
}
So instead, let's first check and handle all edge cases followed by the happy path as the last step of the function. Conveniently, it doesn't need to be wrapped in a condition anymore if all edge cases have already been handled.
// special cases handled first, core functionality comes later
public function sendMail(User $user, Mail $mail)
{
if (! $user->hasSubscription()) {
// throw exception
}
if (! $mail->isValid()) {
// throw exception
}
$mail->send();
}
"Writing Readable PHP" will give you some amazing tips on how to write clean and modern PHP applications. It's full of tips I learned myself over the years as a programmer and it's great to see them all come together in this book.
Freek and Christoph bring a ton of experience to the table. They make sure you have all the tools you need to keep your code readable for years to come.
Having spent more than 10 years writing PHP, I thought I knew everything I needed. I learned a lot more than I expected as an experienced developer, and can see a lot of benefit in this course for developers of any level.
“Clean code” covers a wide spectrum, but Freek and Christoph manage to boil the essence of beautiful programming down to a very useful set of guidelines. I especially recommend the section on static analysis for programmers looking to take their skills to the next level.
VAT will be calculated during checkout by Paddle.
We support Purchasing Power Parity.