| Conditions | 18 |
| Paths | 1602 |
| Total Lines | 45 |
| 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 |
||
| 28 | public function traiterLeFichier($fichier, $target, $parameters) |
||
| 29 | { |
||
| 30 | if (file_exists($target) && explode('.', basename($target))[1] == 'yml') { |
||
| 31 | $currentServices = Yaml::parse(file_get_contents($target)); |
||
| 32 | $newServices = Yaml::parse($this->render($fichier.'.twig', $parameters)); |
||
| 33 | // gestion de fichiers sans services ni parameters => routing |
||
| 34 | $listeDesParametres = !empty($currentServices['parameters'])?array_keys($currentServices['parameters']):[]; |
||
| 35 | $listeDesServices = !empty($currentServices['services'])?array_keys($currentServices['services']):[]; |
||
| 36 | $listeDesDeclarations = !empty($currentServices)?array_keys($currentServices):[]; |
||
| 37 | $listeDesNouveauxParametres = !empty($newServices['parameters'])?array_keys($newServices['parameters']):[]; |
||
| 38 | $listeDesNouveauxServices = !empty($newServices['services'])?array_keys($newServices['services']):[]; |
||
| 39 | $listeDesNouvellesDeclarations = !empty($newServices)?array_keys($newServices):[]; |
||
| 40 | |||
| 41 | $diffServices = array_diff($listeDesNouveauxServices, $listeDesServices); |
||
| 42 | $diffParametres = array_diff($listeDesNouveauxParametres, $listeDesParametres); |
||
| 43 | $diffDeclarations = array_diff($listeDesNouvellesDeclarations, $listeDesDeclarations); |
||
| 44 | if(empty($diffServices) && empty($diffParametres) && empty($diffDeclarations) ){ |
||
| 45 | return false; |
||
| 46 | } |
||
| 47 | foreach ($diffServices as $libelle){ |
||
| 48 | $currentServices['services'][$libelle] = $newServices['services'][$libelle]; |
||
| 49 | } |
||
| 50 | foreach ($diffParametres as $libelle){ |
||
| 51 | $currentServices['parameters'][$libelle] = $newServices['parameters'][$libelle]; |
||
| 52 | } |
||
| 53 | foreach ($diffDeclarations as $libelle){ |
||
| 54 | $currentServices[$libelle] = $newServices[$libelle]; |
||
| 55 | } |
||
| 56 | $content = Yaml::dump($currentServices, 3, 4); |
||
| 57 | $flink = fopen($target, 'w'); |
||
| 58 | if ($flink) { |
||
| 59 | $write = fwrite($flink, $content); |
||
| 60 | if ($write) { |
||
| 61 | fclose($flink); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | return true; |
||
| 65 | } |
||
| 66 | // On ne modifie pas un fichier existant. |
||
| 67 | if(file_exists($target)){ |
||
| 68 | return false; |
||
| 69 | } |
||
| 70 | $this->renderFile($fichier.'.twig', $target, $parameters); |
||
| 71 | return true; |
||
| 72 | } |
||
| 73 | |||
| 87 |