Thursday, July 23. 2009Why I love PHPWhile working on PHP_Depend's parser I realized one major reason Why I love PHP, it's the flexibility of language. Even if you think you now know all ways to solve a problem, there is always one more way to solve it.
But to be serious, don't be worried, if you don't get it.
Posted by Manuel Pichler
in fun, php, php_depend, phpugdo, planet-php
at
19:22
| Comments (17)
| Trackbacks (0)
Tuesday, July 7. 2009The value of complexity metrics - Cyclomatic Complexity (1/2)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.
Posted by Manuel Pichler
in php, php_depend, phpugdo, phpundercontrol, planet-php, projects
at
21:20
| Comments (2)
| Trackbacks (0)
Defined tags for this entry: checkstyle, cyclomatic complexity, design quality, npath complexity, php_depend, quality assurance, software metrics
Monday, May 18. 2009PHP_Depend-0.9.5 releasedToday I released PHP_Depend 0.9.5, which contains many bug fixes and improvements. The main features of this release are PHP 5.3 namespace support and a more robust parser that ignores most kinds of syntax errors,
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
Posted by Manuel Pichler
in php, php_depend, phpugdo, planet-php, projects
at
22:21
| Comments (0)
| Trackbacks (0)
Saturday, February 21. 2009PHP_Depend-0.9.4 releasedToday I released PHP_Depend 0.9.4, which contains many bug fixes and improvements.
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
Posted by Manuel Pichler
in php, php_depend, phpugdo, planet-php, projects
at
21:15
| Comment (1)
| Trackbacks (0)
Monday, January 19. 2009PHP_Depend-0.9.3 releasedJust now I released PHP_Depend 0.9.3, the primary goal for this release was focused on less memory consumption. A run of PHP_Depend 0.9.2 against eZ Publish took up to 1GB and PHP_Depend 0.9.3 analyzes the same source with a memory limit of 160Mb.
From now on you will get the latest PHP_Depend version through the new pear channel pear.pdepend.org, for a few weeks I will keep the old pear channel. Enter the following pear commands to upgrade PHP_Depend's channel. mapi@arwen ~ $ pear channel-discover pear.pdepend.org mapi@arwen ~ $ pear uninstall xplib/PHP_Depend mapi@arwen ~ $ pear install pdepend/PHP_Depend Or checkout version 0.9.3 from the PHP_Depend subversion repository. mapi@arwen ~ $ svn co http://svn.pdepend.org/tags/0.9.3
Posted by Manuel Pichler
in php, php_depend, phpugdo, planet-php, projects
at
21:44
| Comments (2)
| Trackbacks (0)
Defined tags for this entry: optimization, performance, php5, php_depend, quality assurance, release announcement
Saturday, January 3. 2009Seven Things - Tagged by Kore NordmannNowadays there are some really strange online habits, like this I was tagged post. Even if I ignore most of those customs this time I will go on with Kore's blog post and tell seven things about me.
And now I will split the baton I got from Kore in seven pieces and pass it on:
These are the rules apparently:
Posted by Manuel Pichler
in php, phpugdo, planet-php
at
12:51
| Comments (0)
| Trackbacks (0)
Defined tags for this entry: online habits
Wednesday, December 31. 2008PHP_Depend-0.9.1 releasedJust 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
Posted by Manuel Pichler
in php, php_depend, phpugdo, planet-php, projects
at
10:31
| Comments (0)
| Trackbacks (0)
Defined tags for this entry: npath complexity, php5, php_depend, quality assurance, release announcement
Monday, December 15. 2008PHP_Depend-0.9.0 releasedToday I released version 0.9.0 of PHP_Depend. Beside bugfixes this release contains new features like a PHPUnit compatible xml-log.
mapi@arwen ~ $ pear channel-discover pear.xplib.de mapi@arwen ~ $ pear install xplib/php_depend
or as a subversion checkout of the 0.9.0 branch or tag. mapi@arwen ~ $ svn co http://svn.pdepend.org/branches/0.9.0 mapi@arwen ~ $ svn co http://svn.pdepend.org/tags/0.9.0 Feel free to report issues, bugs or just leave a comment here.
Posted by Manuel Pichler
in php, php_depend, phpugdo, planet-php, projects
at
15:04
| Comment (1)
| Trackbacks (0)
Defined tags for this entry: php5, php_depend, quality assurance, release announcement, software metrics
Friday, December 12. 2008Discover the diversityAre you also tired of all those monotonous and boring source code you read or write every day? No new challenges, always the same constructs and expression, must that really be so?
Fortunately do you use a programming language that comes with a wide range of opportunities to solve identical tasks in various ways. And here is a simple tip how you can bring variety in your source code with a single expression. Just use the whole range of valid
You should also vary the embedded expression which increases the number of possible solutions
In this sense, a lot of fun and a nice weekend... Sunday, November 23. 2008phpUnderControl 0.4.6 released
Posted by Manuel Pichler
in php, phpugdo, phpundercontrol, planet-php, projects
at
21:14
| Comments (2)
| Trackbacks (0)
Saturday, September 20. 2008Documentation error for "merge-phpunit"
There was a documentation error in the previously presented ant build file for the new
Beside this documentation error, there was a bug in version 0.4.3 related to the same topic, which is fixed now. So please make sure you have the latest version (at least 0.4.4) installed.
Posted by Manuel Pichler
in php, phpugdo, phpundercontrol, planet-php, projects
at
10:51
| Comments (0)
| Trackbacks (0)
Sunday, September 7. 2008phpUnderControl 0.4.3 releasedI currently released a new version of phpUnderControl. Beside some minor fixes this release comes with a new feature to aggregate test results of multiple PHPUnit runs.
Use the new cli command
Posted by Manuel Pichler
in php, phpugdo, phpundercontrol, planet-php, projects
at
19:11
| Comment (1)
| Trackback (1)
Defined tags for this entry: continuous integration, cruisecontrol, phpundercontrol, phpunit, release announcement
Sunday, July 27. 2008PHP_Depend-0.8.0 releasedToday I released the stable 0.8.0 version of PHP_Depend.
The previous list was taken from the PHP_Depend issue tracker. Feel free to report issues, bugs or just leave a comment here.
Posted by Manuel Pichler
in php, php_depend, phpugdo, planet-php, projects
at
16:02
| Comments (6)
| Trackbacks (0)
Wednesday, June 18. 2008PHP_Depend-0.8.0beta1 releasedThis new release of PHP_Depend took some time to be finished. This is because the initial idea of a simple adaption of JDepend evolved (supported thru this blog-post by Sebastian), and so PHP_Depend has become a complete software metric application. Many new features and enhancements have found their way into this version. One of the key features is the pluggable architecture for custom Loggers and Metric-Analyzers. This opens the possibility to hook own Logger- and Analyzer-implementations into the execution chain of PHP_Depend. Beside these architectural changes this PHP_Depend version is shipped with a large set of implemented software metrics. ClassLevel (Class)
CodeRank (Class, Package)An adaption of google's PageRank algorithm for classes and packages.
Coupling (Project)
Cyclomatic Complexity (Project, Method, Function)
Dependency (Package)For details see the following entry.
Hierarchy (Project)
Inheritance (Project)
NodeCount (Project, Package, Class, Interface)
NodeLOC (Project, Package, Class, Interface, Method, Function)
Due to the fact that PHP is a loosely typed programming language, PHP_Depend can only approximate some values. But the measured results can be improved with a good and complete source code documentation, because PHP_Depend takes advantage of different doc comment annotations ( Beside all these metrics, PHP_Depend also provides a new chart type, the "Overview Pyramid". The Overview Pyramid can be a handy tool to analyze legacy code. If you have read the book Object-Oriented Metrics in Practice you should know howto interpret the Overview Pyramid, all others have to wait for a detailed description. ![]() PHP_Depend Overview Pyramid for PHP_Depend This new version can be installed with the PEAR-Installer. Just discover the pear.xplib.de channel and install the latest PHP_Depend release. After PHP_Depend has been installed successfully, the new command line tool pdepend should exist.
mapi@arwen ~ $ pear channel-discover pear.xplib.de
mapi@arwen ~ $ pear install xplib/PHP_Depend-beta
mapi@arwen ~ $ pdepend --help
PHP_Depend 0.8.0beta1 by Manuel Pichler
Usage: pdepend [options] [logger] <dir[,dir[,...]]>
--jdepend-chart=<file> Generates a diagram of the analyzed packages.
--jdepend-xml=<file> Generates the package dependency log.
--overview-pyramid=<file> Generates a chart with an Overview Pyramid for the
analyzed project.
--summary-xml=<file> Generates a xml log with all metrics.
--coderank-mode=<*[,...]> Used CodeRank strategies. Comma separated list of
'inheritance'(default), 'property' and 'method'.
--suffix=<ext[,...]> List of valid PHP file extensions.
--ignore=<dir[,...]> List of exclude directories.
--exclude=<pkg[,...]> List of exclude packages.
--without-annotations Do not parse doc comment annotations.
--help Print this help text.
--version Print the current PHP_Depend version.
There is also a Subversion repository at http://svn.pdepend.org/, where the latest development version can be found. Please test this beta release and file bug-reports and feature-requests in the PHP_Depend bug tracker.
Posted by Manuel Pichler
in php, php_depend, phpugdo, planet-php, projects
at
16:39
| Comments (0)
| Trackbacks (0)
Defined tags for this entry: php, php_depend, quality assurance, release announcement, software architecture, software metrics
Sunday, March 30. 2008phpUnderControl 0.4.0 releasedA few minutes ago I have released the latest phpUnderControl 0.4.0 version. In addition to many minor fixes and improvements this version comes with three utility commands, that should simplify some common tasks. 1) Project deleteThe project delete command provides a simple way to delete a complete project with all its contents, including logs, artifacts and sources, from your CruiseControl installation. [mapi@arwen~]$ phpuc delete --project-name connectfour /opt/cruisecontrol 2) Project cleanI do not really like this feature, because I really dislike the idea to delete old builds and artifacts, but I must admit that I have mounted a 100 GB partition as artifacts directory. Due to the fact that this feature was requested by many phpUnderControl users, it is implemented in phpUnderControl 0.4.0. This command allows you to delete old logs and artifacts except a configurable number of the latests builds. The following command will remove all build results for the php-under-control except the last 20 builds. [mapi@arwen~]$ phpuc clean --project-name php-under-control \
--keep-builds 20 /opt/cruisecontrol
3) Project createThe project create command provides a cli wizard to set up a new CruiseControl project. The following command will create a new project for the PHPUnit BankAccount sample, checkout the latest svn version, create the required directories and finally prepare the ant build.xml and the CruiseControl config.xml. If you don't like XML or you have multiple projects, that share a common source/project layout, this command could be useful for you. [mapi@arwen~]$ phpuc project --version-control svn \
--version-control-url svn://svn.phpunit.de/.. \
--project-name BankAccount2 \
--source-dir . \
--test-case BankAccountTest \
--test-dir . \
--test-file BankAccountTest.php \
--schedule-interval 20 \
/opt/cruisecontrol
But I would always recommend to use the example build.xml and config.xml to set up a new project. Both files are completely documented and contain links to the original CruiseControl configuration reference. I will do my best to complete the missing documentation for the CruiseControl config.xml file and the new cli commands. Any help is welcome.
Posted by Manuel Pichler
in php, phpugdo, phpundercontrol, planet-php, projects
at
14:37
| Comments (12)
| Trackbacks (0)
« previous page
(Page 2 of 3, totaling 38 entries)
» next page
|
ProjectsFurther stuffCategories |


