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

CanResolveDocumentRoot   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDocumentRoot() 0 10 4
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