Entries tagged as npath complexity
Related tagsbug fix ant cli continuous integration php php5 phpmd phpundercontrol php_depend pmd release announcement sebastian marek software metrics static code analysis tokenizer checkstyle cruisecontrol cyclomatic complexity design quality phpunit php_codesniffer quality assurance conference hamburg phpugdo unconference arbit ipc karlsruhe kore talks overview pyramid software architecture software design book changes company consulting crazy css dortmund elephpant ext/filter ezcomponents fabien potencier fun lint logger phpbbq phpt phpug pirum quality static_reflection support testing thinkpad tools training unit test xml xpath zce zend certified engineer optimization performance cbo class interface size coupling between objects dbus derick annotations customization dashboard phpdoc rule set usability elger git github mayflower php_codebrowser thorsten article cologne php-magazin
Sunday, August 22. 2010
Sunday, April 25. 2010
I am proud to announce the 0.9.12 release of PHP_Depend. PHP_Depend is a low level static code analysis tool. It takes the given source and calculates several software metrics for the code. This data can be used by software-developers, architects and designers to control the quality of a software-product without time consuming code audits.
This new release of PHP_Depend has done a great step into the direction of a token free PHP_Depend version. This means future versions of PHP_Depend will work without the need to traverse linear token streams up and down, to measure metrics. Instead PHP_Depend will rely on it's internal abstract syntax tree, that represents the logical structure of the analyzed source code. With this solution it will be possible to implement several new features that will make PHP_Depend more useful, for example static callgraph analysis.
As always, you can get the latest PHP_Depend version from its PEAR channel: pear.pdepend.org:
mapi@arwen ~ $ pear channel-discover pear.pdepend.org mapi@arwen ~ $ pear install pdepend/PHP_Depend-beta
Or you can fetch the sources from the subversion reposition:
mapi@arwen ~ $ svn co http://svn.pdepend.org/trunk pdepend
And additionally you can find a repository mirror on github:
mapi@arwen ~ $ git clone git://github.com/manuelpichler/pdepend.git
Friday, August 7. 2009
The NPath complexity calculation was broken in PHP_Depend 0.9.6. This bug was fixed in PHP_Depend 0.9.7.
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.
A look at this list of statements may result in the questions:
Is this list wrong, it doesn't list
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:
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
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
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.
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:
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, December 31. 2008
Just now I released PHP_Depend 0.9.1, the major feature in this new version is an implementation of the NPath Complexity metric, beside that feature the main focus for this release was on performance improvements of the current implementation.
An additional test concept was introduced with the 0.9.* branch of PHP_Depend. Nightly builds test PHP_Depend against a series of open source projects to detect deadlocks like endless loop or similar issues. This procedure is also used to test each release candidate of PHP_Depend. The tested project are:
You can get the latest PHP_Depend version through its PEAR channel pear.xplib.de or as a subversion checkout of the 0.9.1 tag.
mapi@arwen ~ $ svn co http://svn.pdepend.org/tags/0.9.1
(Page 1 of 1, totaling 5 entries)