Lines
61.53%
8 / 13
Methods
50.00%
1 / 2
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| urlFor | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| determineBasePath | 58.33% | 7 / 12 | 0.00% | 0 / 1 | 10.54 | ||
| 10 | class SlimApp extends \Slim\App | |
| 11 | { | |
| 12 | public function urlFor(string $name, array $params = []): string | |
| 13 | { | |
| 14 | return $this->getRouteCollector()->getRouteParser()->urlFor($name, $params); | |
| 15 | } | |
| 16 | ||
| 17 | /** | |
| 18 | * @SuppressWarnings("PHPMD.Superglobals") | |
| 19 | */ | |
| 20 | public function determineBasePath(): void | |
| 21 | { | |
| 22 | $envBasePath = getenv('ZMS_MODULE_BASEPATH'); | |
| 23 | $basePath = $envBasePath !== false ? $envBasePath : ''; | |
| 24 | if ($basePath === '') { | |
| 25 | $requestUri = $_SERVER['REQUEST_URI'] ?? null; | |
| 26 | $scriptName = $_SERVER['SCRIPT_NAME'] ?? null; | |
| 27 | if (!is_string($requestUri) || !is_string($scriptName)) { | |
| 28 | return; | |
| 29 | } | |
| 30 | ||
| 31 | while ( | |
| 32 | min(strlen($requestUri), strlen($scriptName)) > strlen($basePath) | |
| 33 | && strncmp($requestUri, $scriptName, strlen($basePath) + 1) === 0 | |
| 34 | ) { | |
| 35 | $nextPath = substr($requestUri, 0, strlen($basePath) + 1); | |
| 36 | $basePath = $nextPath; | |
| 37 | } | |
| 38 | } | |
| 39 | ||
| 40 | $this->setBasePath(rtrim($basePath, '/')); | |
| 41 | } | |
| 42 | } |