Linting All Your PHP Files

The Problem

The PHP CLI has a cool feature (-l) that allows you to check a file to see if it has any syntax errors:

scotts-air:~ scottkeckwarren$ php -l test.php 
Parse error: parse error, expecting `"function (T_FUNCTION)"' in test.php on line 5
Errors parsing test.php

The downside to this is that it doesn’t work on a whole directory. So unless you’re willing to add every new file to a script it’s not a quick way to check all your files before deployment.

The Solution

With some command line magic we can have it run on all the PHP files in our application:

find -L application -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l

I find it helpful to run my template files through this process as well:

find -L application -name '*.phtml' -print0 | xargs -0 -n 1 -P 4 php -l 

Converting Laravel 6.x Migrations to MySQL

Laravel Logo

I’ve had trouble knowing what to put in my migrations’ up() and down() functions. The Laravel Docs include a lot of information but I wanted a quick reference guide for myself to convert Laravel migrations to MySQL commands because that’s what I’m used to. :-)

I also spend some time compiling this into a Cheetsheet if you want a printable version of this post.

Read More

Link Post and Podcast Roundup: January 2020 Edition

Link Post Logo

January’s links.

Read More

Looking Back at 2019 and Looking Forward to 2020

Looking Back at 2019 and Looking Forward to 2020 Header Image

Happy 2020 everyone! As we normally try to do this time of year it’s time take a little retrospective on what’s been done over the last year and what we want to accomplish in the coming year.

Read More

What the F*ck Is With All the Artisan Commands: Make Test

Laravel Logo

Read More

New Layout!

New Layout

Welcome to the new layout for! This redesign has been on our minds for a while now and it’s great to be able to finally get it out to everyone!

Setting Up Better PHPUnit to Run Inside a Vagrant VM

PHPUnit Logo

For the last several months, I’ve been using Visual Studio Code for all my PHP projects. I started using Better PHPUnit to run my unit tests because it has a quick keyboard shortcut to run a specific unit test from inside Code. I just set Better PHPUnit up on a new computer I forgot a couple of hoops I had to jump through in order to get it to run inside my Vagrant VM. This post is documentation so I won’t forget and that will hopefully help someone else.

Read More

Link Post and Podcast Roundup: December 2019 Edition

Link Post Logo

December’s links.

Read More

Debugging the Eloquent Query Builder

Laravel Logo

The other day I had an Eloquent query that wasn’t returning what I expected it to. I started looking for a way to determine what was happening “under the hood” so to speak. It turns out it’s very simple.

// Enable query log

$users = User::where('email', '=', '')->get();

// get the results

This will output something like the following:

array (
  0 => 
  array (
    'query' => 'select * from `users` where `email` = ?',
    'bindings' => 
    array (
      0 => '',
    'time' => 2.75,

Can we all agree dd() is the best thing for quick debugging ever?

Defining Relationships In Laravel 5.6 and 6.x

Laravel Logo

I wanted to take a quick break in my barrage of Artisan posts to write about defining one-to-many and many-to-many relationships in Laravel’s Eloquent. Eloquent also supports one-to-one relationships but I felt like those are used so rarely that I could skip it.

Read More

Join Our Mailing List!

View previous campaigns.

subscribe via RSS

All content copyright This Programming Thing 2012 - 2020
Blogging about PHP, MySQL, Zend Framework, MySQL, Server Administration and Programming in general