Thursday, June 10. 2010

Today I have released the second beta version of phpUnderControl. Beside several minor tweaks and bug fixes, this release contains one additional feature I was asked for during the IPC in Berlin. This feature allows you to specify a maximum number of log entries that will be shown in the generated metric charts. This can be very useful once you have a project with a great amount of builds and the chart rendering gets slower and slower.

This feature adds a new option --max-number to phpUnderControl's chart command. To rebuild all your charts you can call phpUnderControl's shell script with the following command:

Thursday, April 29. 2010

As many of you may already have noticed, there will be a big change in my
career as a professional software engineer and architect this summer. Together
with Kore and Toby I am in the process of founding a company. The focus
of this company will be on services all around the whole quality life cycle in
PHP projects.

Under the hood of our company we will also offer support, trainings and
consulting for several quality assurance tools, like pdepend, phpmd and
phpUnderControl. For you, this opens a great opportunity. You can use the
tools and the documentation, as well as participate in the community, as
usual. But from now on you can also purchase professional support, if you get
stuck or need general assitance. And when you miss a feature or need an
individual extension for one of these tools, don't hesitate to contact us.

I am really excited what cool things will happen in the next couple of years
and I am looking forward to cowork with professionals like Toby and
Kore.

To finalize the little marketing for the company and its services I would
appreciate to meet you, your colleagues and your compmany, to give
presentations or into-depth trainings on one of the tools or on quality
assurance in general.

Sunday, January 31. 2010

Today I have released phpUnderControl version 0.5.1. It's a bug fix release that closes several issues open since a long time. First of all I would like to thank Sebastian Marek who was the main contributor to this releases, so a big thankyou to you.

Beside the new release some more things have changed. From now on the phpUnderControl development is hosted on github. This means that from now on the latest version of phpUnderControl can be obtained with the following command:

Sunday, December 6. 2009

After quite some time of silence around phpUnderControl I have bundled the 0.5.0 release today. Beside minor changes, bugfixes and enhancements this release contains one new major feature, the PHP_CodeBrowser.

phpUnderControl integrating PHP_CodeBrowser

The PHP_CodeBrowser is a separate application that collects various XML log files with different project metrics/violations and presents them in a browseable source view with syntax highligting. This tool is a contribution by the Mayflower GmbH, where it was developed and now shared with the Open Source Community. At this point I would like to thank Mayflower as a whole and in particular at Elger and Thorsten, which were responsible for all technical aspects of this contribution.

But why do we use a CruiseControl publishers instead of a regular ant (Your build tool here)target? The answer is really simple. The PHP_CodeBrowser must be the very last artifact generated for a project, which means it must also run after PHPUnit, to collect the test result logs. But in most setups PHPUnit is configured with failonerror="on" to mark a build as failed, when an error occured during the test execution. But with this configuration a following PHP_CodeBrowser target would never be executed by ant, because the build failed already. This cannot happen with a CruiseControl publisher which is always executed in a separated process.

If you create a new project with phpUnderControl's project command, phpUnderControl will automatically search for an installed PHP_CodeBrowser and add the required publishers to your config.xml file when it is present.

Tuesday, July 7. 2009

Software metrics are currently on everyone's lips and a frequently discussed topic. There are many conference talks, blog posts and other presentations that talk about software metrics. But to me it seems as if this subject is a closed book for many developers, so I decided to write this little post about a special category of software metrics, the complexity metrics.

Complexity metrics are a theoretical approach to measure the subjective complexity of a software fragment, where the words software fragment stand for a paraphrase for functions, methods, classes and nearly every logical unit that can be found in a software system. The most prevalent procedure to calculate complexity values is static code analysis, where an application parses the raw source code of a project, counts different statements and expressions and packs up the determined results in simple classification numbers. And with this information you already know the main concepts behind most software metrics, classification numbers and counting. As you can see there is no magic behind the scene, the only thing required is a good background knowledge to interpret those values.

The Cyclomatic Complexity Number or short CCN is the
oldest complexity metrics. The first time this software
metric was mentioned was 1976 by Thomas J. McCabe. This
metric counts the available decision paths in a software
fragment to determine its complexity. Each decision path
starts with one of the conditional statements from the
following list, so that it is fairly easy to detect them in
existing source code.

?

case

elseif

for

foreach

if

while

A look at this list of statements may result in the questions:
Is this list wrong, it doesn't list else and default?
But it is correct. The assumption is that both statements
will contain the defaut execution path of a program which
also exists when there are no special cases to capture.

Each decision path gets the value 1 and the sum of all these
values represents the Cyclomatic Complexity of the analyzed
software fragment. Note that each function and method also
counts with a value of 1 With this knowlegde we can now
calculate the complexity of the following example code:

<?php

class CyclomaticComplexityNumber

{

public function exampe( $x, $y )// (1)

{

if( $x > 23 || $y < 42)// (1)

{

for( $i = $x; $i >= $x &&amp; $i <= $y; ++$i )// (1)

{

}

}

else

{

switch( $x + $y )

{

case1: // (1)

break;

case2: // (1)

break;

default:

break;

}

}

}

file_exists('/tmp/log') or touch('/tmp/log');

}

Based on the previous definition the Cyclomatic Complexity
Number of the example code example is 5. But you may have
noticed that this approach does not capture all decision paths
that exist. We haven't catched those paths that came from the
by the boolean expression || line 6 and && line 8, and
the logical or expression in line 25. A variation of the
Cyclomatic Complexity Number that also captures those paths
is the so called CCN2. The CCN2 is the most widely used
variation of this software metrics. Tools like PHPUnit, PMD
and Checkstyle report it as Cyclomatic Complexity of an
analyzed software fragment.

