Conditions | 1 |
Paths | 1 |
Total Lines | 54 |
Code Lines | 39 |
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 |
||
51 | public function validationCreate(Validator $validator) |
||
52 | { |
||
53 | $validator |
||
54 | ->provider('upload', 'App\Model\Validation\UploadValidator') |
||
55 | ->notEmpty('name', __("You must select a name.")) |
||
56 | ->add('name', 'minLength', [ |
||
57 | 'rule' => ['minLength', 5], |
||
58 | 'message' => __("Please, {0} characters minimum for the name.", 5) |
||
59 | ]) |
||
60 | ->allowEmpty('picture_file') |
||
61 | ->add('picture_file', [ |
||
62 | 'mimeType' => [ |
||
63 | 'rule' => ['mimeType', ['image/jpeg', 'image/png']], |
||
64 | 'message' => __("The mimeType is not allowed."), |
||
65 | 'on' => function ($context) { |
||
66 | return !empty($context['data']['picture_file']['name']); |
||
67 | } |
||
68 | ], |
||
69 | 'fileExtension' => [ |
||
70 | 'rule' => ['extension', ['jpg', 'jpeg', 'png']], |
||
71 | 'message' => __("The extension allowed are {0}.", '.jpg, .jpeg and .png'), |
||
72 | 'on' => function ($context) { |
||
73 | return !empty($context['data']['picture_file']['name']); |
||
74 | } |
||
75 | ], |
||
76 | 'fileSize' => [ |
||
77 | 'rule' => ['fileSize', '<', '500KB'], |
||
78 | 'message' => __("The file exceeded the max allowed size of {0}", '500KB'), |
||
79 | 'on' => function ($context) { |
||
80 | return !empty($context['data']['picture_file']['name']); |
||
81 | } |
||
82 | ], |
||
83 | 'maxDimension' => [ |
||
84 | 'rule' => ['maxDimension', 130, 130], |
||
85 | 'provider' => 'upload', |
||
86 | 'message' => __( |
||
87 | "The file exceeded the max allowed dimension. Max height : {0} Max width : {1}", |
||
88 | 130, |
||
89 | 130 |
||
90 | ), |
||
91 | ] |
||
92 | ]) |
||
93 | ->notEmpty('type', __("You must select a type.")) |
||
94 | ->add('type', 'inList', [ |
||
95 | 'rule' => ['inList', ['comments', 'registration']], |
||
96 | 'message' => __("This type is not allowed. Allowed types : {0}", implode(", ", ['comments', 'registration'])), |
||
97 | ]) |
||
98 | ->notEmpty('rule', __("You must select a rule.")) |
||
99 | ->add('rule', 'numeric', [ |
||
100 | 'rule' => 'numeric' |
||
101 | ]); |
||
102 | |||
103 | return $validator; |
||
104 | } |
||
105 | } |
||
106 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.