| Conditions | 14 |
| Paths | 210 |
| Total Lines | 37 |
| Code Lines | 27 |
| 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 | $listeDesParametres = !empty($currentServices['parameters'])?array_keys($currentServices['parameters']):[]; |
||
| 34 | $listeDesServices = !empty($currentServices['services'])?array_keys($currentServices['services']):[]; |
||
| 35 | $listeDesNouveauxParametres = !empty($newServices['parameters'])?array_keys($newServices['parameters']):[]; |
||
| 36 | $listeDesNouveauxServices = !empty($newServices['services'])?array_keys($newServices['services']):[]; |
||
| 37 | $diffServices = array_diff($listeDesNouveauxServices, $listeDesServices); |
||
| 38 | $diffParametres = array_diff($listeDesNouveauxParametres, $listeDesParametres); |
||
| 39 | if(empty($diffServices) && empty($diffParametres) ){ |
||
| 40 | return false; |
||
| 41 | } |
||
| 42 | foreach ($diffServices as $libelle){ |
||
| 43 | $currentServices['services'][$libelle] = $newServices['services'][$libelle]; |
||
| 44 | } |
||
| 45 | foreach ($diffParametres as $libelle){ |
||
| 46 | $currentServices['parameters'][$libelle] = $newServices['parameters'][$libelle]; |
||
| 47 | } |
||
| 48 | $content = Yaml::dump($currentServices, 3, 4); |
||
| 49 | $flink = fopen($target, 'w'); |
||
| 50 | if ($flink) { |
||
| 51 | $write = fwrite($flink, $content); |
||
| 52 | if ($write) { |
||
| 53 | fclose($flink); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | return true; |
||
| 57 | } |
||
| 58 | // On ne modifie pas un fichier existant. |
||
| 59 | if(file_exists($target)){ |
||
| 60 | return false; |
||
| 61 | } |
||
| 62 | $this->renderFile($fichier.'.twig', $target, $parameters); |
||
| 63 | return true; |
||
| 64 | } |
||
| 65 | |||
| 79 |