Kategorie: Tutorial

Let CodeSniffer inspect your code in PhpStorm

Some time ago I wrote an article on how to format your code automatically in PhpStorm to be conform the PSR standards. In this article I want to show you how you can enable inspections in PhpStorm which throws a warning if you have code which is not PSR, e.g.

  • Whitespace at the end of line
  • No newline at the end of file
  • No newline between namespace and use statements
  • etc…

This is pretty easy. We will use squizlabs/PHP_CodeSniffer from Github.

Read More

It's only fair to share...Share on FacebookTweet about this on TwitterShare on RedditEmail this to someoneShare on Tumblr

How to automatically append text to a git commit message

In our company, we are using a ticketing system that has Git integration. When commiting, you can reference the ticket with „refs #{Ticket-ID}“ and the ticket system automatically shows the commits that are conherent to the ticket. This is pretty simple to execute, but not everyone in the company uses it, because it gets forgotten most of the time, so I decided to write a script that automatically appends the text to a commit message, without anyone having to worry about it.

In our case, when creating feature branch we have a naming convention, that is defined as following feature/{Ticket-ID}_{Ticket-Name} which allows us to quickly find feature branches on a remote.

Now lets head to the script:

BRANCH=`git branch | grep '^\*' | cut -b3-`

echo "$1"
if [[ $BRANCH =~ $re ]];
echo "refs #"$BASH_REMATCH >> "$1";

Let me explain the script. This first two lines are simply getting the current name of the branch and defining a regex for finding the Ticket ID. The rest of the script simply checks whether the current branch name matches the regex, and if it does, adds „refs #{Ticket-ID}“ to the commit message. Otherwise, the original commit message will be used.

If you want to use this script, you have to navigate to your .git folder. Now create (if not exists) a hook folder and the folder/file

mkdir hooks && cd hooks && touch prepare-commit-msg && chmod a+x prepare-commit-msg && nano prepare-commit-msg

If you don’t have nano or don’t want to use it, forget the part after the last two ampersands and open the file how you like. Then copy the code from above into your that file, save it, and test it with a new commit. In my case it looks like this.

Screenshot 2015-07-22 16.50.16 Kopie

As you can see, I just added `test` as a commit message, however, the prepare-commit-msg hook automatically added refs #{Ticket-ID} to the message. Happy coding!

It's only fair to share...Share on FacebookTweet about this on TwitterShare on RedditEmail this to someoneShare on Tumblr

Fix it the right way! – SSL Error: unable to get local issuer certificate

If you use cURL on your private machine or server you may experience some problems connecting to websites using https or redirecting you to a https version of the website. One example for this problem is the Facebook Graph API. XAMPP as an example doesn’t ship with any certificates so you have to fix this problem by yourself.

Read More

It's only fair to share...Share on FacebookTweet about this on TwitterShare on RedditEmail this to someoneShare on Tumblr

Install PHP Mess Detector – phpmd – for PHPStorm

Hello fellow coders,

in this article I want to show you how to install PHP Mess Detector and allow it to work with PHPStorm.

What PHPMD does is: It takes a given PHP source code base and look for several potential problems within that source. These problems can be things like:

  • Possible bugs
  • Suboptimal code
  • Overcomplicated expressions
  • Unused parameters, methods, properties

Please continue reading now: For this tutorial I’m using composer. Some of you might turn around now because they don’t want to use composer and just want to download a zip and install it. But I can assure you that installing something with composer does only take about 30 seconds and it works.

So let’s start. For myself I have a folder ‚work‘ where I store all my projects. In this folder I created a new one named ‚composer‘. If you have done this navigate to the folder and create a file called composer.json

Now, for phpmd to work you also need phpdepend. To get phpdepend you just prepend a line to the composer.json file. Your finished composer.json file should look like this.

    "require": {
        "pdepend/pdepend" : "1.1.0",
        "phpmd/phpmd" : "1.4.*"

This tells composer to download phpdepend and afterwards phpmd. It’s simple as that.

Next step is to download composer.phar from here and put it into the composer folder you created before. Now, simply navigate in your terminal/console to the composer folder. In my example it would be


Next step is to locate your php executable. This is done by typing

 which php 

into the console. For me my php executable is located under /usr/bin/php

When you’ve done all this you need to let composer install the dependencies. Simply type

/usr/bin/php composer.phar install

into the console and the composer does the rest. Open PHPStorm and navigate through the menu bar to your preferences. In the preferences search for PHP Mess Detector and chose the result found under the PHP tree. In the path just navigate to your phpmd executable. In my example it would be


Press the validate button to be sure, that the path is correct and everyting is loaded correctly. Afterwards go to Inspections, search again for PHP Mess Detector validation and activate it by clicking on the checkbox. You also need to check the checkboxes on the right to activate some rules you want. For an overview about the rules go here.


Bildschirmfoto 2014-07-16 um 09.55.47


If you now hit Apply on the preferences and give the project some time to reload you should be able to use PHP Mess Detector with your activated rules. Happy coding

It's only fair to share...Share on FacebookTweet about this on TwitterShare on RedditEmail this to someoneShare on Tumblr