Legacy code is something we all deal with. How can you figure out where to start untangling the big ball of mud you've been handed.
Note: photos excluded from CC LIcense.
39. DANGER,WILL ROBINSON!!
Don’t confuse the map with
the territory.The metrics are
a map to the location of
possible problems in your
code.They are not your
code.
Use the metrics, don’t let the
metrics use you.
Publicity photo from “Lost in Space”
Tuesday, July 9, 13
40. COPY/PASTE DETECTION
Finds code duplication in your project. Extracting them into a
single method will make future maintenance easier It will also
shorten the methods including them.
Identical methods across multiple classes make good
candidates for inheritance orTraits.
https://github.com/sebastianbergmann/phpcpd
Tuesday, July 9, 13
41. PHPUNIT
The most popular automated unit testing framework for php,
used in most significant open source projects, such as Drupal,
Joomla, Zend Framework2, Symfony2, etc.
Calculates a CRAP index on the code as part of the coverage
report, but only for code executed as part of running the tests.
Manual: http://phpunit.de/manual/current/en/index.html (also
available in ePub and PDF files)
Code: https://github.com/sebastianbergmann/phpunit/
Tuesday, July 9, 13
42. PHP MESS DETECTOR
The PHP Project Mess Detector goes through single files or an
entire project looking for many potential problem areas. It has
some factors included in it, but you can create your own tests,
if you have others you’d like to rely on.
http://phpmd.org
Tuesday, July 9, 13
43. PHP DEPEND
PHP Depend is a small program that generates several
different reports about the condition of a code project it’s
pointed at.Aside from the “normal” reports, it produces two
graphics that are quite useful for giving you a general idea of
what you’re looking at: the Abstraction-Instability Chart and
the Overview Pyramid.
Code & Docs: http://www.pdepend.org/
Tuesday, July 9, 13
44. THE OVERVIEW PYRAMID
This is a high-level view of the metrics of the system. It
calculates the cyclomatic complexity, counts lines of code,
methods, classes and packages. It also counts the distinct
method calls, and “fan-out,” the references from a class to a
class in a different inheritance branch, and analyses the
inheritance heirarchy.
Tuesday, July 9, 13
45. OVERVIEW PYRAMID CHART
The overview Pyramid
charts for Drupal,Wordpress
and Joomla give us a “50,000
ft” view of the systems.
Tuesday, July 9, 13
46. ABSTRACTION AND
INSTABILITY
The Abstraction metric (0-1) is measure of how easily the
system can be expanded/modified.
The instability metric (0 - 1) is an attempt to measure the ease
of change.
Packages approaching [0,0] are rigid. Packages approaching [1,1]
are completely abstract, therefore useless.The “happy meridian”
is a diagonal through the center of the chart.
http://www.objectmentor.com/resources/articles/oodmetrc.pdf
Tuesday, July 9, 13
47. ABSTRACTION-INSTABILITY
CHART
These are the A-I charts for
Drupal,Wordpress, and Joomla.
Drupal has very few objects
but they’re well balanced.
Wordpress has more, but no
abstraction.
Joomla has a wide range of
objects, not all well-balanced.
Tuesday, July 9, 13
48. SYMFONY2
Here are the charts for the
Symfony2 framework.
The overview looks very
good, while the A-I chart
shows a well-distributed mix
of objects in the system.
Tuesday, July 9, 13