Path   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A setPath() 0 9 2
A getPath() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace Sinergi\Config\Path;
4
5
class Path implements PathInterface
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $path;
11
12
    /**
13
     * @param null|string $path
14
     */
15
    public function __construct($path = null)
16
    {
17
        if ($path) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $path of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
18
            $this->setPath($path);
19
        }
20
    }
21
22
    /**
23
     * @param string $path
24
     * @return $this
25
     * @throws PathNotFoundException
26
     */
27
    public function setPath($path)
28
    {
29
        $path = realpath($path);
30
        if (!is_dir($path)) {
31
            throw new PathNotFoundException("Config path ({$path}) is not a valid directory");
32
        }
33
        $this->path = $path;
34
        return $this;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getPath()
41
    {
42
        return $this->path;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function __toString()
49
    {
50
        return $this->getPath();
51
    }
52
}
53