Completed
Push — master ( 36c459...78506e )
by Guillaume
02:39
created

EntiteGenerator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 16
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 16 16 3
A getParamaters() 0 9 1
A getClef() 0 4 1
A getFichiers() 0 12 1

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 Starkerxp\StructureBundle\Generator;
4
5
use Symfony\Component\HttpKernel\Bundle\Bundle;
6
7
class EntiteGenerator extends AbstractGenerator
8
{
9 View Code Duplication
    public function generate(Bundle $bundle, $libelle)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
10
    {
11
        $parameters = $this->getParamaters($bundle, $libelle);
12
        $parameters['nomService'] = strtolower(
13
            str_replace(['_Bundle', '@'], '', preg_replace('#\B([A-Z])#', '_\1', $parameters['namespaceBundle']))
14
        );
15
        foreach ($this->getFichiers() as $fichier) {
16
            try {
17
                $this->kernel->locateResource("@StarkerxpStructureBundle/Resources/views/Gabarit/".$fichier.".twig");
18
            } catch (\InvalidArgumentException $e) {
19
                throw new \InvalidArgumentException('Il manque un fichier de template');
20
            }
21
            $target = $bundle->getPath().str_replace($this->getClef(), [$libelle, lcfirst($libelle)], $fichier);
22
            $this->traiterLeFichier($fichier, $target, $parameters);
23
        }
24
    }
25
26
27
    public function getParamaters(Bundle $bundle, $libelle)
28
    {
29
        return array(
30
            'nomEntity' => $libelle,
31
            'namespace' => $bundle->getNamespace(),
32
            'namespaceBundle' => '@'.$bundle->getName(),
33
            'namespaceFQC' => str_replace('\\', '\\\\', $bundle->getNamespace()),
34
        );
35
    }
36
37
    public function getClef()
38
    {
39
        return ['_nomEntity_', '_lnomEntity_'];
40
    }
41
42
    public function getFichiers()
43
    {
44
        return [
45
            '/Resources/config/managers.yml',
46
            '/Entity/_nomEntity_.php',
47
            '/Manager/_nomEntity_Manager.php',
48
            '/Repository/_nomEntity_Repository.php',
49
            '/Tests/Manager/_nomEntity_ManagerTest.php',
50
            '/Tests/DataFixtures/_nomEntity_Manager/_nomEntity_Manager.yml',
51
            '/Tests/DataFixtures/_nomEntity_Manager/Default_nomEntity_.yml',
52
        ];
53
    }
54
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
55