Conditions | 18 |
Paths | 1602 |
Total Lines | 47 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
55 | public function traiterLeFichier($fichier, $target, $parameters) |
||
56 | { |
||
57 | if (file_exists($target) && explode('.', basename($target))[1] == 'yml') { |
||
58 | $currentServices = Yaml::parse(file_get_contents($target)); |
||
59 | $newServices = Yaml::parse($this->render($fichier.'.twig', $parameters)); |
||
60 | // gestion de fichiers sans services ni parameters => routing |
||
61 | $listeDesParametres = !empty($currentServices['parameters']) ? array_keys($currentServices['parameters']) : []; |
||
62 | $listeDesServices = !empty($currentServices['services']) ? array_keys($currentServices['services']) : []; |
||
63 | $listeDesDeclarations = !empty($currentServices) ? array_keys($currentServices) : []; |
||
64 | $listeDesNouveauxParametres = !empty($newServices['parameters']) ? array_keys($newServices['parameters']) : []; |
||
65 | $listeDesNouveauxServices = !empty($newServices['services']) ? array_keys($newServices['services']) : []; |
||
66 | $listeDesNouvellesDeclarations = !empty($newServices) ? array_keys($newServices) : []; |
||
67 | |||
68 | $diffServices = array_diff($listeDesNouveauxServices, $listeDesServices); |
||
69 | $diffParametres = array_diff($listeDesNouveauxParametres, $listeDesParametres); |
||
70 | $diffDeclarations = array_diff($listeDesNouvellesDeclarations, $listeDesDeclarations); |
||
71 | if (empty($diffServices) && empty($diffParametres) && empty($diffDeclarations)) { |
||
72 | return false; |
||
73 | } |
||
74 | foreach ($diffServices as $libelle) { |
||
75 | $currentServices['services'][$libelle] = $newServices['services'][$libelle]; |
||
76 | } |
||
77 | foreach ($diffParametres as $libelle) { |
||
78 | $currentServices['parameters'][$libelle] = $newServices['parameters'][$libelle]; |
||
79 | } |
||
80 | foreach ($diffDeclarations as $libelle) { |
||
81 | $currentServices[$libelle] = $newServices[$libelle]; |
||
82 | } |
||
83 | $content = Yaml::dump($currentServices, 3, 4); |
||
84 | $flink = fopen($target, 'w'); |
||
85 | if ($flink) { |
||
86 | $write = fwrite($flink, $content); |
||
87 | if ($write) { |
||
88 | fclose($flink); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | return true; |
||
93 | } |
||
94 | // On ne modifie pas un fichier existant. |
||
95 | if (file_exists($target)) { |
||
96 | return false; |
||
97 | } |
||
98 | $this->renderFile($fichier.'.twig', $target, $parameters); |
||
99 | |||
100 | return true; |
||
101 | } |
||
102 | |||
126 |