Passed
Push — master ( 1117df...fac7df )
by Siad
11:02
created

Dirname   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 48
ccs 12
cts 15
cp 0.8
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 0 3 1
A setFile() 0 6 2
A main() 0 11 3
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
 * Determines the directory name of the specified file.
22
 *
23
 * This task can accept the following attributes:
24
 * <ul>
25
 * <li>file
26
 * <li>property
27
 * </ul>
28
 * Both <b>file</b> and <b>property</b> are required.
29
 * <p>
30
 * When this task executes, it will set the specified property to the
31
 * value of the specified file up to, but not including, the last path
32
 * element. If file is a file, the directory will be the current
33
 * directory.
34
 *
35
 * @author  Siad Ardroumli <[email protected]>
36
 * @package phing.tasks.system
37
 */
38
class Dirname extends Task
39
{
40
    /**
41
     * @var PhingFile $file
42
     */
43
    private $file;
44
    private $property;
45
46
    /**
47
     * Path to take the dirname of.
48
     *
49
     * @param string|PhingFile file a <code>File</code> value
50
     */
51 1
    public function setFile($file)
52
    {
53 1
        if ($file instanceof PhingFile) {
54
            $this->file = $file;
55
        } else {
56 1
            $this->file = new PhingFile($file);
57
        }
58 1
    }
59
60
    /**
61
     * The name of the property to set.
62
     *
63
     * @param string $property the name of the property
64
     */
65 1
    public function setProperty($property)
66
    {
67 1
        $this->property = $property;
68 1
    }
69
70
    /**
71
     * Execute this task.
72
     *
73
     * @throws BuildException on error
74
     */
75 1
    public function main()
76
    {
77 1
        if ($this->property == null) {
78
            throw new BuildException("property attribute required", $this->getLocation());
79
        }
80 1
        if ($this->file == null) {
81
            throw new BuildException("file attribute required", $this->getLocation());
82
        }
83
84 1
        $value = $this->file->getAbsoluteFile()->getParent();
85 1
        $this->getProject()->setNewProperty($this->property, $value);
86 1
    }
87
}
88