| Conditions | 10 |
| Paths | 41 |
| Total Lines | 45 |
| Code Lines | 24 |
| 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 |
||
| 62 | public function raise() |
||
| 63 | { |
||
| 64 | // 捕捉可能な例外の場合のみDelegateExceptionでラップする |
||
| 65 | // そうでない場合はそのままスロー |
||
| 66 | if ($this->exceptionObject instanceof SystemException) { |
||
| 67 | throw $this->exceptionObject; |
||
| 68 | } else { |
||
| 69 | $originException = $this->exceptionObject; |
||
| 70 | $delegateException = null; |
||
| 71 | |||
| 72 | if ($originException instanceof DelegateException) { |
||
| 73 | // 複数レイヤ間で例外がやりとりされる場合、すでにDelegateExceptionでラップ済みなので戻す |
||
| 74 | $originException = $delegateException->getOriginException(); |
||
| 75 | } |
||
| 76 | |||
| 77 | $invokeMethods = []; |
||
| 78 | foreach ($this->exceptionHandler as $exceptionHandlerAnnotation) { |
||
| 79 | $exceptions = $exceptionHandlerAnnotation->exceptions; |
||
| 80 | $refMethod = $exceptionHandlerAnnotation->method; |
||
| 81 | foreach ($exceptions as $exception) { |
||
| 82 | if (is_a($originException, $exception)) { |
||
| 83 | // 一つのメソッドに複数の捕捉例外が指定された場合(派生例外クラス含む)、先勝で1回のみ実行する |
||
| 84 | // そうでなければ複数回メソッドが実行されるため |
||
| 85 | // ただし同一クラス内に限る(親クラスの同一名のメソッドは実行する) |
||
| 86 | // TODO ここはテストを追加する |
||
| 87 | $classpath = $refMethod->class . "#" . $refMethod->name; |
||
| 88 | if (!array_key_exists($classpath, $invokeMethods)) { |
||
| 89 | $invokeMethods[$classpath] = $refMethod; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | if (count($invokeMethods) > 0) { |
||
| 96 | $delegateException = new DelegateException($this->exceptionObject); |
||
| 97 | $delegateException->enableHandled(); |
||
| 98 | } |
||
| 99 | |||
| 100 | foreach ($invokeMethods as $classpath => $invokeMethod) { |
||
| 101 | $params = ["class" => get_class($this->instance), "method" => $this->method, "exception" => $originException]; |
||
| 102 | $invokeMethod->invokeArgs($this->instance, [$params]); |
||
| 103 | $this->logger->debug("Execution of handling is success: " . $classpath); |
||
| 104 | } |
||
| 105 | |||
| 106 | throw $delegateException ?: $originException; |
||
| 107 | } |
||
| 110 |