| Conditions | 11 |
| Paths | 40 |
| Total Lines | 66 |
| Lines | 14 |
| Ratio | 21.21 % |
| 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 |
||
| 84 | public function getInstance($expression) |
||
| 85 | { |
||
| 86 | // might be a simple type of pointcut |
||
| 87 | $isNegated = false; |
||
| 88 | |||
| 89 | // there are advices which do not reference any pointcuts, spare them the parsing |
||
| 90 | if (empty($expression)) { |
||
| 91 | $type = 'blank'; |
||
| 92 | |||
| 93 | } else { |
||
| 94 | // first of all we have to get the type of the pointcut |
||
| 95 | // check for connector pointcuts first |
||
| 96 | $expression = trim($expression); |
||
| 97 | |||
| 98 | // if we are already in a wrapping connector pointcut then we will cut it off as those are not distinguished |
||
| 99 | // by type but rather by their connector |
||
| 100 | $expression = $this->trimConnectorTypes($expression); |
||
| 101 | |||
| 102 | // now lets have a look if we are wrapped in some outer brackets |
||
| 103 | $parserUtil = new Parser(); |
||
| 104 | if (strlen($expression) === $parserUtil->getBracketSpan($expression, '(')) { |
||
| 105 | $expression = substr($expression, 1, strlen($expression) - 2); |
||
| 106 | } |
||
| 107 | |||
| 108 | // now check if we do have any "and" connectors here |
||
| 109 | View Code Duplication | if (strpos($expression, AndPointcut::CONNECTOR) !== false) { |
|
| 110 | $class = '\AppserverIo\Doppelgaenger\Entities\Pointcuts\AndPointcut'; |
||
| 111 | $tmp = $this->findConnectorPointcut($expression, $class); |
||
| 112 | if ($tmp !== false) { |
||
| 113 | return $tmp; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | // or-connection comes second |
||
| 118 | View Code Duplication | if (strpos($expression, OrPointcut::CONNECTOR) !== false) { |
|
| 119 | $class = '\AppserverIo\Doppelgaenger\Entities\Pointcuts\OrPointcut'; |
||
| 120 | $tmp = $this->findConnectorPointcut($expression, $class); |
||
| 121 | if ($tmp !== false) { |
||
| 122 | return $tmp; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | // trim the expression from containing brackets first |
||
| 127 | while ($expression[0] === '(' && $expression[strlen($expression) - 1] === ')') { |
||
| 128 | $expression = substr($expression, 1, strlen($expression) - 2); |
||
| 129 | } |
||
| 130 | |||
| 131 | if (strpos($expression, '!') !== false) { |
||
| 132 | $isNegated = true; |
||
| 133 | $expression = str_replace('!', '', $expression); |
||
| 134 | } |
||
| 135 | $type = trim(strstr($expression, '(', true)); |
||
| 136 | } |
||
| 137 | |||
| 138 | // build up the class name and check if we know a class like that |
||
| 139 | $class = '\AppserverIo\Doppelgaenger\Entities\Pointcuts\\' . ucfirst($type) . 'Pointcut'; |
||
| 140 | |||
| 141 | // check if we got a valid class |
||
| 142 | if (!class_exists($class)) { |
||
| 143 | throw new \InvalidArgumentException(sprintf('Could not resolve the expression %s to any known pointcut type', $expression)); |
||
| 144 | } |
||
| 145 | |||
| 146 | $pointcut = new $class(substr(trim(str_replace($type, '', $expression), '( '), 0, -1), $isNegated); |
||
| 147 | |||
| 148 | return $pointcut; |
||
| 149 | } |
||
| 150 | |||
| 170 |