RequestHelper::getPathInfo()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tebe\Pvc\Helper;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
9
class RequestHelper
10
{
11
    public static function getPathInfo(ServerRequestInterface $request): string
12
    {
13
        $serverParams = $request->getServerParams();
14
        $pathInfo = $serverParams['PATH_INFO'] ?? '';
15
        $pathInfo = trim($pathInfo, '/');
16
        if (empty($pathInfo)) {
17
            $pathInfo = 'index/index';
18
        }
19
        if (strpos($pathInfo, '/') === false) {
20
            $pathInfo .= '/index';
21
        }
22
        return $pathInfo;
23
    }
24
}
25