RestGeneratorTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 10.2 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 5
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testImpresaRestGenerator() 5 42 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Yoghi\Bundle\MaddaBundle\Generator;
4
5
/*
6
 * This file is part of the MADDA project.
7
 *
8
 * (c) Stefano Tamagnini <>
9
 *
10
 * This source file is subject to the GPLv3 license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13
14
use Yoghi\Bundle\MaddaBundle\Finder\Finder;
15
use Yoghi\Bundle\MaddaBundleTest\Utils\AbstractCommonLogTest;
16
use Yoghi\Bundle\MaddaBundleTest\Utils\FileCompare;
17
use Yoghi\Bundle\MaddaBundleTest\Utils\PhpunitFatalErrorHandling;
18
use Yoghi\Bundle\MaddaBundleTest\Utils\VfsAdapter;
19
20
/**
21
 * @author Stefano Tamagnini <>
22
 */
23
class RestGeneratorTest extends \PHPUnit_Framework_TestCase
24
{
25
    use AbstractCommonLogTest;
26
    use FileCompare;
27
    use PhpunitFatalErrorHandling;
28
29
    public function testImpresaRestGenerator()
30
    {
31
        $directoryOutput = self::$directoryV->url().'/output';
32
33
        if (!file_exists($directoryOutput)) {
34
            mkdir($directoryOutput, 0700, true);
35
        }
36
37
        $resourcesDir = __DIR__.'/../Resources';
38
39
        $rgen = new RestGenerator();
40
        $rgen->setLogger($this->logger);
41
        $rgen->generateRest($resourcesDir.'/raml/api.raml', new VfsAdapter($directoryOutput));
42
43
        // $finderV = new Finder();
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
        // $finderV->search($directoryOutput, 'php');
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
        // foreach ($finderV->getFindedFiles() as $file) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
        //     $namespace = str_replace('vfs://root/output/', '', pathinfo($file, PATHINFO_DIRNAME));
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
        //     $name = str_replace('.php', '', pathinfo($file, PATHINFO_FILENAME));
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
48
        //     $this->logger->info('$mappaToCheck[\''.$namespace.'\'] = \''.$name.'\';');
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
49
        // }
50
        // echo $this->readLog();
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
        // exit;
52
53
        $mappaToCheck = [];
54
        $mappaToCheck['AppBundle/Controller'][] = 'StatusController';
55
        $mappaToCheck['AppBundle/Controller'][] = 'BadgeController';
56
        $mappaToCheck['AppBundle/Controller'][] = 'WorkspaceController';
57
        $mappaToCheck['AppBundle/Controller'][] = 'StreamController';
58
59 View Code Duplication
        foreach ($mappaToCheck as $namespace => $classList) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
            foreach ($classList as $className) {
61
                $this->compareClassPhp($resourcesDir.'/raml/generated/'.$namespace, $namespace, $className, $directoryOutput, true);
62
            }
63
        }
64
65
        // $routingFile = 'AppBundle/Resources/config/routing.yml';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
        // $this->compareFile($resourcesDir.'/raml/generated/', $directoryOutput, $routingFile, false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
68
        $errors = $rgen->getErrors();
69
        $this->assertCount(0, $errors, 'errori durante la generazione');
70
    }
71
}
72