News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Zumba Engineering Blog:
Enforce code standards with composer, git hooks, and phpcs
April 15, 2014 @ 09:13:48

The Zumba Engineering blog has a new post looking at a way you can control code quality and standards with the help of Composer, git hooks and the PHP Code Sniffer (phpcs) tools.

Maintaining code quality on projects where there are many developers contributing is a tough assignment. How many times have you tried to contribute to an open-source project only to find the maintainer rejecting your pull request on the grounds of some invisible coding standard? [...] Luckily there are tools that can assist maintainers. In this post, I'll be going over how to use composer, git hooks, and phpcs to enforce code quality rules.

These three technologies are combined together to make a more seamless experience for the developer while keeping the code quality high. Their method makes use of the "scripts" (post-install-cmd) feature of Composer to, after the installation of all packages, set up a git hook script that will run the phpcs checks on pre-commit. It's a pretty simple shell script that kicks back any errors it might find before the user can commit their changes.

0 comments voice your opinion now!
code standards composer git hook phpcs codesniffer install precommit

Link: http://engineering.zumba.com/2014/04/14/control-code-quality

Kevin van Zonneveld:
It's Almost 2014 and We Are Still Committing Broken Code
December 30, 2013 @ 09:19:28

Kevin van Zonneveld has a new post that, while not PHP specific, does have a handy script that will help you stop committing broken code.

Whatever the reason, it's almost 2014 and we are still committing broken code. This needs to stop because best case: Travis or Jenkins prevent those errors from hitting production and it's frustrating to go back and revert/redo that stuff. A waste of your time and state of mind, you were already working on other things. Worst case: your error goes unnoticed and hits production.

To help resolve the problem, he suggests using the "hook" system common to most version control software. In his specific example, he shows the use of a pre-commit hook that fires off a bash script on the files being committed. He includes the full code for this bash script that includes a check for PHP scripts using the built in PHP linter (the "-l" option on the command line). He also includes the commands and updates you'll need to make to get it installed on git.

0 comments voice your opinion now!
git precommit hook syntax error bash script tutorial

Link: http://kvz.io/blog/2013/12/29/one-git-commit-hook-to-rule-them-all/

Freek Lijten's Blog:
Git commit hooks using PHP
July 06, 2011 @ 09:48:51

In this new post from Freek Lijten he looks at a set of git commit hooks written in PHP for making things happen before, during and post commit.

Git hooks are usually found inside the .git/hooks folder of your git repository. Git tends to provide sample hook files there which are postfixed with a .sample extension. These examples are written as shell scripts. Take a look at them if you want, but today we're talking PHP!

He briefly touches on the types of hooks you can set up and includes two example scripts showing a pre-commit lint test for the changed files and a check during the commit on the message given for a certain standard (in their case, it must start with a three letter code).

0 comments voice your opinion now!
git commit hook tutorial precommit postcommit commitmsg example


Graham Christensen's Blog:
Sane Pre-Commit Hooks for Symfony + Git
August 25, 2009 @ 13:49:16

Symfony users will want to check out this pre-commit hook for git from Graham Christensen that can help you keep your sanity in place by rebuilding some of the essentials when a commit is made.

Throughout my history of working with Symfony, I've noticed a trend that I'll make a minor edit in a database configuration file, forget to actually regenerate the models and forms, commit the edit, and then find several days later (when I do want to regenerate the models) that they're breaking. I then do this little dance of going through the history finding out where exactly I went wrong.

To remedy the situation he came up with a pre-commit hook that does the following:

  • rebuilds SQL from schemas
  • rebuilds models
  • rebuilds forms
  • rebuilds filters
  • inserts sample SQL data
  • loads all data from the fixture files

Full example code for the hook is included in the post.

0 comments voice your opinion now!
symfony framework precommit hook rebuild



Community Events





Don't see your event here?
Let us know!


symfony package community language composer release tool laravel framework update opinion podcast voicesoftheelephpant series application introduction security interview version library

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework