Completed
Push — master ( b88100...c1b2a0 )
by Guillaume
02:38
created

EntiteGenerator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 23.81 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 10
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B generate() 10 25 3
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
6
class EntiteGenerator extends AbstractGenerator
7
{
8
    public function generate($entite)
9
    {
10
        $entite = explode(':', $entite);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $entite. This often makes code more readable.
Loading history...
11
        $bundle = $this->kernel->getBundle($entite[0]);
12
        $libelle = ucfirst($entite[1]);
13
14
        $parameters = [
15
            'nomEntity'       => $libelle,
16
            'namespace'       => $bundle->getNamespace(),
17
            'namespaceBundle' => '@'.$bundle->getName(),
18
            'namespaceFQC'    => str_replace('\\', '\\\\', $bundle->getNamespace()),
19
        ];
20
        $parameters['nomService'] = strtolower(str_replace(['_Bundle', '@'], '', preg_replace('#\B([A-Z])#', '_\1', $parameters['namespaceBundle'])));
21
22 View Code Duplication
        foreach ($this->getFichiers() as $template) {
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...
23
            try {
24
                $this->kernel->locateResource("@StarkerxpStructureBundle/Resources/views/Gabarit/".$template.".twig");
25
            } catch (\InvalidArgumentException $e) {
26
                throw new \InvalidArgumentException('Il manque un fichier de template');
27
            }
28
            // On génère le nom de fichier qui va être modifié ou généré.
29
            $fichierACreerModifier = $bundle->getPath().str_replace("_nomEntity_", $libelle, $template);
30
            $this->traiterLeFichier($template, $fichierACreerModifier, $parameters);
31
        }
32
    }
33
34
    public function getFichiers()
35
    {
36
        return [
37
            '/Resources/config/managers.yml',
38
            '/Entity/_nomEntity_.php',
39
            '/Manager/_nomEntity_Manager.php',
40
            '/Repository/_nomEntity_Repository.php',
41
            '/Tests/Manager/_nomEntity_ManagerTest.php',
42
            '/Tests/DataFixtures/_nomEntity_Manager/_nomEntity_Manager.yml',
43
            '/Tests/DataFixtures/_nomEntity_Manager/Default_nomEntity_.yml',
44
        ];
45
    }
46
47
}
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...
48