|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHPCI - Continuous Integration for PHP. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright 2014, Block 8 Limited. |
|
6
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md |
|
7
|
|
|
* |
|
8
|
|
|
* @link https://www.phptesting.org/ |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace PHPCI\Plugin; |
|
12
|
|
|
|
|
13
|
|
|
use PHPCI\Builder; |
|
14
|
|
|
use PHPCI\Model\Build; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* PHP CS Fixer - Works with the PHP Coding Standards Fixer for testing coding standards. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Gabriel Baker <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class PhpCsFixer implements \PHPCI\Plugin |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var \PHPCI\Builder |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $phpci; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var \PHPCI\Model\Build |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $build; |
|
32
|
|
|
|
|
33
|
|
|
protected $workingDir = ''; |
|
34
|
|
|
protected $level = ' --level=psr2'; |
|
35
|
|
|
protected $verbose = ''; |
|
36
|
|
|
protected $diff = ''; |
|
37
|
|
|
protected $levels = array('psr0', 'psr1', 'psr2', 'symfony'); |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Standard Constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* $options['directory'] Output Directory. Default: %BUILDPATH% |
|
43
|
|
|
* $options['filename'] Phar Filename. Default: build.phar |
|
44
|
|
|
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/ |
|
45
|
|
|
* $options['stub'] Stub Content. No Default Value |
|
46
|
|
|
* |
|
47
|
|
|
* @param Builder $phpci |
|
48
|
|
|
* @param Build $build |
|
49
|
|
|
* @param array $options |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct(Builder $phpci, Build $build, array $options = array()) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->phpci = $phpci; |
|
54
|
|
|
$this->build = $build; |
|
55
|
|
|
|
|
56
|
|
|
$this->workingdir = $this->phpci->buildPath; |
|
|
|
|
|
|
57
|
|
|
$this->buildArgs($options); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Run PHP CS Fixer. |
|
62
|
|
|
* |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
|
|
public function execute() |
|
66
|
|
|
{ |
|
67
|
|
|
$curdir = getcwd(); |
|
68
|
|
|
chdir($this->workingdir); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
$phpcsfixer = $this->phpci->findBinary('php-cs-fixer'); |
|
71
|
|
|
|
|
72
|
|
|
$cmd = $phpcsfixer.' fix . %s %s %s'; |
|
73
|
|
|
$success = $this->phpci->executeCommand($cmd, $this->verbose, $this->diff, $this->level); |
|
74
|
|
|
|
|
75
|
|
|
chdir($curdir); |
|
76
|
|
|
|
|
77
|
|
|
return $success; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Build an args string for PHPCS Fixer. |
|
82
|
|
|
* |
|
83
|
|
|
* @param $options |
|
84
|
|
|
*/ |
|
85
|
|
|
public function buildArgs($options) |
|
86
|
|
|
{ |
|
87
|
|
|
if (isset($options['verbose']) && $options['verbose']) { |
|
88
|
|
|
$this->verbose = ' --verbose'; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (isset($options['diff']) && $options['diff']) { |
|
92
|
|
|
$this->diff = ' --diff'; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if (isset($options['level']) && in_array($options['level'], $this->levels)) { |
|
96
|
|
|
$this->level = ' --level='.$options['level']; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if (isset($options['workingdir']) && $options['workingdir']) { |
|
100
|
|
|
$this->workingdir = $this->phpci->buildPath.$options['workingdir']; |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.