Passed
Push — master ( 06f87c...33b6d3 )
by Siad
08:23
created

HasFreeSpaceCondition::parseHumanSizes()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 20
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
eloc 17
nc 7
nop 1
dl 0
loc 20
ccs 0
cts 18
cp 0
crap 56
rs 8.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
/**
21
 * Condition returns true if selected partition has the requested space, false otherwise.
22
 *
23
 * @author  Siad Ardroumli <[email protected]>
24
 * @package phing.tasks.system.condition
25
 */
26
class HasFreeSpaceCondition implements Condition
27
{
28
    /**
29
     * @var string $partition
30
     */
31
    private $partition;
32
33
    /**
34
     * @var string $needed
35
     */
36
    private $needed;
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @throws BuildException
42
     *
43
     * @return boolean
44
     */
45
    public function evaluate()
46
    {
47
        $this->validate();
48
49
        $free = disk_free_space($this->partition);
50
        return $free >= SizeHelper::fromHumanToBytes($this->needed);
51
    }
52
53
    /**
54
     * @return void
55
     *
56
     * @throws BuildException
57
     */
58
    private function validate()
59
    {
60
        if (null == $this->partition) {
61
            throw new BuildException("Please set the partition attribute.");
62
        }
63
        if (null == $this->needed) {
64
            throw new BuildException("Please set the needed attribute.");
65
        }
66
    }
67
68
    /**
69
     * Set the partition/device to check.
70
     *
71
     * @param $partition
72
     *
73
     * @return void
74
     */
75
    public function setPartition($partition)
76
    {
77
        $this->partition = $partition;
78
    }
79
80
    /**
81
     * Set the amount of free space required.
82
     *
83
     * @return void
84
     */
85
    public function setNeeded($needed)
86
    {
87
        $this->needed = $needed;
88
    }
89
}
90