Passed
Push — master ( ddbf8b...086098 )
by Robbie
11:17
created

PathAware::getPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Control\Middleware\ConfirmationMiddleware;
4
5
/**
6
 * Path aware trait for rules and bypasses
7
 */
8
trait PathAware
9
{
10
    /**
11
     * @var string
12
     */
13
    private $path;
14
15
    /**
16
     * Returns the path
17
     *
18
     * @return string
19
     */
20
    public function getPath()
21
    {
22
        return $this->path;
23
    }
24
25
    /**
26
     * Update the path
27
     *
28
     * @param string $path
29
     *
30
     * @return $this
31
     */
32
    public function setPath($path)
33
    {
34
        $this->path = $this->normalisePath($path);
35
        return $this;
36
    }
37
38
    /**
39
     * Returns the normalised version of the given path
40
     *
41
     * @param string $path Path to normalise
42
     *
43
     * @return string normalised version of the path
44
     */
45
    protected function normalisePath($path)
46
    {
47
        if (substr($path, -1) !== '/') {
48
            return $path . '/';
49
        } else {
50
            return $path;
51
        }
52
    }
53
}
54