| Conditions | 15 |
| Paths | 129 |
| Total Lines | 41 |
| Code Lines | 20 |
| 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 |
||
| 17 | public function isValid($vol, $context = []) |
||
| 18 | { |
||
| 19 | if (!($vol instanceof Bbcvols)) { |
||
| 20 | throw new \InvalidArgumentException('Flight validator only accepts a flight'); |
||
| 21 | } |
||
| 22 | |||
| 23 | $this->valid = true; |
||
| 24 | |||
| 25 | if (!$this->isHourValid($vol->heureD)) { |
||
| 26 | $this->addError('heureD', "L'heure depart n'est pas correcte'"); |
||
| 27 | } |
||
| 28 | |||
| 29 | if (!$this->isHourValid($vol->heureA)) { |
||
| 30 | $this->addError('heureA', 'L\'heure d\'arrivee n\'est pas correcte'); |
||
| 31 | } |
||
| 32 | |||
| 33 | if (empty($this->errors) && ($vol->heureA - $vol->heureD) <= 0) { |
||
| 34 | $this->addError('heures', 'L\'heure de depart est plus grande que l\'heure d\'arrivee'); |
||
| 35 | } |
||
| 36 | |||
| 37 | // PAX |
||
| 38 | if (!is_integer($vol->nbrPax) || $vol->nbrPax < 0) { |
||
| 39 | $this->addError('nbrPax', 'Erreur le nombre de passager est un nombre négatif.'); |
||
| 40 | } |
||
| 41 | |||
| 42 | if ($vol->mustHavePax() && !$vol->hasPax()) { |
||
| 43 | $this->addError('nbrPax', 'Erreur ce type de vol doit etre fait avec des passagers.'); |
||
| 44 | } |
||
| 45 | |||
| 46 | // verification billing |
||
| 47 | if ($this->isGroupedFlight($context) && $vol->getFlightType()->isBillingRequired() && $vol->isFree()) { |
||
| 48 | $this->addError('cost', 'Erreur ce type de vol doit être payant.'); |
||
| 49 | } |
||
| 50 | |||
| 51 | if ($vol->getFlightType()->isBillingRequired() && !$vol->hasReceiver()) { |
||
| 52 | $this->addError('cost', |
||
| 53 | 'Erreur ce type de vol doit être payant, mais personne n\'a été signalé comme recepteur d\'argent.'); |
||
| 54 | } |
||
| 55 | |||
| 56 | return $this->valid; |
||
| 57 | } |
||
| 58 | |||
| 79 | } |