AbstractStrategy::resetFileName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
}