| Conditions | 23 |
| Paths | 4097 |
| Total Lines | 65 |
| Code Lines | 33 |
| 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 |
||
| 30 | public function isValid($vol, $context = []) |
||
| 31 | { |
||
| 32 | if (!($vol instanceof Bbcvols)) { |
||
| 33 | throw new \InvalidArgumentException('Flight validator only accepts a flight'); |
||
| 34 | } |
||
| 35 | |||
| 36 | $this->valid = true; |
||
| 37 | |||
| 38 | if (!$this->isHourValid($vol->heureD)) { |
||
| 39 | $this->addError('heureD', "L'heure depart n'est pas correcte'"); |
||
| 40 | } |
||
| 41 | |||
| 42 | if (!$this->isHourValid($vol->heureA)) { |
||
| 43 | $this->addError('heureA', 'L\'heure d\'arrivee n\'est pas correcte'); |
||
| 44 | } |
||
| 45 | |||
| 46 | if (empty($this->errors) && ($vol->heureA - $vol->heureD) <= 0) { |
||
| 47 | $this->addError('heures', 'L\'heure de depart est plus grande que l\'heure d\'arrivee'); |
||
| 48 | } |
||
| 49 | |||
| 50 | if(empty($vol->lieuD)){ |
||
| 51 | $this->addError('lieuD', 'Le lieu de départ est vide'); |
||
| 52 | } |
||
| 53 | |||
| 54 | if(empty($vol->lieuA)){ |
||
| 55 | $this->addError('lieuA', 'Le lieu d\'arrivée est vide'); |
||
| 56 | } |
||
| 57 | |||
| 58 | // PAX |
||
| 59 | if (!is_numeric($vol->nbrPax) || (int)$vol->nbrPax < 0) { |
||
| 60 | $this->addError('nbrPax', 'Erreur le nombre de passager est un nombre négatif.'); |
||
| 61 | } |
||
| 62 | |||
| 63 | if ($vol->mustHavePax() && !$vol->hasPax()) { |
||
| 64 | $this->addError('nbrPax', 'Erreur ce type de vol doit etre fait avec des passagers.'); |
||
| 65 | } |
||
| 66 | |||
| 67 | // verification billing |
||
| 68 | if ($this->isGroupedFlight($context) && $vol->getFlightType()->isBillingRequired() && $vol->isFree()) { |
||
| 69 | $this->addError('cost', 'Erreur ce type de vol doit être payant.'); |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($vol->getFlightType()->isBillingRequired() && !$vol->hasReceiver()) { |
||
| 73 | $this->addError('cost', |
||
| 74 | 'Erreur ce type de vol doit être payant, mais personne n\'a été signalé comme recepteur d\'argent.'); |
||
| 75 | } |
||
| 76 | |||
| 77 | if($vol->getFlightType()->isBillingRequired() && ($vol->getAmountPerPassenger()) < $this->getMinPrice()){ |
||
| 78 | $this->addError('cost', |
||
| 79 | sprintf('Le montant demandé pour ce vol n\'est pas suffisant un minimum de %s euros est demandé', $this->getMinPrice())); |
||
| 80 | } |
||
| 81 | |||
| 82 | //Kilometers |
||
| 83 | if($vol->hasKilometers() && !$vol->getKilometers() > 0){ |
||
| 84 | $this->addError('kilometers', |
||
| 85 | 'Les kilometres doivent être un nombre positif'); |
||
| 86 | } |
||
| 87 | |||
| 88 | if($vol->hasKilometers() && !$vol->hasKilometersDescription()){ |
||
| 89 | $this->addError('justif_kilometers', |
||
| 90 | 'Vous essayez d\'encoder des kilometres sans justificatif.'); |
||
| 91 | } |
||
| 92 | |||
| 93 | return $this->valid; |
||
| 94 | } |
||
| 95 | |||
| 137 | } |