Conditions | 13 |
Paths | 6 |
Total Lines | 41 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 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 |
||
45 | public function addPlageHoraire(PlageHoraire $plage_horaire) |
||
46 | { |
||
47 | // Règles d'ajout |
||
48 | if ($plage_horaire instanceof PlageHoraire\GardePlageHoraire) { |
||
49 | // Contrôles des gardes existantes (une dispo ne peut pas être ajoutée sur une garde) |
||
50 | foreach ($plage_horaire->getPompier()->getGardes() as $garde) { |
||
51 | if ($garde->includes($plage_horaire, false)) { |
||
52 | throw new InvalidDateException('Une garde existe aux dates de la garde à ajouter'); |
||
53 | } |
||
54 | } |
||
55 | // Contrôles des dispo existantes (si une garde est posé sur une dispo, on la transforme) |
||
56 | foreach ($plage_horaire->getPompier()->getDispos() as $dispo) { |
||
57 | if ($dispo->includes($plage_horaire, false)) { |
||
58 | $plage_horaire->getPompier()->getPlagesHoraires()->removeElement($dispo); |
||
59 | if ($dispo->getStart() < $plage_horaire->getStart()) { |
||
60 | new PlageHoraire\DispoPlageHoraire($this, $plage_horaire->getPompier(), $dispo->getStart(), $plage_horaire->getStart()); |
||
61 | } |
||
62 | if ($dispo->getEnd() > $plage_horaire->getEnd()) { |
||
63 | new PlageHoraire\DispoPlageHoraire($this, $plage_horaire->getPompier(), $plage_horaire->getEnd(), $dispo->getEnd()); |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | } elseif ($plage_horaire instanceof PlageHoraire\DispoPlageHoraire) { |
||
68 | // Contrôles des gardes existantes (une dispo ne peut pas être ajoutée sur une garde) |
||
69 | foreach ($plage_horaire->getPompier()->getGardes() as $garde) { |
||
70 | if ($garde->includes($plage_horaire, false)) { |
||
71 | throw new InvalidDateException('Une garde existe aux dates de la dispo'); |
||
72 | } |
||
73 | } |
||
74 | // Contrôles des dispo existantes (une dispo ne peut pas être ajoutée sur une autre dispo) |
||
75 | foreach ($plage_horaire->getPompier()->getDispos() as $dispo) { |
||
76 | if ($dispo->includes($plage_horaire, false)) { |
||
77 | throw new InvalidDateException('Une disponibilité existe aux dates de la dispo'); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | |||
82 | $this->plages_horaires->add($plage_horaire); |
||
83 | |||
84 | return $this; |
||
85 | } |
||
86 | |||
157 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..