|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* PHP-CS-Fixer plugin for HiDev |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/hidev-php-cs-fixer |
|
7
|
|
|
* @package hidev-php-cs-fixer |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hidev\phpcsfixer\console; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Goal to run php-cs-fixer. |
|
16
|
|
|
*/ |
|
17
|
|
|
class PhpCsFixerController extends \hidev\controllers\FileController |
|
18
|
|
|
{ |
|
19
|
|
|
protected $_before = ['.php_cs']; |
|
20
|
|
|
|
|
21
|
|
|
protected $_version; |
|
22
|
|
|
|
|
23
|
|
|
public function setVersion($value) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->_version = $value; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getVersion() |
|
29
|
|
|
{ |
|
30
|
|
|
if ($this->_version === null) { |
|
31
|
|
|
$this->_version = $this->determineVersion(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
return $this->_version; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function determineVersion() |
|
38
|
|
|
{ |
|
39
|
|
|
$str = reset($this->exec('php-cs-fixer', ['--version'])); |
|
|
|
|
|
|
40
|
|
|
if (preg_match('/ version (\S+) /', $str, $m)) { |
|
41
|
|
|
return $m[1]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return '1.x'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getCasedLevel() |
|
48
|
|
|
{ |
|
49
|
|
|
$level = strtolower($this->level); |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
return $level === 'symfony' ? 'Symfony' : strtoupper($level); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function actionMake() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->runAction('fix'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function actionFix() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->runAction('stop-fix'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function actionStopFix() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->passthru('php-cs-fixer', ['fix', '.']); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function actionCheck() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->passthru('php-cs-fixer', ['fix', '.', '--dry-run']); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|