1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Cubiche application. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) Cubiche |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
namespace Cubiche\Tools\CodeStyle; |
12
|
|
|
|
13
|
|
|
use Cubiche\Tools\ConfigUtils; |
14
|
|
|
use Symfony\CS\Console\Command\FixCommand; |
15
|
|
|
use Symfony\CS\Fixer; |
16
|
|
|
use Symfony\CS\Finder\DefaultFinder; |
17
|
|
|
use Symfony\CS\Config\Config; |
18
|
|
|
use Cubiche\Tools\GitUtils; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* CSFixCommand. |
22
|
|
|
* |
23
|
|
|
* @author Karel Osorio Ramírez <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class CSFixCommand extends FixCommand |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @param Fixer $fixer |
29
|
|
|
*/ |
30
|
|
|
public function __construct(Fixer $fixer = null) |
31
|
|
|
{ |
32
|
|
|
$finder = DefaultFinder::create(); |
33
|
|
|
$finder->append($this->commitedFiles()); |
34
|
|
|
|
35
|
|
|
parent::__construct($fixer, Config::create()->finder($finder)->fixers($this->fixers())); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return Generator |
40
|
|
|
*/ |
41
|
|
|
protected function commitedFiles() |
42
|
|
|
{ |
43
|
|
|
foreach (GitUtils::commitedFiles() as $file) { |
44
|
|
|
yield new \SplFileInfo($file); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
|
|
protected function fixers() |
52
|
|
|
{ |
53
|
|
|
$config = ConfigUtils::getConfig('phpcsfixer', array( |
54
|
|
|
'fixers' => [ |
55
|
|
|
'-psr0','eof_ending','indentation','linefeed','lowercase_keywords','trailing_spaces', 'short_tag', |
56
|
|
|
'php_closing_tag','extra_empty_lines','elseif','function_declaration', '-phpdoc_scalar', '-phpdoc_types' |
57
|
|
|
] |
58
|
|
|
)); |
59
|
|
|
|
60
|
|
|
return $config['fixers']; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|