Conditions | 1 |
Paths | 1 |
Total Lines | 61 |
Code Lines | 45 |
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 |
||
100 | public function validationDefault(Validator $validator) |
||
101 | { |
||
102 | $validator |
||
103 | ->requirePresence('login', 'create') |
||
104 | ->notEmpty('login', __d('community', 'Login could not be empty.')) |
||
105 | ->add('login', 'unique', [ |
||
106 | 'provider' => 'table', |
||
107 | 'rule' => 'validateUnique', |
||
108 | 'message' => __d('community', 'User with this login already exists.') |
||
109 | ]) |
||
110 | ->add('login', 'length', [ |
||
111 | 'rule' => ['minLength', MIN_LENGTH_LOGIN], |
||
112 | 'message' => __d('community', 'The minimum login length must be {0} characters', MIN_LENGTH_LOGIN) |
||
113 | ]); |
||
114 | |||
115 | $validator |
||
116 | ->requirePresence('slug', 'create') |
||
117 | ->notEmpty('slug', __d('community', 'Alias could not be empty.')) |
||
118 | ->add('slug', 'unique', [ |
||
119 | 'provider' => 'table', |
||
120 | 'rule' => 'validateUnique', |
||
121 | 'message' => __d('community', 'User with this alias already exists.') |
||
122 | ]) |
||
123 | ->add('slug', 'length', [ |
||
124 | 'rule' => ['minLength', MIN_LENGTH_LOGIN], |
||
125 | 'message' => __d('community', 'The minimum alias length must be {0} characters', MIN_LENGTH_LOGIN) |
||
126 | ]); |
||
127 | |||
128 | $validator |
||
129 | ->requirePresence('group_id', 'create') |
||
130 | ->notEmpty('group_id', __d('community', 'Please, choose user group.')) |
||
131 | ->notEmpty('name', __d('community', 'Please, enter you full name.')); |
||
132 | |||
133 | $validator |
||
134 | ->notEmpty('email', __d('community', 'Please, enter you email.')) |
||
135 | ->add('email', 'unique', [ |
||
136 | 'provider' => 'table', |
||
137 | 'rule' => 'validateUnique', |
||
138 | 'message' => __d('community', 'User with this email already exists.') |
||
139 | ]) |
||
140 | ->add('email', 'valid', [ |
||
141 | 'rule' => 'email', |
||
142 | 'message' => __d('community', 'Please enter valid email.') |
||
143 | ]); |
||
144 | |||
145 | $validator |
||
146 | ->notEmpty('password', __d('community', 'Please, enter you password.')) |
||
147 | ->add('password', 'minLength', [ |
||
148 | 'rule' => ['minLength', MIN_LENGTH_PASS], |
||
149 | 'message' => __d('community', 'The minimum password length is {0}', MIN_LENGTH_PASS) |
||
150 | ]); |
||
151 | |||
152 | $validator |
||
153 | ->notEmpty('password_confirm', __d('community', 'Please, confirm you password.')) |
||
154 | ->add('password_confirm', 'no-misspelling', [ |
||
155 | 'rule' => ['compareWith', 'password'], |
||
156 | 'message' => __d('community', 'Passwords are not equal') |
||
157 | ]); |
||
158 | |||
159 | return $validator; |
||
160 | } |
||
161 | |||
175 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.