Code Duplication    Length = 45-45 lines in 2 locations

phpmetrics/tests/Metric/Class_/Complexity/SystemComplexityVisitorTest.php 1 location

@@ 14-58 (lines=45) @@
11
 * @group complexity
12
 * @group defect
13
 */
14
class SystemComplexityVisitorTest extends \PHPUnit\Framework\TestCase
15
{
16
    /**
17
     * @dataProvider provideExamples
18
     *
19
     * @param string $filename
20
     * @param string $class
21
     * @param float $rdc
22
     * @param float $rsc
23
     * @param float $rsysc
24
     */
25
    public function testLackOfCohesionOfMethodsIsWellCalculated($filename, $class, $rdc, $rsc, $rsysc)
26
    {
27
        $metrics = new Metrics();
28
29
        $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
30
        $traverser = new \PhpParser\NodeTraverser();
31
        $traverser->addVisitor(new \PhpParser\NodeVisitor\NameResolver());
32
        $traverser->addVisitor(new ClassEnumVisitor($metrics));
33
        $traverser->addVisitor(new SystemComplexityVisitor($metrics));
34
35
        $code = file_get_contents($filename);
36
        $this->assertNotFalse($code);
37
38
        $stmts = $parser->parse($code);
39
        $this->assertNotNull($stmts);
40
41
        $traverser->traverse($stmts);
42
43
        $metric = $metrics->get('A');
44
        $this->assertNotNull($metric);
45
46
        $this->assertSame($rdc, $metric->get('relativeDataComplexity'));
47
        $this->assertSame($rsc, $metric->get('relativeStructuralComplexity'));
48
        $this->assertSame($rsysc, $metric->get('relativeSystemComplexity'));
49
    }
50
51
    /** @return mixed[] */
52
    public function provideExamples()
53
    {
54
        return [
55
            [ __DIR__ . '/../../examples/systemcomplexity1.php', 'A', 2.5, 1.0, 3.5],
56
        ];
57
    }
58
}
59

phpmetrics/tests/Metric/Class_/Text/LengthVisitorTest.php 1 location

@@ 13-57 (lines=45) @@
10
 * @group loc
11
 * @group metric
12
 */
13
class LengthVisitorTest extends \PHPUnit\Framework\TestCase
14
{
15
    /**
16
     * @dataProvider provideExamples
17
     *
18
     * @param string $example
19
     * @param string $functionName
20
     * @param int $loc
21
     * @param int $lloc
22
     * @param int $cloc
23
     */
24
    public function testLineCountsAreWellCalculated($example, $functionName, $loc, $lloc, $cloc)
25
    {
26
        $metrics = new Metrics();
27
28
        $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
29
        $traverser = new \PhpParser\NodeTraverser();
30
        $traverser->addVisitor(new \PhpParser\NodeVisitor\NameResolver());
31
        $traverser->addVisitor(new ClassEnumVisitor($metrics));
32
        $traverser->addVisitor(new LengthVisitor($metrics));
33
34
        $code = file_get_contents($example);
35
        $this->assertNotFalse($code);
36
37
        $stmts = $parser->parse($code);
38
        $this->assertNotNull($stmts);
39
40
        $traverser->traverse($stmts);
41
42
        $metric = $metrics->get($functionName);
43
        $this->assertNotNull($metric);
44
45
        $this->assertEquals($lloc, $metric->get('lloc'));
46
        $this->assertEquals($cloc, $metric->get('cloc'));
47
        $this->assertEquals($loc, $metric->get('loc'));
48
    }
49
50
    /** @return mixed[] */
51
    public function provideExamples()
52
    {
53
        return [
54
            [ __DIR__ . '/../../examples/loc1.php', 'A', 21, 13, 8],
55
        ];
56
    }
57
}
58