| Conditions | 23 |
| Paths | 409 |
| Total Lines | 71 |
| Code Lines | 39 |
| 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 declare(strict_types = 1); |
||
| 55 | public function query(array $query, string $path=''): Result |
||
| 56 | { |
||
| 57 | $class = null; |
||
| 58 | |||
| 59 | if (isset($query['uri']) && $query['uri'] !== "") { |
||
| 60 | foreach ($this->config as $type => $config) { |
||
| 61 | // request URI matches uriSpace |
||
| 62 | if (strpos($query['uri'], $config['uriSpace']) === 0) { |
||
| 63 | $uri = $query['uri']; |
||
| 64 | $notation = substr($uri, strlen($config['uriSpace'])); |
||
| 65 | |||
| 66 | if (!preg_match($config['notationPattern'], $notation)) { |
||
| 67 | return new Result(); |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($config['notationNormalizer']) { |
||
| 71 | $notation = $config['notationNormalizer']($notation); |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!$notation && $notation !== '0') { |
||
| 75 | unset($notation); |
||
| 76 | } |
||
| 77 | |||
| 78 | $class = "JSKOS\\$type"; |
||
| 79 | |||
| 80 | break; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | if (!isset($uri)) { |
||
| 84 | return new Result(); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | if (isset($query['notation']) && $query['notation'] !== "") { |
||
| 89 | if (isset($notation)) { |
||
| 90 | if ($query['notation'] != $notation) { |
||
| 91 | // requested notation and uri do not match |
||
| 92 | return new Result(); |
||
| 93 | } |
||
| 94 | } else { |
||
| 95 | foreach ($this->config as $type => $config) { |
||
| 96 | if (preg_match($config['notationPattern'], $query['notation'])) { |
||
| 97 | $notation = $query['notation']; |
||
| 98 | if ($config['notationNormalizer']) { |
||
| 99 | $notation = $config['notationNormalizer']($notation); |
||
| 100 | } |
||
| 101 | |||
| 102 | $class = "JSKOS\\$type"; |
||
| 103 | |||
| 104 | if (!isset($uri)) { |
||
| 105 | $uri = $config['uriSpace'] . $notation; |
||
| 106 | } |
||
| 107 | break; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | if (!isset($notation)) { |
||
| 111 | return new Result(); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | if ($class && isset($uri)) { |
||
| 117 | if (isset($notation)) { |
||
| 118 | $content = new $class(['uri' => $uri, 'notation' => [$notation]]); |
||
| 119 | } else { |
||
| 120 | $content = new $class(['uri' => $uri]); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | return isset($content) ? new Result([$content]) : new Result(); |
||
| 125 | } |
||
| 126 | } |
||
| 127 |