CanResolveDocumentRoot::getDocumentRoot()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
namespace Suitmedia\LighthouseAudit\Concerns;
4
5
use LogicException;
6
7
trait CanResolveDocumentRoot
8
{
9
    /**
10
     * Validate and return the real document root path.
11
     *
12
     * @param mixed $path
13
     *
14
     * @throws LogicException
15
     *
16
     * @return string
17
     */
18
    public function getDocumentRoot($path) :string
19
    {
20
        $path = is_string($path) ? realpath($path) : realpath('.');
21
22
        if ($path === false || !is_dir($path)) {
23
            throw new LogicException('The given path is not a directory or directory is not exists.');
24
        }
25
26
        return $path;
27
    }
28
}
29