Conditions | 29 |
Paths | > 20000 |
Total Lines | 91 |
Code Lines | 47 |
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()){ |
||
64 | if (!$vol->hasPax()) { |
||
65 | $this->addError('nbrPax', 'Erreur ce type de vol doit etre fait avec des passagers.'); |
||
66 | } |
||
67 | |||
68 | if(empty(trim($vol->getPassengerNames()))){ |
||
69 | $this->addError('passenger_names', 'Le nom des passagers est obligatoire.'); |
||
70 | } |
||
71 | |||
72 | if(empty(trim($vol->getPassengerNames()))){ |
||
73 | $this->addError('passenger_names', 'Le nom des passagers est obligatoire.'); |
||
74 | } |
||
75 | |||
76 | $passengers = explode(';', $vol->getPassengerNames()); |
||
77 | if(count($passengers) !== $vol->getNumberOfPassengers()){ |
||
78 | $this->addError('passenger_names', 'Le nombre de noms des passagers doit être égale au nombre de passagers.'); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | if($vol->isInstruction()){ |
||
83 | if($vol->getPilotId() === $vol->getOrganisatorId()){ |
||
84 | $this->addError('organisator', 'l\'organisateur d\'un vol d\'instruction doit être l\'instructeur et non le pilote'); |
||
85 | } |
||
86 | |||
87 | if($this->isGroupedFlight($context)){ |
||
88 | $this->addError('alone', "Le vol d'instruction est un vol à un seul ballon."); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | // verification billing |
||
93 | if ($this->isGroupedFlight($context) && $vol->getFlightType()->isBillingRequired() && $vol->isFree()) { |
||
94 | $this->addError('cost', 'Erreur ce type de vol doit être payant.'); |
||
95 | } |
||
96 | |||
97 | if ($vol->getFlightType()->isBillingRequired() && !$vol->hasReceiver()) { |
||
98 | $this->addError('cost', |
||
99 | 'Erreur ce type de vol doit être payant, mais personne n\'a été signalé comme recepteur d\'argent.'); |
||
100 | } |
||
101 | |||
102 | if ($vol->getFlightType()->isBillingRequired() && ($vol->getAmountPerPassenger()) < $this->getMinPrice()) { |
||
103 | $this->addError('cost', |
||
104 | sprintf('Le montant demandé pour ce vol n\'est pas suffisant un minimum de %s euros est demandé', |
||
105 | $this->getMinPrice())); |
||
106 | } |
||
107 | |||
108 | //Kilometers |
||
109 | if ($vol->hasKilometers() && !$vol->getKilometers() > 0) { |
||
110 | $this->addError('kilometers', |
||
111 | 'Les kilometres doivent être un nombre positif'); |
||
112 | } |
||
113 | |||
114 | if ($vol->hasKilometers() && !$vol->hasKilometersDescription()) { |
||
115 | $this->addError('justif_kilometers', |
||
116 | 'Vous essayez d\'encoder des kilometres sans justificatif.'); |
||
117 | } |
||
118 | |||
119 | return $this->valid; |
||
120 | } |
||
121 | |||
164 | } |