Passed
Push — main ( 28d658...6dddcc )
by Michiel
06:12
created

HgBaseTask::checkRepositoryIsDirAndExists()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
rs 10
cc 3
nc 3
nop 1
crap 3.0416
1
<?php
2
3
/**
4
 * Utilise Mercurial from within Phing.
5
 *
6
 * PHP Version 5.4
7
 *
8
 * @category Tasks
9
 * @package  phing.tasks.ext
10
 * @author   Ken Guest <[email protected]>
11
 * @license  LGPL (see http://www.gnu.org/licenses/lgpl.html)
12
 * @link     https://github.com/kenguest/Phing-HG
13
 */
14
15
namespace Phing\Task\Ext\Hg;
16
17
use Phing\Task;
18
use Phing\Exception\BuildException;
19
use Phing\Util\StringHelper;
20
use Siad007\VersionControl\HG\Factory;
21
22
/**
23
 * Base task for integrating phing and mercurial.
24
 *
25
 * @category Tasks
26
 * @package  phing.tasks.ext.hg
27
 * @author   Ken Guest <[email protected]>
28
 * @license  LGPL (see http://www.gnu.org/licenses/lgpl.html)
29
 * @link     HgBaseTask.php
30
 */
31
abstract class HgBaseTask extends Task
32
{
33
    /**
34
     * Insecure argument
35
     *
36
     * @var string
37
     */
38
    protected $insecure = '';
39
40
    /**
41
     * Repository directory
42
     *
43
     * @var string
44
     */
45
    protected $repository = '';
46
47
    /**
48
     * Whether to be quiet... --quiet argument.
49
     *
50
     * @var bool
51
     */
52
    protected $quiet = false;
53
54
    /**
55
     * Username.
56
     *
57
     * @var string
58
     */
59
    protected $user = '';
60
61
    public static $factory = null;
62
    /**
63
     * Set repository attribute
64
     *
65
     * @param string $repository Repository
66
     *
67
     * @return void
68
     */
69 16
    public function setRepository($repository)
70
    {
71 16
        $this->repository = $repository;
72
    }
73
74
75
    /**
76
     * Set the quiet attribute --quiet
77
     *
78
     * @param string $quiet yes|no|true|false|1|0
79
     *
80
     * @return void
81
     */
82
    public function setQuiet($quiet)
83
    {
84
        $this->quiet = StringHelper::booleanValue($quiet);
85
    }
86
87
    /**
88
     * Get the quiet attribute value.
89
     *
90
     * @return bool
91
     */
92 15
    public function getQuiet()
93
    {
94 15
        return $this->quiet;
95
    }
96
97
    /**
98
     * Get Repository attribute/directory.
99
     *
100
     * @return string
101
     */
102 3
    public function getRepository()
103
    {
104 3
        return $this->repository;
105
    }
106
107
    /**
108
     * Set insecure attribute
109
     *
110
     * @param string $insecure 'yes', etc.
111
     *
112
     * @return void
113
     */
114
    public function setInsecure($insecure)
115
    {
116
        $this->insecure = StringHelper::booleanValue($insecure);
0 ignored issues
show
Documentation Bug introduced by
The property $insecure was declared of type string, but Phing\Util\StringHelper::booleanValue($insecure) is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
117
    }
118
119
    /**
120
     * Get 'insecure' attribute value. (--insecure or null)
121
     *
122
     * @return string
123
     */
124 11
    public function getInsecure()
125
    {
126 11
        return $this->insecure;
127
    }
128
129
    /**
130
     * Set user attribute
131
     *
132
     * @param string $user username/email address.
133
     *
134
     * @return void
135
     */
136 2
    public function setUser($user)
137
    {
138 2
        $this->user = $user;
139
    }
140
141
    /**
142
     * Get username attribute.
143
     *
144
     * @return string
145
     */
146 1
    public function getUser()
147
    {
148 1
        return $this->user;
149
    }
150
151
    /**
152
     * Check provided repository directory actually is an existing directory.
153
     *
154
     * @param string $dir Repository directory
155
     *
156
     * @return bool
157
     * @throws BuildException
158
     */
159 11
    public function checkRepositoryIsDirAndExists($dir)
160
    {
161 11
        if (file_exists($dir)) {
162 7
            if (!is_dir($dir)) {
163
                throw new BuildException("Repository '$dir' is not a directory.");
164
            }
165
        } else {
166 4
            throw new BuildException("Repository directory '$dir' does not exist.");
167
        }
168 7
        return true;
169
    }
170
171 21
    public function getFactoryInstance($command, $options = [])
172
    {
173 21
        self::$factory = Factory::getInstance($command, $options);
174 21
        return self::$factory;
175
    }
176
}
177