| Conditions | 10 |
| Paths | 98 |
| Total Lines | 35 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 1 |
| CRAP Score | 10 |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 33 | public function __construct(array $data = [], ?string $name = null, ?string $exp = null, ?array $options = []) |
||
| 34 | 36 | { |
|
| 35 | if (isset($data['value'])) { |
||
| 36 | $data['name'] = $data['value']; |
||
| 37 | unset($data['value']); |
||
| 38 | } |
||
| 39 | |||
| 40 | foreach ($data as $key => $value) { |
||
| 41 | if (!property_exists(self::class, $key)) { |
||
| 42 | throw new InvalidArgumentException(sprintf('Unknown property "%s" on annotation "%s".', $key, self::class)); |
||
| 43 | } |
||
| 44 | |||
| 45 | $this->{$key} = $value; |
||
| 46 | } |
||
| 47 | |||
| 48 | if (null !== $name) { |
||
| 49 | $this->name = $name; |
||
| 50 | } |
||
| 51 | |||
| 52 | if (null !== $exp) { |
||
| 53 | $this->exp = $exp; |
||
| 54 | } |
||
| 55 | |||
| 56 | if (0 !== count($options)) { |
||
| 57 | $this->options = $options; |
||
| 58 | } |
||
| 59 | |||
| 60 | foreach ($options as $option) { |
||
| 61 | if (is_array($option) && class_exists($option[0])) { |
||
| 62 | $this->options[] = new $option[0]([], ...$option[1]); |
||
| 63 | |||
| 64 | continue; |
||
| 65 | } |
||
| 66 | |||
| 67 | $this->options[] = $option; |
||
| 68 | } |
||
| 71 |