News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Andrew Podner:
NPATH Complexity Demystified
November 14, 2012 @ 10:55:57

In a new post to his site today Andrew Podner takes a look at NPATH and tries to "demystify" some of the concepts around it.

"NPATH, which counts the acyclic execution paths through a function, is an objective measure of software complexity related to the ease with which software can be comprehensively tested."[1] This is the definition from an article written in 1988 by Brian Nejmeh. As informative as this is, my eyes glazed over half way into it. So what the heck is acyclic execution anyway?

He defines the term in a bit easier to understand language and includes an example function to help illustrate how NPATH is measured.

The goal is to limit your NPATH complexity in a given method down to 200 or less. [...] As with other complexity metrics, this one can be checked with PHP Mess Detector (phpmd). The importance of staying under the 200 path threshold is realized when you develop tests and start trying to debug.
0 comments voice your opinion now!
npath complexity cyclomatic introduction phpmd phpmessdetector


Sebastian Bergmann's Blog:
CRAP in PHPUnit 3.5
January 12, 2010 @ 11:14:03

As Sebastian Bergmann mentions in his latest post, he's changed up how the code coverage functionality is handled in PHPUnit so that he can add something new - CRAP.

PHP_CodeCoverage is a component that provides collection, processing, and rendering functionality for PHP code coverage information. [...] Having all code that deals with code coverage in a separate component allows for easier development and better testing. The first result of these improved development conditions is a small new feature that I recently implemented, the support for the CRAP metric.

Your code's CRAP (Change Risk Analysis and Predictions) scoring combines the idea of cyclomatic complexity and code coverage statistics to try to guess at how difficult any given piece of code would be to maintain. You can see an example here - the lower the number the better.

0 comments voice your opinion now!
crap cyclomatic complexity codecoverage phpunit unittest


Jacob Santos' Blog:
What is your C.R.A.P. Index?
August 07, 2007 @ 11:57:00

In relation to a recent announcement from Sebastian Bergmann about the inclusion of Cyclometic Complexity testing in the upcoming PHPUnit release, Jacob Santos has taken a look at its use - find the C.R.A.P. of a process.

The Change Risk Analysis and Predictions (CRAP) index is to give some idea how difficult it would be to maintain the code base. It is not to be used in evaluating how "beautiful" the code is.

He had to modify things slightly in PHPUnit to get it to work with entire files/functions, but it was still simple to use the testing software to create each file's CRAP index. For his examples, he chose the WordPress code and includes the code he used for the tests - two functions: getCCLevel and getCrapIndex. The results of the report are also included.

1 comment voice your opinion now!
phpunit crap index cyclomatic complexity unittest phpunit crap index cyclomatic complexity unittest


Sebastian Bergmann's Blog:
PHPUnit and Software Metrics
August 03, 2007 @ 12:06:00

In a update to his recent post on Cyclomatic Complexity in PHPUnit, Sebastian Bergmann has given more information about the software metrics support that the upcoming release (3.1.6) of PHPUnit will offer.

The upcoming 3.1.6 release of PHPUnit adds a couple of software metrics to the data that is stored in PHPUnit's test database.

Among the metrics gathered are things like: lines of code, commented lines of code, an attribute inheritance factor, depth of inheritance tree, method hiding factor and a polymorphism factor (he links each of these more complex ones for more information on the subject). Still included in the post is an example of the output for the Cyclomatic Complexity metric.

0 comments voice your opinion now!
phpunit software metric level file class method cyclomatic phpunit software metric level file class method cyclomatic


Sebastian Bergmann's Blog:
PHPUnit and Cyclomatic Complexity
August 02, 2007 @ 07:56:00

Sebastian Bergmann mentions today about a feature in an upcoming release of a popuular unit testing tool for PHP, PHPUnit - the addition of more software metrics.

The upcoming 3.1.6 release of PHPUnit adds a couple of software metrics to the data that is stored in PHPUnit's test database. Among these metrics is the Cyclomatic Complexity Number (CCN).

An example of how the CCN works is shown in the post giving the className, methodName and the complexity ranking given for the combination. His example shows the rankings for a part of the eZ Components software.

0 comments voice your opinion now!
phpunit unittest cyclomatic complexity database software metrics phpunit unittest cyclomatic complexity database software metrics


Jim Plush's Blog:
Cyclomatic Complexity for the Test Driven PHP'er
June 05, 2006 @ 14:45:55

Unit testing in PHP applications is growing more and more in popularity, so much so that some developers get into it, test all of their code and aren't exactly sure when enough is enough. Jim Plush has a suggestion for those kinds of testers - consider the cyclomatic complexity.

It's one of the most common questions you ask when you first start using Test Driven Development or Unit Testing in general... When am I done?

It's the point you feel confident when all your tests exercise the code in your classes. How do I know when that point is? I've come across a new way of finding this point using something called cyclomatic complexity. Developed by Thomas McCabe in the 70's cyclomatic complexity is a simple measurement of how complex a piece of code is. One of the nice parts of it is that you can use it when working with unit tests.

To illustrate, he gives a simple example of a function with only a function call and return inside. This has a cyclomatic complexity rating of 1 (the lowest). Now, start adding in ifs, loops, and other ways for the data to go and you start adding more complexity levels. Jim suggests that this can be another useful unit testing measurement - one more unit test for each level of complexity.

He also notes a pleasant side effect of this sort of classification:

The other nice part of a CC number is you can quickly find out when a method is ripe for refactoring. If you have a method with a CC number of 20 you know you most likely have a problem on your hand.
1 comment voice your opinion now!
cyclomatic complexity unit testing levels refactoring cyclomatic complexity unit testing levels refactoring



Community Events





Don't see your event here?
Let us know!


opinion deployment list release tips laravel symfony interview framework community introduction update podcast install package zendserver library language series api

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework