Passed
Push — master ( b5ca42...8fe651 )
by Siad
05:05
created

MkdirTask::main()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 9.1595

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 18
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 26
ccs 10
cts 18
cp 0.5556
crap 9.1595
rs 9.0444
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
use Phing\Exception\BuildException;
21
use Phing\Io\File;
22
use Phing\Project;
23
use Phing\Task;
24
25
/**
26
 * Task to create a directory.
27
 *
28
 * @author  Andreas Aderhold, [email protected]
29
 * @package phing.tasks.system
30
 */
31
class MkdirTask extends Task
32
{
33
34
    /**
35
     * Directory to create.
36
     *
37
     * @var File $dir
38
     */
39
    private $dir;
40
41
    /**
42
     * Mode to create directory with
43
     *
44
     * @var integer|null
45
     */
46
    private $mode = null;
47
48
    /**
49
     * create the directory and all parents
50
     *
51
     * @throws BuildException if dir is somehow invalid, or creation failed.
52
     */
53 172
    public function main()
54
    {
55 172
        if ($this->dir === null) {
56
            throw new BuildException("dir attribute is required", $this->getLocation());
57
        }
58 172
        if ($this->dir->isFile()) {
59
            throw new BuildException(
60
                "Unable to create directory as a file already exists with that name: " . $this->dir->getAbsolutePath()
61
            );
62
        }
63 172
        if (!$this->dir->exists()) {
64 166
            $result = $this->dir->mkdirs($this->mode);
65 166
            if (!$result) {
66
                if ($this->dir->exists()) {
67
                    $this->log("A different process or task has already created " . $this->dir->getAbsolutePath());
68
69
                    return;
70
                }
71
                $msg = "Directory " . $this->dir->getAbsolutePath() . " creation was not successful for an unknown reason";
72
                throw new BuildException($msg, $this->getLocation());
73
            }
74 166
            $this->log("Created dir: " . $this->dir->getAbsolutePath());
75
        } else {
76 13
            $this->log(
77 13
                'Skipping ' . $this->dir->getAbsolutePath() . ' because it already exists.',
78 13
                Project::MSG_VERBOSE
79
            );
80
        }
81 172
    }
82
83
    /**
84
     * The directory to create; required.
85
     *
86
     * @param  File $dir
87
     * @return void
88
     */
89 172
    public function setDir(File $dir)
90
    {
91 172
        $this->dir = $dir;
92 172
    }
93
94
    /**
95
     * Sets mode to create directory with
96
     *
97
     * @param  mixed $mode
98
     * @return void
99
     */
100 4
    public function setMode($mode)
101
    {
102 4
        $this->mode = base_convert((int) $mode, 8, 10);
0 ignored issues
show
Documentation Bug introduced by
It seems like base_convert((int)$mode, 8, 10) of type string is incompatible with the declared type integer|null of property $mode.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
103 4
    }
104
}
105