Completed
Push — master ( da521e...2646ae )
by Richan
01:12
created

CanResolveDocumentRoot::getDocumentRoot()   A

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
     * @throws LogicException
14
     * @return string
15
     */
16
    public function getDocumentRoot($path) :string
17
    {
18
        $path = is_string($path) ? realpath($path) : realpath('.');
19
20
        if ($path === false || !is_dir($path)) {
21
            throw new LogicException('The given path is not a directory or directory is not exists.');
22
        }
23
24
        return $path;
25
    }
26
}
27