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

EntiteGenerator::generate()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 17

Duplication

Lines 10
Ratio 40 %

Importance

Changes 0
Metric Value
dl 10
loc 25
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 17
nc 3
nop 1
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