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
|
|
|
/** |
29
|
|
|
* A php source code filename or directory |
30
|
|
|
* |
31
|
|
|
* @var PhingFile |
32
|
|
|
*/ |
33
|
|
|
private $file; |
34
|
|
|
|
35
|
|
|
/** @var Commandline */ |
36
|
|
|
private $cmd; |
37
|
|
|
|
38
|
|
|
/** @var bool */ |
39
|
|
|
private $cache = false; |
40
|
|
|
|
41
|
|
|
/** @var bool */ |
42
|
|
|
private $ignoreAnnotations = false; |
43
|
|
|
|
44
|
|
|
/** @var bool */ |
45
|
|
|
private $checkreturn = false; |
46
|
|
|
|
47
|
|
|
/** @var string */ |
48
|
|
|
private $bin = 'phpcs'; |
49
|
|
|
|
50
|
|
|
public function __construct() |
51
|
|
|
{ |
52
|
|
|
$this->cmd = new Commandline(); |
53
|
|
|
parent::__construct(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getCommandline(): Commandline |
57
|
|
|
{ |
58
|
|
|
return $this->cmd; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param bool $cache |
63
|
|
|
*/ |
64
|
|
|
public function setCache(bool $cache): void |
65
|
|
|
{ |
66
|
|
|
$this->cache = $cache; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param bool $ignore |
71
|
|
|
*/ |
72
|
|
|
public function setIgnoreAnnotations(bool $ignore): void |
73
|
|
|
{ |
74
|
|
|
$this->ignoreAnnotations = $ignore; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param bool $checkreturn |
79
|
|
|
*/ |
80
|
|
|
public function setCheckreturn(bool $checkreturn): void |
81
|
|
|
{ |
82
|
|
|
$this->checkreturn = $checkreturn; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $bin |
87
|
|
|
*/ |
88
|
|
|
public function setBin(string $bin): void |
89
|
|
|
{ |
90
|
|
|
$this->bin = $bin; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param PhingFile $file |
95
|
|
|
*/ |
96
|
|
|
public function setFile(PhingFile $file): void |
97
|
|
|
{ |
98
|
|
|
$this->file = $file; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function main() |
102
|
|
|
{ |
103
|
|
|
if ($this->file === null) { |
104
|
|
|
throw new BuildException('Missing attribute "file".'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$toExecute = $this->getCommandline(); |
108
|
|
|
|
109
|
|
|
$this->cache |
110
|
|
|
? $toExecute->createArgument()->setValue('--cache') |
111
|
|
|
: $toExecute->createArgument()->setValue('--no-cache'); |
112
|
|
|
|
113
|
|
|
if ($this->ignoreAnnotations) { |
114
|
|
|
$toExecute->createArgument()->setValue('--ignore-annotations'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$toExecute->createArgument()->setFile($this->file); |
118
|
|
|
|
119
|
|
|
$exe = new ExecTask(); |
120
|
|
|
$exe->setProject($this->getProject()); |
121
|
|
|
$exe->setLocation($this->getLocation()); |
122
|
|
|
$exe->setOwningTarget($this->target); |
123
|
|
|
$exe->setTaskName($this->getTaskName()); |
124
|
|
|
$exe->setExecutable($this->bin); |
125
|
|
|
$exe->setCheckreturn($this->checkreturn); |
126
|
|
|
$exe->setLevel('info'); |
127
|
|
|
$exe->setExecutable($toExecute->getExecutable()); |
128
|
|
|
$exe->createArg()->setLine(implode(' ', $toExecute->getArguments())); |
129
|
|
|
$exe->main(); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|