Passed
Push — master ( 127e3c...a9335c )
by Siad
06:34
created

PhpCSTask::setFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
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
 * A PHP code sniffer task. Checking the style of one or more PHP source files.
22
 *
23
 * @author  Siad Ardroumli <[email protected]>
24
 * @package phing.tasks.ext
25
 */
26
class PhpCSTask extends Task
27
{
28
    use LogLevelAware;
29
30
    /**
31
     * A php source code filename or directory
32
     *
33
     * @var PhingFile
34
     */
35
    private $file;
36
37
    /** @var Commandline */
38
    private $cmd;
39
40
    /** @var bool */
41
    private $cache = false;
42
43
    /** @var bool */
44
    private $ignoreAnnotations = false;
45
46
    /** @var bool */
47
    private $checkreturn = false;
48
49
    /** @var string */
50
    private $bin = 'phpcs';
51
52 1
    public function __construct()
53
    {
54 1
        $this->cmd = new Commandline();
55 1
        $this->logLevelName = 'info';
56 1
        parent::__construct();
57 1
    }
58
59 1
    public function getCommandline(): Commandline
60
    {
61 1
        return $this->cmd;
62
    }
63
64
    /**
65
     * @param bool $cache
66
     */
67
    public function setCache(bool $cache): void
68
    {
69
        $this->cache = $cache;
70
    }
71
72
    /**
73
     * @param bool $ignore
74
     */
75 1
    public function setIgnoreAnnotations(bool $ignore): void
76
    {
77 1
        $this->ignoreAnnotations = $ignore;
78 1
    }
79
80
    /**
81
     * @param bool $checkreturn
82
     */
83 1
    public function setCheckreturn(bool $checkreturn): void
84
    {
85 1
        $this->checkreturn = $checkreturn;
86 1
    }
87
88
    /**
89
     * @param string $bin
90
     */
91 1
    public function setBin(string $bin): void
92
    {
93 1
        $this->bin = $bin;
94 1
    }
95
96
    /**
97
     * @param PhingFile $file
98
     */
99 1
    public function setFile(PhingFile $file): void
100
    {
101 1
        $this->file = $file;
102 1
    }
103
104 1
    public function main()
105
    {
106 1
        if ($this->file === null) {
107
            throw new BuildException('Missing attribute "file".');
108
        }
109
110 1
        $toExecute = $this->getCommandline();
111
112 1
        $this->cache
113
            ? $toExecute->createArgument()->setValue('--cache')
114 1
            : $toExecute->createArgument()->setValue('--no-cache');
115
116 1
        if ($this->ignoreAnnotations) {
117 1
            $toExecute->createArgument()->setValue('--ignore-annotations');
118
        }
119
120 1
        $toExecute->createArgument()->setFile($this->file);
121
122 1
        $exe = new ExecTask();
123 1
        $exe->setProject($this->getProject());
124 1
        $exe->setLocation($this->getLocation());
125 1
        $exe->setOwningTarget($this->target);
126 1
        $exe->setTaskName($this->getTaskName());
127 1
        $exe->setExecutable($this->bin);
128 1
        $exe->setCheckreturn($this->checkreturn);
129 1
        $exe->setLevel($this->logLevelName);
130 1
        $exe->setExecutable($toExecute->getExecutable());
131 1
        $exe->createArg()->setLine(implode(' ', $toExecute->getArguments()));
132 1
        $exe->main();
133 1
    }
134
}
135