Skip to main content

Running pdepend on PHP7

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

Being a good citizen of the PHP community we do test out internal libs against the current PHP7 codebase. So far we had no issues but then at one day one of our Jenkins PHP7 jobs failed. After investigating a bit it turned out that the problem was not part of our codebase but part of of pdepend. The pdepend process died with the error message that "T_CHARACTER and T_BAD_CHARACTER are no longer defined" which is true. The error was already reported as an issue on Github. As I do not like broken jobs in Jenkins I was looking for a fix which in the end was pretty easy. The basic idea was to skip the execution of pdepend in our Phing script when running on our PHP7 buildnodes.

This is how our -ci:prepare Phing task looks like:

<target name="-ci:prepare"
description="Prepare for the build"
hidden="true">

<mkdir dir="${phing.dir}/build/coverage"/>
<mkdir dir="${phing.dir}/build/logs"/>
<mkdir dir="${phing.dir}/build/pdepend"/>
</target>

I changed the "code" to this. As an outcome the "pdepend.enabled" variable is set if Phing is running on PHP < 7.0.0.

<target name="-ci:prepare"
description="Prepare for the build"
hidden="true">

<!--
pdepend 2.1.0 has issues running on PHP7, skipping the execution
if PHP7 platform is detected
-->
<if>
<not>
<contains
string="${php.version}"
substring="7." />
</not>
<then>
<property
name="pdepend.enabled"
value="true"
override="true" />
</then>
</if>

<mkdir dir="${phing.dir}/build/coverage"/>
<mkdir dir="${phing.dir}/build/logs"/>
<mkdir dir="${phing.dir}/build/pdepend"/>
</target>

Last not least I had to add an "if" check to our main pdepend target like this:

<target name="ci:pdepend"
depends="-init, -ci:prepare"
if="pdepend.enabled">

<resolvepath propertyName="pdepend.path.abs" dir="${phing.dir}" file="${pdepend.path}"/>
<resolvepath propertyName="pdepend.log.abs" dir="${phing.dir}" file="${pdepend.log}"/>
<resolvepath propertyName="pdepend.chart.abs" dir="${phing.dir}" file="${pdepend.chart}"/>
<resolvepath propertyName="pdepend.pyramid.abs" dir="${phing.dir}" file="${pdepend.pyramid}"/>

<exec executable="${pdepend.path.abs}"
passthru="true"
checkreturn="true">
<arg value="--jdepend-xml=${pdepend.log.abs}" />
<arg value="--jdepend-chart=${pdepend.chart.abs}" />
<arg value="--overview-pyramid=${pdepend.pyramid.abs}" />
<arg path="${phing.dir}/src" />
</exec>
</target>

What happens now is that the ci:pdepend target will only run if the "pdepend.enabled" variable is set. If the variable is not set the exectution of the target is skipped. Best of all: No error gets thrown when the target is skipped.