| Conditions | 13 | 
| Paths | 7 | 
| Total Lines | 28 | 
| Code Lines | 14 | 
| 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  | 
            ||
| 50 | public function validateAttribute($model, $attribute)  | 
            ||
| 51 |     { | 
            ||
| 52 |         $value = $model->{$attribute}; | 
            ||
| 53 | |||
| 54 |         if ($this->length && strlen($value) <= $this->length) { | 
            ||
| 55 |             return $model->addError($attribute, 'The string must have at least {$this->length} chars.'); | 
            ||
| 56 | }  | 
            ||
| 57 | |||
| 58 |         if ($this->specials && !preg_match('/\W/', $value)) { | 
            ||
| 59 | return $model->addError($attribute, 'The string must contain any special char.');  | 
            ||
| 60 | }  | 
            ||
| 61 | |||
| 62 |         if ($this->numbers && !preg_match('/\d/', $value)) { | 
            ||
| 63 | return $model->addError($attribute, 'The string must contain at least one digit');  | 
            ||
| 64 | }  | 
            ||
| 65 | |||
| 66 |         if ($this->letters && !preg_match('/\p{L}/', $value)) { | 
            ||
| 67 | return $model->addError($attribute, 'The string must at least have one letter sign.');  | 
            ||
| 68 | }  | 
            ||
| 69 | |||
| 70 |         if ($this->uppercase && !preg_match('/[A-Z]/', $value)) { | 
            ||
| 71 | return $model->addError($attribute, 'The string must at least have one upper case letter.');  | 
            ||
| 72 | }  | 
            ||
| 73 | |||
| 74 |         if ($this->lowercase && !preg_match('/[a-z]/', $value)) { | 
            ||
| 75 | return $model->addError($attribute, 'The string must at least have one lower case letter.');  | 
            ||
| 76 | }  | 
            ||
| 77 | }  | 
            ||
| 78 | }  |