Example #1
0
 /**
  * Run the task.
  *
  * @param array &$options Additional options.
  *
  * @return integer Number of errors.
  */
 public function run(&$options)
 {
     require 'SebastianBergmann/PHPCPD/autoload.php';
     $lib = realpath($this->_config->getPath() . '/lib');
     $factory = new File_Iterator_Factory();
     $files = array_keys(iterator_to_array($factory->getFileIterator($lib, 'php')));
     $detector = new SebastianBergmann\PHPCPD\Detector\Detector(new SebastianBergmann\PHPCPD\Detector\Strategy\DefaultStrategy());
     $clones = $detector->copyPasteDetection($files, 5, 70);
     $printer = new SebastianBergmann\PHPCPD\TextUI\ResultPrinter();
     $printer->printResult($clones, $lib, true);
     return count($clones);
 }
    /**
     * @covers       SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection
     * @covers       SebastianBergmann\PHPCPD\CodeClone::getLines
     * @dataProvider strategyProvider
     */
    public function testDetectingSimpleClonesWorks($strategy)
    {
        $detector = new SebastianBergmann\PHPCPD\Detector\Detector(new $strategy());
        $clones = $detector->copyPasteDetection(array(TEST_FILES_PATH . 'Math.php'));
        $clones = $clones->getClones();
        $this->assertEquals(TEST_FILES_PATH . 'Math.php', $clones[0]->aFile);
        $this->assertEquals(86, $clones[0]->aStartLine);
        $this->assertEquals(TEST_FILES_PATH . 'Math.php', $clones[0]->bFile);
        $this->assertEquals(150, $clones[0]->bStartLine);
        $this->assertEquals(28, $clones[0]->size);
        $this->assertEquals(68, $clones[0]->tokens);
        $this->assertEquals('    public function div($v1, $v2)
    {
        $v3 = $v1 / ($v2 + $v1);
        if ($v3 > 14)
        {
            $v4 = 0;
            for ($i = 0; $i < $v3; $i++)
            {
                $v4 += ($v2 * $i);
            }
        }
        $v5 = ($v4 < $v3 ? ($v3 - $v4) : ($v4 - $v3));

        $v6 = ($v1 * $v2 * $v3 * $v4 * $v5);

        $d = array($v1, $v2, $v3, $v4, $v5, $v6);

        $v7 = 1;
        for ($i = 0; $i < $v6; $i++)
        {
            shuffle( $d );
            $v7 = $v7 + $i * end($d);
        }

        $v8 = $v7;
        foreach ( $d as $x )
        {
            $v8 *= $x;
', $clones[0]->getLines());
    }
Example #3
0
 /**
  * @covers       SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection
  * @dataProvider strategyProvider
  */
 public function testStripComments($strategy)
 {
     $detector = new SebastianBergmann\PHPCPD\Detector\Detector(new $strategy());
     $clones = $detector->copyPasteDetection(array(TEST_FILES_PATH . 'e.php', TEST_FILES_PATH . 'f.php'), 8, 10, true);
     $clones = $clones->getClones();
     $this->assertCount(0, $clones);
     $clones = $detector->copyPasteDetection(array(TEST_FILES_PATH . 'e.php', TEST_FILES_PATH . 'f.php'), 7, 10, true);
     $clones = $clones->getClones();
     $this->assertCount(1, $clones);
 }