Copy & Paste Detection in PHPUnit 3.2

Sebastian Bergmann » 22 August 2007 » in New Features » 0 Comments

Version 3.2 of PHPUnit is shaping up nicely. In this blog posting I want to highlight another aspect of PHPUnit's new Project Mess Detector feature set.

Duplicate code can be hard to find, especially in a large project. Johann-Peter Hartmann of MAYFLOWER GmbH recently implemented Copy & Paste Detection for PHPUnit's growing set of features that extends its usage scenarios beyond "just unit testing" to a one-stop solution for quality assurance in PHP-based projects.

Here is an example of how PHPUnit 3.2 will report code duplication:
<?xml version="1.0" encoding="UTF-8"?>
<pmd-cpd version="PHPUnit 3.2.0">
  <duplication lines="12" tokens="56">
    <file path="/usr/local/src/ezcomponents/trunk/Graph/src/driver/svg.php"
               line="197"/>
    <file path="/usr/local/src/ezcomponents/trunk/Graph/src/driver/svg.php"
               line="248"/>
    <codefragment><![CDATA[
if ( !in_array( $color->__toString(), $this->drawnGradients, true ) )
{
    $gradient = $this->dom->createElement( 'linearGradient' );
    $gradient->setAttribute( 'id', 'Definition_' . $color->__toString() );
    $this->defs->appendChild( $gradient );

    // Start of linear gradient
    $stop = $this->dom->createElement( 'stop' );
    $stop->setAttribute( 'offset', 0 );
    $stop->setAttribute(
      'style',
      sprintf( 'stop-color: #%02x%02x%02x; stop-opacity: %.2F;',
               $color->startColor->red,
               $color->startColor->green,
]]></codefragment>
  </duplication>
Defined tags for this entry: , , ,

Trackback specific URI for this entry

0 Comments to "Copy & Paste Detection in PHPUnit 3.2"

Display comments as (Linear | Threaded)
  1. No comments

2 Trackbacks to "Copy & Paste Detection in PHPUnit 3.2"

  1. Manuel Pichler 18/11/2007 at 21:52
    This is the first release of the phpUnderControl tool. This tool aims to take the first steps with CruiseControl and PHP as easy as possible. phpUnderControl integrates three of the best PHP development tools into CruiseControl, combined with an easy se
  2. Sebastian Bergmann 19/11/2007 at 12:06
    Sebastian Bergmann and his contributors are proud to announce the immediate availability of PHPUnit 3.2. This release is a major improvement to the popular open source testing solution for PHP applications. It includes new features and bug fixes. High

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Submitted comments will be subject to moderation before being displayed.