| Conditions | 12 |
| Paths | 8 |
| Total Lines | 43 |
| Code Lines | 24 |
| Lines | 20 |
| Ratio | 46.51 % |
| Changes | 2 | ||
| 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 |
||
| 94 | public function __call($name, $arguments) |
||
| 95 | { |
||
| 96 | View Code Duplication | if (preg_match('/^set(\w+)/', $name, $matches) |
|
| 97 | && in_array($property = lcfirst($matches[1]), array_keys($this->getRivetsConfig())) |
||
| 98 | ) { |
||
| 99 | array_unshift($arguments, $property); |
||
| 100 | return call_user_func_array([$this, 'attach'], $arguments); |
||
| 101 | } |
||
| 102 | |||
| 103 | View Code Duplication | if (preg_match('/^add(\w+)/', $name, $matches) |
|
| 104 | && in_array($collection = str_plural(lcfirst($matches[1])), array_keys($this->getRivetsConfig())) |
||
| 105 | ) { |
||
| 106 | array_unshift($arguments, $collection); |
||
| 107 | return call_user_func_array([$this, 'attach'], $arguments); |
||
| 108 | } |
||
| 109 | |||
| 110 | View Code Duplication | if (preg_match('/^unset(\w+)/', $name, $matches) |
|
| 111 | && in_array($property = lcfirst($matches[1]), array_keys($this->getRivetsConfig())) |
||
| 112 | ) { |
||
| 113 | array_unshift($arguments, $property); |
||
| 114 | return call_user_func_array([$this, 'removeRivet'], $arguments); |
||
| 115 | } |
||
| 116 | |||
| 117 | View Code Duplication | if (preg_match('/^remove(\w+)/', $name, $matches) |
|
| 118 | && in_array($collection = str_plural(lcfirst($matches[1])), array_keys($this->getRivetsConfig())) |
||
| 119 | ) { |
||
| 120 | array_unshift($arguments, $collection); |
||
| 121 | return call_user_func_array([$this, 'removeRivet'], $arguments); |
||
| 122 | } |
||
| 123 | |||
| 124 | if ( ! in_array($name, array_keys($this->getRivetsConfig()))) { |
||
| 125 | return parent::__call($name, $arguments); |
||
| 126 | } |
||
| 127 | |||
| 128 | list($type, $class) = $this->getRivetConfig($name); |
||
| 129 | |||
| 130 | if ($type == 'property') { |
||
| 131 | return $this->getRivetProperty($class, $name); |
||
| 132 | } |
||
| 133 | if ($type == 'collection') { |
||
| 134 | return $this->getRivetCollection($class, $name); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 186 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.