PHP Lint has got your back

Eric Van Johnson
Feb 23, 2016 · 2 min read
Image for post
Image for post

Hopefully, you have one of those friends who has your back, who will step in and stop you from making a really, really stupid mistake. Because we all are fallible and whether it be in a moment of rage, or just because we are in a rush, we will make mistakes.

This is why I have PHP Lint added as a pre-commit hook on my PHP Project repos. It only takes a minute to set it up and will have you a ton of time, and headache in the future.

First, you need to make sure you have PHP Lint installed on your system. If you are a PHP developer, then the chances are you have it.

Next go to you PHP project .git directory and add the following code to the file .git/hooks/pre-commit

And that should be it. Now every time you do a commit on some PHP code, your git workflow will send each file through the PHP Linter to check for errors. See the example below

Most editors will show you when you make an error, but we are rushing and don’t notice that we forgot to add a semi-colon.

Image for post
Image for post

We add the file and attempt to do a commit but because of the hook, Git will refuse to commit the files, and we can sleep easier at night knowing we can’t accidentally send broken code to our repo.

One thing to note, this git hook will only parse the files you are committing and not the entire project. Meaning if you have a co-working was not doing linting, and you pull in their changes but don’t touch the file, your commit will not catch it.


Originally published at www.shocm.com on February 23, 2016.

DiegoDev Group

A groups of passionate developers who care about the code…

Eric Van Johnson

Written by

Company: @diegodevgroup | Podcaster: @PHPUgly / @larachatslack / @phparch | UG Org: @SDPHP | Enjoy Scotch and Baseball. Thoughts and tweets are my own. ☮

DiegoDev Group

A groups of passionate developers who care about the code they create, the communities they build, and the solutions they implement.

Eric Van Johnson

Written by

Company: @diegodevgroup | Podcaster: @PHPUgly / @larachatslack / @phparch | UG Org: @SDPHP | Enjoy Scotch and Baseball. Thoughts and tweets are my own. ☮

DiegoDev Group

A groups of passionate developers who care about the code they create, the communities they build, and the solutions they implement.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store