Completed
Push — master ( 68fe25...8e1e8c )
by Woody
11s
created

Path::setPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Northwoods\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 27
    public function __construct($path = null)
16
    {
17 27
        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 27
            $this->setPath($path);
19
        }
20 25
    }
21
22
    /**
23
     * @param string $path
24
     * @return $this
25
     * @throws PathNotFoundException
26
     */
27 27
    public function setPath($path)
28
    {
29 27
        $path = realpath($path);
30 27
        if (!is_dir($path)) {
31 2
            throw new PathNotFoundException("Config path ({$path}) is not a valid directory");
32
        }
33 25
        $this->path = $path;
34 25
        return $this;
35
    }
36
37
    /**
38
     * @return string
39
     */
40 21
    public function getPath()
41
    {
42 21
        return $this->path;
43
    }
44
45
    /**
46
     * @return string
47
     */
48 18
    public function __toString()
49
    {
50 18
        return $this->getPath();
51
    }
52
}
53