Basic tools for analyze PHP Code

If you get enrollment into a new work to maintain  Php project with millions of thousands of  lines of code written these tools can be one of your best friends.

phploc: phploc is a tool for quickly measuring the size of a PHP project.

install on fedora 15:

su

yum install php-phpunit-phploc.noarch

usage:

phploc <php source code dir>

phpdcd: phpdcd is a Dead Code Detector (DCD) for PHP code. It scans a PHP project for code that is no longer used.

install on fedora 15:

su

yum install php-phpunit-phpdcd.noarch

usage:

phpdcd  <php source code dir>

phpcpd: phpcpd is a Copy/Paste Detector (CPD) for PHP code. It scans a PHP project for duplicated code.

install on fedora 15:

su

yum install php-phpunit-phpcpd.noarch

usage:

phpcpd <php source code dir>

if your project is enormous you will need another key tools: Hope, Faith and Hard Work

more info about these tools and more at http://sebastian-bergmann.de/software/

Using Logical Or in Perl regex


#!/usr/bin/perl

use strict;
use warnings;

my %colors=( "life" , "white or black",
 "cat" , "black",
 "horse" , "white or black",
 "blood",    "red",
 "sky" ,"blue");

foreach my $coloredThing (keys %colors)
{
 print "$coloredThing ";
 if ($colors{$coloredThing}=~m/(black|white)/)
 {
 print "Match";
 }
 else
 {
 print "Doesn't Match";
 }
 print "\n";
}

and here the Output

sky Doesn’t Match
blood Doesn’t Match
cat Match
horse Match
life Match