| Conditions | 16 |
| Paths | 13 |
| Total Lines | 48 |
| Code Lines | 34 |
| 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 |
||
| 105 | public function resolveByStringRepresentation(string $urn): array |
||
| 106 | { |
||
| 107 | // linking to any t3:// syntax |
||
| 108 | if (stripos($urn, 't3://') === 0) { |
||
| 109 | // lets parse the urn |
||
| 110 | $urnParsed = parse_url($urn); |
||
| 111 | $type = $urnParsed['host']; |
||
| 112 | if (isset($urnParsed['query'])) { |
||
| 113 | parse_str(htmlspecialchars_decode($urnParsed['query']), $data); |
||
| 114 | } else { |
||
| 115 | $data = []; |
||
| 116 | } |
||
| 117 | $fragment = $urnParsed['fragment'] ?? null; |
||
| 118 | |||
| 119 | if (is_object($this->handlers[$type])) { |
||
| 120 | $result = $this->handlers[$type]->resolveHandlerData($data); |
||
| 121 | $result['type'] = $type; |
||
| 122 | } else { |
||
| 123 | throw new UnknownLinkHandlerException('LinkHandler for ' . $type . ' was not registered', 1460581769); |
||
| 124 | } |
||
| 125 | // this was historically named "section" |
||
| 126 | if ($fragment) { |
||
| 127 | $result['fragment'] = $fragment; |
||
| 128 | } |
||
| 129 | } elseif ((strpos($urn, '://') || StringUtility::beginsWith($urn, '//')) && $this->handlers[self::TYPE_URL]) { |
||
| 130 | $result = $this->handlers[self::TYPE_URL]->resolveHandlerData(['url' => $urn]); |
||
| 131 | $result['type'] = self::TYPE_URL; |
||
| 132 | } elseif (stripos($urn, 'mailto:') === 0 && $this->handlers[self::TYPE_EMAIL]) { |
||
| 133 | $result = $this->handlers[self::TYPE_EMAIL]->resolveHandlerData(['email' => $urn]); |
||
| 134 | $result['type'] = self::TYPE_EMAIL; |
||
| 135 | } elseif (stripos($urn, 'tel:') === 0 && $this->handlers[self::TYPE_TELEPHONE]) { |
||
| 136 | $result = $this->handlers[self::TYPE_TELEPHONE]->resolveHandlerData(['telephone' => $urn]); |
||
| 137 | $result['type'] = self::TYPE_TELEPHONE; |
||
| 138 | } else { |
||
| 139 | $result = []; |
||
| 140 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Link']['resolveByStringRepresentation'] ?? null)) { |
||
| 141 | $params = ['urn' => $urn, 'result' => &$result]; |
||
| 142 | foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Link']['resolveByStringRepresentation'] as $hookMethod) { |
||
| 143 | $fakeThis = null; |
||
| 144 | GeneralUtility::callUserFunction($hookMethod, $params, $fakeThis); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | if (empty($result) || empty($result['type'])) { |
||
| 148 | throw new UnknownUrnException('No valid URN to resolve found', 1457177667); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | return $result; |
||
| 153 | } |
||
| 182 |