Making overloaded functions readable

Sometimes you might allow a function to accept multiple data types. I don’t know for certain if it’s the correct term but for the remainder of this post I’m going to call such a function overloaded. In this post I’d like to show you a little trick to make overloaded functions more readable. Let’s first […]

Continue reading →

Improving readability using array_filter

In this post I’d like to share a quick tip on how you can improve the readability of your code with array_filter. Today I was working on some code that looked something like this: class Address { … public function toArray() { $address = [ ‘name’ => $this->name, ‘street’ => $this->street, ‘location’ => $this->location, ]; […]

Continue reading →

Using collection macros in Laravel

Laravel 5.2 provides some nice additions to the framework. One handy feature that I don’t see listed in the release notes is that Collection now is macroable.  Using it’s macro function you can easily extend Illuminate\Support\Collection with your own custom functions. Take a look at this piece of code to uppercase every string in a collection. $uppercaseWords […]

Continue reading →

Making string concatenation readable in PHP

Probably all PHP developers know how to concatenate strings. The most popular method is using the .-operator.  For small concatenations using this operator works fine. When lots of strings or variables need to be combined it can become cumbersome. Here’s an example: $logMessage = ‘A ‘.$user->type.’ with e-mailaddress ‘.$user->email.’ has performed ‘.$action.’ on ‘.$subject.’.’; Wow, […]

Continue reading →