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 |
||
97 | public function validationDefault(Validator $validator) |
||
98 | { |
||
99 | $validator |
||
100 | ->requirePresence('login', 'create') |
||
101 | ->notEmpty('login', __d('community', 'Login could not be empty.')) |
||
102 | ->add('login', 'unique', [ |
||
103 | 'provider' => 'table', |
||
104 | 'rule' => 'validateUnique', |
||
105 | 'message' => __d('community', 'User with this login already exists.') |
||
106 | ]) |
||
107 | ->add('login', 'length', [ |
||
108 | 'rule' => ['minLength', MIN_LENGTH_LOGIN], |
||
109 | 'message' => __d('community', 'The minimum login length must be {0} characters', MIN_LENGTH_LOGIN) |
||
110 | ]); |
||
111 | |||
112 | $validator |
||
113 | ->requirePresence('slug', 'create') |
||
114 | ->notEmpty('slug', __d('community', 'Alias could not be empty.')) |
||
115 | ->add('slug', 'unique', [ |
||
116 | 'provider' => 'table', |
||
117 | 'rule' => 'validateUnique', |
||
118 | 'message' => __d('community', 'User with this alias already exists.') |
||
119 | ]) |
||
120 | ->add('slug', 'length', [ |
||
121 | 'rule' => ['minLength', MIN_LENGTH_LOGIN], |
||
122 | 'message' => __d('community', 'The minimum alias length must be {0} characters', MIN_LENGTH_LOGIN) |
||
123 | ]); |
||
124 | |||
125 | $validator |
||
126 | ->requirePresence('group_id', 'create') |
||
127 | ->notEmpty('group_id', __d('community', 'Please, choose user group.')) |
||
128 | ->notEmpty('name', __d('community', 'Please, enter you full name.')); |
||
129 | |||
130 | $validator |
||
131 | ->notEmpty('email', __d('community', 'Please, enter you email.')) |
||
132 | ->add('email', 'unique', [ |
||
133 | 'provider' => 'table', |
||
134 | 'rule' => 'validateUnique', |
||
135 | 'message' => __d('community', 'User with this email already exists.') |
||
136 | ]) |
||
137 | ->add('email', 'valid', [ |
||
138 | 'rule' => 'email', |
||
139 | 'message' => __d('community', 'Please enter valid email.') |
||
140 | ]); |
||
141 | |||
142 | $validator |
||
143 | ->notEmpty('password', __d('community', 'Please, enter you password.')) |
||
144 | ->add('password', 'minLength', [ |
||
145 | 'rule' => ['minLength', MIN_LENGTH_PASS], |
||
146 | 'message' => __d('community', 'The minimum password length is {0}', MIN_LENGTH_PASS) |
||
147 | ]); |
||
148 | |||
149 | $validator |
||
150 | ->notEmpty('password_confirm', __d('community', 'Please, confirm you password.')) |
||
151 | ->add('password_confirm', 'no-misspelling', [ |
||
152 | 'rule' => ['compareWith', 'password'], |
||
153 | 'message' => __d('community', 'Passwords are not equal') |
||
154 | ]); |
||
155 | |||
156 | return $validator; |
||
157 | } |
||
158 | } |
||
159 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.