Conditions | 10 |
Paths | 96 |
Total Lines | 30 |
Code Lines | 17 |
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 |
||
44 | public function isValid($value, $context = []) |
||
45 | { |
||
46 | |||
47 | $this->valid = true; |
||
48 | |||
49 | if(empty($value->name)){ |
||
50 | $this->addError('name', 'Le nom est requis pour créer une commande'); |
||
51 | } |
||
52 | if(empty($value->civilityId)){ |
||
53 | $this->addError('civility', 'Le titre de civilite est un champ requis.'); |
||
54 | } |
||
55 | if(empty($value->email) && empty($value->phone)){ |
||
56 | $this->addError('email', 'Soit l\'e-mail soit le téléphone est requis'); |
||
57 | } |
||
58 | if(empty($value->nbrPax) || (int)$value->nbrPax <= 0){ |
||
59 | $this->addError('nbrPax', 'Le nombre de passagers doit être plus grand que 0.'); |
||
60 | } |
||
61 | if(empty($value->region)){ |
||
62 | $this->addError('region', 'Le lieu de décollage doit etre configuré'); |
||
63 | } |
||
64 | |||
65 | if((int)$value->nbrPax > 0){ |
||
66 | $costPerPax = $value->cost / (int)$value->nbrPax; |
||
67 | if($costPerPax < $this->getMinPrice()){ |
||
68 | $this->addError('cost', sprintf('Le prix demandé par passagé est trop peu élevé. Un minimum de %s est demandé', $this->getMinPrice())); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | return $this->valid; |
||
73 | } |
||
74 | |||
87 | } |