Skip to main content

Running pdepend on PHP7

· 2 min read
Stephan Hochdörfer

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"

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

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"

pdepend 2.1.0 has issues running on PHP7, skipping the execution
if PHP7 platform is detected
substring="7." />
override="true" />

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

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"

<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}"
<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" />

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.