| Conditions | 10 |
| Paths | 72 |
| Total Lines | 30 |
| Code Lines | 19 |
| 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 |
||
| 30 | public function __construct(array $attributes = []) |
||
| 31 | { |
||
| 32 | $count = 0; |
||
| 33 | if (isset($attributes['nameFromType'])) { |
||
| 34 | $this->nameFromType = $attributes['nameFromType']; |
||
| 35 | if ($this->nameFromType) { |
||
| 36 | $count++; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | if (isset($attributes['nameFromMethodName'])) { |
||
| 40 | $this->nameFromMethodName = $attributes['nameFromMethodName']; |
||
| 41 | if ($this->nameFromMethodName) { |
||
| 42 | $count++; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | if (isset($attributes['name'])) { |
||
| 46 | $this->name = $attributes['name']; |
||
| 47 | $count++; |
||
| 48 | } |
||
| 49 | |||
| 50 | if ($count === 0) { |
||
| 51 | $this->nameFromType = true; |
||
| 52 | } |
||
| 53 | if ($count > 1) { |
||
| 54 | throw new AnnotationException('There should be only one property in the list "name", "nameFromType", ' |
||
| 55 | .'"nameFromMethodName". You can add aliases if you need several names.'); |
||
| 56 | } |
||
| 57 | |||
| 58 | if (isset($attributes['tags']) && \is_array($attributes['tags'])) { |
||
| 59 | $this->setTags(...$attributes['tags']); |
||
| 60 | } |
||
| 94 |