AbstractStrategy   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 2
cbo 2
dl 0
loc 100
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setFileName() 0 13 2
A setFilePath() 0 17 3
A getFileName() 0 10 2
A getFilePath() 0 10 2
A resetFileName() 0 6 1
A resetFilePath() 0 6 1
1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2014-05-26 
5
 */
6
7
namespace Net\Bazzline\Component\Locator\FileExistsStrategy;
8
9
/**
10
 * Class AbstractStrategy
11
 * @package Net\Bazzline\Component\Locator\FileExistsStrategy
12
 */
13
abstract class AbstractStrategy implements FileExistsStrategyInterface
14
{
15
    /** @var null|string */
16
    private $fileName;
17
18
    /** @var null|string */
19
    private $filePath;
20
21
    /**
22
     * @param string $name
23
     * @return $this
24
     * @throws InvalidArgumentException
25
     */
26
    public function setFileName($name)
27
    {
28
        $name = (string) $name;
29
30
        if ($name === '') {
31
            throw new InvalidArgumentException(
32
                'invalid filename given'
33
            );
34
        }
35
        $this->fileName = $name;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @param string $path
42
     * @return $this
43
     * @throws InvalidArgumentException
44
     */
45
    public function setFilePath($path)
46
    {
47
        if (!is_dir($path)) {
48
            throw new InvalidArgumentException(
49
                'provided path "' . $path . '" has to be a directory'
50
            );
51
        }
52
53
        if (!is_writable($path)) {
54
            throw new InvalidArgumentException(
55
                'provided path "' . $path . '" has to be writable'
56
            );
57
        }
58
        $this->filePath = $path;
59
60
        return $this;
61
    }
62
63
    /**
64
     * @return null|string
65
     * @throws RuntimeException
66
     */
67
    protected function getFileName()
68
    {
69
        if (is_null($this->fileName)) {
70
            throw new RuntimeException(
71
                'file name is mandatory'
72
            );
73
        }
74
75
        return $this->fileName;
76
    }
77
78
    /**
79
     * @return null|string
80
     * @throws RuntimeException
81
     */
82
    protected function getFilePath()
83
    {
84
        if (is_null($this->filePath)) {
85
            throw new RuntimeException(
86
                'file path is mandatory'
87
            );
88
        }
89
90
        return $this->filePath;
91
    }
92
93
    /**
94
     * @return $this
95
     */
96
    protected function resetFileName()
97
    {
98
        $this->fileName = null;
99
100
        return $this;
101
    }
102
103
    /**
104
     * @return $this
105
     */
106
    protected function resetFilePath()
107
    {
108
        $this->filePath = null;
109
110
        return $this;
111
    }
112
}