| Conditions | 25 |
| Paths | 39 |
| Total Lines | 97 |
| Code Lines | 66 |
| 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 |
||
| 57 | public function resolve(string $linkParameter): array |
||
| 58 | { |
||
| 59 | $a = []; |
||
| 60 | if (stripos(rawurldecode(trim($linkParameter)), 'phar://') === 0) { |
||
| 61 | throw new \RuntimeException( |
||
| 62 | 'phar scheme not allowed as soft reference target', |
||
| 63 | 1530030673 |
||
| 64 | ); |
||
| 65 | } |
||
| 66 | |||
| 67 | $result = []; |
||
| 68 | // Parse URL scheme |
||
| 69 | $scheme = parse_url($linkParameter, PHP_URL_SCHEME); |
||
| 70 | |||
| 71 | // Resolve FAL-api "file:UID-of-sys_file-record" and "file:combined-identifier" |
||
| 72 | if (stripos($linkParameter, 'file:') === 0) { |
||
| 73 | $result = $this->getFileOrFolderObjectFromMixedIdentifier(substr($linkParameter, 5)); |
||
| 74 | } elseif (GeneralUtility::validEmail(parse_url($linkParameter, PHP_URL_PATH))) { |
||
| 75 | $result['type'] = LinkService::TYPE_EMAIL; |
||
| 76 | $result['email'] = $linkParameter; |
||
| 77 | } elseif (strpos($linkParameter, 'tel:') === 0) { |
||
| 78 | $result['type'] = LinkService::TYPE_TELEPHONE; |
||
| 79 | $result['telephone'] = $linkParameter; |
||
| 80 | } elseif (strpos($linkParameter, ':') !== false) { |
||
| 81 | // Check for link-handler keyword |
||
| 82 | [$linkHandlerKeyword, $linkHandlerValue] = explode(':', $linkParameter, 2); |
||
| 83 | $result['type'] = strtolower(trim($linkHandlerKeyword)); |
||
| 84 | $result['url'] = $linkParameter; |
||
| 85 | $result['value'] = $linkHandlerValue; |
||
| 86 | if ($result['type'] === LinkService::TYPE_RECORD) { |
||
| 87 | [$a['identifier'], $tableAndUid] = explode(':', $linkHandlerValue, 2); |
||
| 88 | $tableAndUid = explode(':', $tableAndUid); |
||
| 89 | if (count($tableAndUid) > 1) { |
||
| 90 | $a['table'] = $tableAndUid[0]; |
||
| 91 | $a['uid'] = $tableAndUid[1]; |
||
| 92 | } else { |
||
| 93 | // this case can happen if there is the very old linkhandler syntax, which was only record:<table>:<uid> |
||
| 94 | $a['table'] = $a['identifier']; |
||
| 95 | $a['uid'] = $tableAndUid[0]; |
||
| 96 | } |
||
| 97 | $result = array_merge($result, $a); |
||
| 98 | } |
||
| 99 | } else { |
||
| 100 | // special handling without a scheme |
||
| 101 | $isLocalFile = 0; |
||
| 102 | $fileChar = (int)strpos($linkParameter, '/'); |
||
| 103 | $urlChar = (int)strpos($linkParameter, '.'); |
||
| 104 | |||
| 105 | $isIdOrAlias = MathUtility::canBeInterpretedAsInteger($linkParameter); |
||
| 106 | $matches = []; |
||
| 107 | // capture old RTE links relative to TYPO3_mainDir |
||
| 108 | if (preg_match('#../(?:index\\.php)?\\?id=([^&]+)#', $linkParameter, $matches)) { |
||
| 109 | $linkParameter = $matches[1]; |
||
| 110 | $isIdOrAlias = true; |
||
| 111 | } |
||
| 112 | $containsSlash = false; |
||
| 113 | if (!$isIdOrAlias) { |
||
| 114 | // Detects if a file is found in site-root and if so it will be treated like a normal file. |
||
| 115 | [$rootFileDat] = explode('?', rawurldecode($linkParameter)); |
||
| 116 | $containsSlash = strpos($rootFileDat, '/') !== false; |
||
| 117 | $pathInfo = pathinfo($rootFileDat); |
||
| 118 | $fileExtension = strtolower($pathInfo['extension'] ?? ''); |
||
| 119 | if (!$containsSlash |
||
| 120 | && trim($rootFileDat) |
||
| 121 | && ( |
||
| 122 | @is_file(Environment::getPublicPath() . '/' . $rootFileDat) |
||
| 123 | || $fileExtension === 'php' |
||
| 124 | || $fileExtension === 'html' |
||
| 125 | || $fileExtension === 'htm' |
||
| 126 | ) |
||
| 127 | ) { |
||
| 128 | $isLocalFile = 1; |
||
| 129 | } elseif ($containsSlash) { |
||
| 130 | // Adding this so realurl directories are linked right (non-existing). |
||
| 131 | $isLocalFile = 2; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | // url (external): If doubleSlash or if a '.' comes before a '/'. |
||
| 136 | if (!$isIdOrAlias && $isLocalFile !== 1 && $urlChar && (!$containsSlash || $urlChar < $fileChar)) { |
||
| 137 | $result['type'] = LinkService::TYPE_URL; |
||
| 138 | if (!$scheme) { |
||
| 139 | $result['url'] = 'http://' . $linkParameter; |
||
| 140 | } else { |
||
| 141 | $result['url'] = $linkParameter; |
||
| 142 | } |
||
| 143 | // file (internal) or folder |
||
| 144 | } elseif ($containsSlash || $isLocalFile) { |
||
| 145 | $result = $this->getFileOrFolderObjectFromMixedIdentifier($linkParameter); |
||
| 146 | } else { |
||
| 147 | // Integer or alias (alias is without slashes or periods or commas, that is |
||
| 148 | // 'nospace,alphanum_x,lower,unique' according to definition in $GLOBALS['TCA']!) |
||
| 149 | $result = $this->resolvePageRelatedParameters($linkParameter); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | return $result; |
||
| 154 | } |
||
| 249 |