|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the CS library. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2015-present LIN3S <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace LIN3S\CS; |
|
15
|
|
|
|
|
16
|
|
|
use LIN3S\CS\Checker\Composer; |
|
17
|
|
|
use LIN3S\CS\Checker\EsLint; |
|
18
|
|
|
use LIN3S\CS\Checker\PhpCsFixer; |
|
19
|
|
|
use LIN3S\CS\Checker\Phpmd; |
|
20
|
|
|
use LIN3S\CS\Checker\Stylelint; |
|
21
|
|
|
use LIN3S\CS\Checker\TwigCs; |
|
22
|
|
|
use LIN3S\CS\Exception\CheckFailException; |
|
23
|
|
|
use LIN3S\CS\Git\Git; |
|
24
|
|
|
use Symfony\Component\Console\Application as BaseApplication; |
|
25
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
26
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
27
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @author Beñat Espiña <[email protected]> |
|
31
|
|
|
*/ |
|
32
|
|
|
final class Application extends BaseApplication |
|
33
|
|
|
{ |
|
34
|
|
|
private const APP_NAME = 'LIN3S CS'; |
|
35
|
|
|
private const APP_VERSION = '0.7.x-dev'; |
|
36
|
|
|
|
|
37
|
|
|
private $name; |
|
|
|
|
|
|
38
|
|
|
private $parameters; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct() |
|
41
|
|
|
{ |
|
42
|
|
|
parent::__construct(self::APP_NAME, self::APP_VERSION); |
|
43
|
|
|
|
|
44
|
|
|
$rootDirectory = realpath(__DIR__ . '/../../../../../../'); |
|
45
|
|
|
$this->parameters = Yaml::parse(file_get_contents($rootDirectory . '/.lin3s_cs.yml'))['parameters']; |
|
46
|
|
|
$this->parameters['root_directory'] = $rootDirectory; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function doRun(InputInterface $input, OutputInterface $output) |
|
50
|
|
|
{ |
|
51
|
|
|
$output->writeln(sprintf('<fg=white;options=bold;bg=red>%s</fg=white;options=bold;bg=red>', $this->name)); |
|
52
|
|
|
$output->writeln('<info>Fetching files...</info>'); |
|
53
|
|
|
$files = Git::committedFiles(); |
|
54
|
|
|
|
|
55
|
|
|
$output->writeln('<info>Check composer</info>'); |
|
56
|
|
|
Composer::check($files); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
if (in_array('phpcsfixer', $this->parameters['enabled'], true)) { |
|
59
|
|
|
$output->writeln('<info>Fixing PHP code style with PHP-CS-Fixer</info>'); |
|
60
|
|
|
PhpCsFixer::check($files, $this->parameters); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (in_array('twigcs', $this->parameters['enabled'], true)) { |
|
64
|
|
|
$output->writeln('<info>Linting the Twig files with TwigCS</info>'); |
|
65
|
|
|
$twigCsResult = TwigCs::check($files, $this->parameters); |
|
|
|
|
|
|
66
|
|
|
if (count($twigCsResult) > 0) { |
|
67
|
|
|
foreach ($twigCsResult as $error) { |
|
68
|
|
|
$output->writeln($error->output()); |
|
69
|
|
|
} |
|
70
|
|
|
throw new CheckFailException('TwigCS'); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (in_array('phpmd', $this->parameters['enabled'], true)) { |
|
75
|
|
|
$output->writeln('<info>Checking code mess with PHPMD</info>'); |
|
76
|
|
|
$phpmdResult = Phpmd::check($files, $this->parameters); |
|
|
|
|
|
|
77
|
|
|
if (count($phpmdResult) > 0) { |
|
78
|
|
|
foreach ($phpmdResult as $error) { |
|
79
|
|
|
$output->writeln($error->output()); |
|
80
|
|
|
} |
|
81
|
|
|
throw new CheckFailException('PHPMD'); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (in_array('stylelint', $this->parameters['enabled'], true)) { |
|
86
|
|
|
$output->writeln('<info>Checking scss files with Stylelint</info>'); |
|
87
|
|
|
$stylelintResult = Stylelint::check($files, $this->parameters); |
|
|
|
|
|
|
88
|
|
|
if (count($stylelintResult) > 0) { |
|
89
|
|
|
foreach ($stylelintResult as $error) { |
|
90
|
|
|
$output->writeln($error->output()); |
|
91
|
|
|
} |
|
92
|
|
|
throw new CheckFailException('Stylelint', 'Please, execute "npm update -g stylelint'); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if (in_array('eslint', $this->parameters['enabled'], true)) { |
|
97
|
|
|
$output->writeln('<info>Checking js files with ESLint</info>'); |
|
98
|
|
|
$esLintResult = EsLint::check($files, $this->parameters); |
|
|
|
|
|
|
99
|
|
|
if (count($esLintResult) > 0) { |
|
100
|
|
|
foreach ($esLintResult as $error) { |
|
101
|
|
|
$output->writeln($error->output()); |
|
102
|
|
|
} |
|
103
|
|
|
throw new CheckFailException( |
|
104
|
|
|
'ESLint', |
|
105
|
|
|
'Please, execute "npm update -g eslint eslint-plugin-class-property ' . |
|
106
|
|
|
'eslint-plugin-react eslint-plugin-babel babel-eslint"' |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
Git::addFiles($files, $this->parameters['root_directory']); |
|
|
|
|
|
|
112
|
|
|
$output->writeln('<info>Nice commit man!</info>'); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function parameters() |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->parameters; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|