Now we get a complexity value of 8 when we apply the CCN2
to the previous example, what is a growt of the software's
complexity of 60%.

Due to the fact that Cyclomatic Complexity Number was
originally invented for procedural programming languages,
this definition for the Cyclomatic Complexity Number still
misses one element to measure the complexity of an object
oriented software system. With the concept of exceptions a
software gets additional decision paths for each catch
statement used in the source code. While try contains
the code for the regular execution code without special
cases, similar to else and default statements.

?

&&

||

or

and

xor

case

catch

elseif

for

foreach

if

while

Now that we know what the Cyclomatic Complexity Number is,
what can we do with the measured information? We can find
the complexity hotspots in a system, for example the top
ten artifacts with the highest complexity, but this is only
important during an initial analyses phase to get the big
picture of an application. For a continuous inspection this
information is not so important. A continuous analyses
requires thresholds that help to categories calculated
values. During the time four values have emerged as good
thresholds for the Cyclomatic Complexity Number of a
software system.

A software fragment with a CCN value between 1-4 has
low complexity.

A complexity value between 5-7 is moderate and still
easy to understand.

Everything between 6-10 has a high complexity, while
everything greater 10 is very complex and hard to
understand.

You may ask, why should I care about the complexity of a
software system, where is the value of benefit in this
metric?

Mostly the complex parts of an application contain business
critical logic. But this complexity has negative impacts on
the readability and understandability of source code. Those
parts will normally become a maintainence and bug fixing
nightmare, because no one knows all the constraints, side
effects and what's exactly going on in that part of the
software. This situation results in the well known saying
"Never touch a running system" which in turn mostly ends
in copy&paste programming. The situation can even become
more critical when the original author leaves the
development team or the company.

Finally a small example how to apply the new knowledge
about the Cyclomatic Complexity Number, thresholds and the
negative impacts of complex software to an existing
development process. The following source listing shows
a complex method taken from PHP_Depend's source. This method
has a Cyclomatic Complexity Number of 16 and I must admit
that the original author needed some time to understand what
was going on in this method.

The first thing to do is to make sure that the test suite
is good enough to ensure that the required refactorings
will not change the public behavior of the component or
class. When this is donw and we are sure our that api
breaks will be detected by the test suitewe can start to
extract logic into separate methods.

The following example shows the result of the refactoring:

<?php

// ...

private function _countCalls(AbstractCallable $callable)

{

$called = array();

$tokens = $callable->getTokens();

$count = count($tokens);

for($i = $this->_findOpenCurlyBrace($tokens); $i < $count; ++$i){

if($this->_isCallableOpenParenthesis($tokens, $i) === false){

continue;

}

if($this->_isMethodInvocation($tokens, $i) === true){

$image = $this->_getInvocationChainImage($tokens, $i);

}elseif($this->_isFunctionInvocation($tokens, $i) === true){

$image = $tokens[$i - 1]->image;

}else{

$image = null;

}

if($image !== null){

$called[$image] = $image;

}

}

$this->_calls += count($called);

}

The subjective feeling of readability heavily depends on the
complexity of control structures, as we can see by a
comparison of the original and the refactored version of the
method example. The new version with its Cyclomatic Complexity
Number of 5 is much easier to read and understand.

This text is the first of two blog posts. The second article
will give a short introduction into the NPath Complexity
You liked this article and you are interested in this and
other quality assurence related topics? - Then you should
now order your copy of the Book Quality Assurance in PHP
Projects. The book talks about nearly all aspect of
quality assurence, with practical tips and expert knowledge
contributed by certain PHP professionals.

Wednesday, February 25. 2009

Just now I found in Felix's blog this excellent phpUnderControl tutorial that comes with useful tips and helping scripts. Because I think it is a really good source to get started with phpUnderControl I will link it here.

Saturday, September 20. 2008

There was a documentation error in the previously presented ant build file for the new merge-phpunit command of phpUnderControl. The @failonerror-attribute of the <exec />-tag in the merge target was set to false, which results in not failed CruiseControl builds To fix this behaviour, you must modify the merge target in your build.xml, so that it looks similar to the following example.

Wednesday, September 10. 2008

I recently released a bugfix version of phpUnderControl. Beside some minor view errors like the odd/even rows problem, the 0.4.4 release of phpUnderControl fixes a bug in the new merged phpunit logs feature, which doesn't cause CruiseControl to fail for such builds.

Wednesday, August 20. 2008

Even if there is not much noise around phpUnderControl and PHP_Depend at the moment, the development of both projects still goes on. Due to the fact that there are some personal movements in these days I have modified my priorities and everything evolves slower, but I plan to spend more time on these projects, at least from the last quarter of this year.

To put your minds on rest, the next release of phpUnderControl is nearly finished, so stay tuned.

Ok, the test run failed, but why did phpUnderControl say: All Tests passed?

The answer is really simple. Due to the fact that phpunit died, it didn't generate any log file and previous log files still reside in build/logs. Because CruiseControl cannot know anything about these outdated build artifacts, it still publishes them as result for last build.

At this moment I realized that I have never mentioned a clean-target for the antbuild.xml file, neither in the example file nor in a blog post or the FAQ. So now its time to catch up on this topic.

You should add an additional target to your antbuild.xml file, that removes all log files and build artifacts of previous builds, before the main build cycle starts.