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

ControllerGenerator::generate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 4
1
<?php
2
3
namespace Starkerxp\StructureBundle\Generator;
4
5
use Symfony\Component\HttpKernel\Bundle\Bundle;
6
7
class ControllerGenerator extends AbstractGenerator
8
{
9
10 View Code Duplication
    public function generate(Bundle $bundle, $libelle, Bundle $bundleEntite, $libelleEntite)
0 ignored issues
show
Unused Code introduced by
The parameter $bundleEntite is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $libelleEntite is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
11
    {
12
        $parameters = $this->getParamaters($bundle, $libelle);
13
        $parameters['nomService'] = strtolower(
14
            str_replace(['_Bundle', '@'], '', preg_replace('#\B([A-Z])#', '_\1', $parameters['namespaceBundle']))
15
        );
16
        foreach ($this->getFichiers() as $fichier) {
17
            try {
18
                $this->kernel->locateResource("@StarkerxpStructureBundle/Resources/views/Gabarit/".$fichier.".twig");
19
            } catch (\InvalidArgumentException $e) {
20
                throw new \InvalidArgumentException('Il manque un fichier de template');
21
            }
22
            $target = $bundle->getPath().str_replace($this->getClef(), [$libelle, lcfirst($libelle)], $fichier);
23
            $this->traiterLeFichier($fichier, $target, $parameters);
24
        }
25
    }
26
27
    public function getParamaters(Bundle $bundle, $libelle)
28
    {
29
        return array(
30
            'nomController' => $libelle,
31
            'nomControllerCamelize' => preg_replace('#\B([A-Z])#', '_\1', $libelle),
32
            'namespace' => $bundle->getNamespace(),
33
            'namespaceBundle' => '@'.$bundle->getName(),
34
            'namespaceFQC' => str_replace('\\', '\\\\', $bundle->getNamespace()),
35
        );
36
    }
37
38
    public function getClef()
39
    {
40
        return ['_nomController_', '_lnomController_'];
41
    }
42
43
    public function getFichiers()
44
    {
45
        return [
46
            '/Controller/_nomController_Controller.php',
47
            '/Tests/Controller/_nomController_ControllerTest.php',
48
            '/Form/Type/_nomController_Type.php',
49
            '/Resources/config/routing.yml',  // Il faut récupérer la locale par défaut afin de générer le bon fichier.
50
            //'/Resources/translations/_lnomController_._defaultLocale_.yml',  // Il faut récupérer la locale par défaut afin de générer le bon fichier.
51
        ];
52
    }
53
}
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...
54