| Conditions | 16 |
| Paths | 8 |
| Total Lines | 67 |
| Code Lines | 56 |
| 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 |
||
| 106 | private function run(PropertyData $propertyData, array $args) |
||
| 107 | { |
||
| 108 | $prefix = substr($this->method, 0, 3); |
||
| 109 | $this->propertyData = $propertyData; |
||
| 110 | if ($prefix == 'get') { |
||
| 111 | $this->mode = true; |
||
| 112 | $propertyData->reflection->setAccessible(true); |
||
| 113 | $value = is_null($this->object) ? $propertyData->reflection->getValue() : $propertyData->reflection->getValue($this->object); |
||
| 114 | $this->checkType($this->propertyData->getTypeTree(), $value); |
||
| 115 | $propertyData->reflection->setAccessible(false); |
||
| 116 | $conditionsSuit = new ConditionsSuit(RunningSuit::OUTPUT_MODE, $this->propertyData, $this->class, $this->method, $this->object); |
||
| 117 | if ($conditionsSuit->processConditions($value)) { |
||
| 118 | $handlersSuit = new HandlersSuit(RunningSuit::OUTPUT_MODE, $this->propertyData, $this->class, $this->object); |
||
| 119 | $value = $handlersSuit->executeHandlers($value); |
||
| 120 | return $value; |
||
| 121 | } else { |
||
| 122 | throw new AxessorsError("conditions for {$this->backtrace['class']}::{$this->method}() did not pass"); |
||
| 123 | } |
||
| 124 | } elseif ($prefix == 'set') { |
||
| 125 | $this->mode = false; |
||
| 126 | $this->checkType($this->propertyData->getTypeTree(), $args[0]); |
||
| 127 | $conditionsSuit = new ConditionsSuit(RunningSuit::INPUT_MODE, $this->propertyData, $this->class, $this->method, $this->object); |
||
| 128 | if ($conditionsSuit->processConditions($args[0])) { |
||
| 129 | $propertyData->reflection->setAccessible(true); |
||
| 130 | $handlersSuit = new HandlersSuit(RunningSuit::INPUT_MODE, $this->propertyData, $this->class, $this->object); |
||
| 131 | $value = $handlersSuit->executeHandlers($args[0]); |
||
| 132 | is_null($this->object) ? $propertyData->reflection->setValue($value) : $propertyData->reflection->setValue($this->object, |
||
| 133 | $value); |
||
| 134 | $propertyData->reflection->setAccessible(false); |
||
| 135 | return; |
||
| 136 | } else { |
||
| 137 | throw new AxessorsError("conditions for {$this->backtrace['class']}::{$this->method}() did not pass"); |
||
| 138 | } |
||
| 139 | } else { |
||
| 140 | $this->method = str_replace(ucfirst($this->propertyData->getName()), 'PROPERTY', $this->method); |
||
| 141 | foreach ($this->propertyData->getTypeTree() as $type => $subType) { |
||
| 142 | $type = is_int($type) ? $subType : $type; |
||
| 143 | $reflection = new \ReflectionClass($type); |
||
| 144 | foreach ($reflection->getMethods() as $method) { |
||
| 145 | if (preg_match('{^m_(in|out)_}', |
||
| 146 | $method->name) && $method->isStatic() && $method->isPublic() && !$method->isAbstract()) { |
||
| 147 | if ($method->name == "m_in_$this->method") { |
||
| 148 | $propertyData->reflection->setAccessible(true); |
||
| 149 | $value = $propertyData->reflection->getValue($this->object); |
||
| 150 | $this->checkType($this->propertyData->getTypeTree(), $value); |
||
| 151 | // add support for static properties |
||
| 152 | $propertyData->reflection->setValue( |
||
| 153 | $this->object, call_user_func( |
||
| 154 | [$type, "m_in_$this->method"], $propertyData->reflection->getValue( |
||
| 155 | $this->object |
||
| 156 | ), $args |
||
| 157 | ) |
||
| 158 | ); |
||
| 159 | $propertyData->reflection->setAccessible(false); |
||
| 160 | return; |
||
| 161 | } elseif ($method->name == "m_out_$this->method") { |
||
| 162 | $propertyData->reflection->setAccessible(true); |
||
| 163 | $value = $propertyData->reflection->getValue($this->object); |
||
| 164 | $this->checkType($this->propertyData->getTypeTree(), $value); |
||
| 165 | $result = call_user_func([$type, "m_out_$this->method"], $value, $args); |
||
| 166 | $propertyData->reflection->setAccessible(false); |
||
| 167 | return $result; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | } |
||
| 171 | } |
||
| 172 | throw new AxessorsError("method {$this->backtrace['class']}::{$this->method}() not found"); |
||
| 173 | } |
||
| 247 |