File tree Expand file tree Collapse file tree 5 files changed +66
-10
lines changed
Expand file tree Collapse file tree 5 files changed +66
-10
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ final class RexStan {
4+ /**
5+ * @return array|string
6+ */
7+ static public function runFromCli () {
8+ $ phpstanBinary = realpath (__DIR__ .'/../vendor/bin/phpstan ' );
9+ $ configPath = realpath (__DIR__ .'/../phpstan.neon ' );
10+
11+ $ cmd = $ phpstanBinary .' analyse -c ' . $ configPath ;
12+ $ output = shell_exec ($ cmd );
13+
14+ return $ output ;
15+ }
16+
17+ /**
18+ * @return array|string
19+ */
20+ static public function runFromWeb () {
21+ $ phpstanBinary = realpath (__DIR__ .'/../vendor/bin/phpstan ' );
22+ $ configPath = realpath (__DIR__ .'/../phpstan.neon ' );
23+
24+ $ cmd = $ phpstanBinary .' analyse -c ' . $ configPath .' --error-format=json --no-progress 2>&1 ' ;
25+
26+ $ output = shell_exec ($ cmd );
27+ if ($ output [0 ] === '{ ' ) {
28+ // return the analysis result as an array
29+ return json_decode ($ output , true );
30+ }
31+
32+ // return the error string as is
33+ return $ output ;
34+ }
35+ }
Original file line number Diff line number Diff line change 11<?php
22
3- class RexStanUserConfig {
3+ final class RexStanUserConfig {
44 /**
55 * @param int $level
66 * @param array<string> $paths
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Symfony \Component \Console \Exception \InvalidArgumentException ;
4+ use Symfony \Component \Console \Input \InputInterface ;
5+ use Symfony \Component \Console \Input \InputOption ;
6+ use Symfony \Component \Console \Output \OutputInterface ;
7+
8+ class rexstan_command extends rex_console_command
9+ {
10+ protected function configure ()
11+ {
12+ $ this
13+ ->setName ('rexstan:analyze ' )
14+ ->setDescription ('Run static code analysis ' )
15+ ;
16+ }
17+
18+ protected function execute (InputInterface $ input , OutputInterface $ output )
19+ {
20+ echo RexStan::runFromCli ();
21+
22+ return 0 ;
23+ }
24+ }
Original file line number Diff line number Diff line change 1212 settings : { title: translate:settings }
1313 readme : { title: translate:readme, subPath: README.md }
1414
15+ console_commands :
16+ rexstan:analyze : rexstan_command
17+
1518requires :
1619 php :
1720 version : ' >=7.2'
Original file line number Diff line number Diff line change 22
33/** @var rex_addon $this */
44
5- $ phpstanBinary = realpath (__DIR__ .'/../vendor/bin/phpstan ' );
6- $ configPath = realpath (__DIR__ .'/../phpstan.neon ' );
5+ $ phpstanResult = RexStan::runFromWeb ();
76
8- $ cmd = $ phpstanBinary .' analyse -c ' . $ configPath .' --error-format=json --no-progress 2>&1 ' ;
9-
10- $ output = shell_exec ($ cmd );
11- if ($ output [0 ] === '{ ' ) {
12- $ phpstanResult = json_decode ($ output , true );
13- } else {
14- echo '<span class="rexstan-error"> ' .nl2br (rex_escape ($ output )).'</span> ' ;
7+ if (is_string ($ phpstanResult )) {
8+ echo '<span class="rexstan-error"> ' .nl2br (rex_escape ($ phpstanResult )).'</span> ' ;
159 return ;
1610}
1711
You can’t perform that action at this time.
0 commit comments