@@ -68,8 +68,6 @@ function getFilesToFix()
6868 return (bool ) preg_match ('/\.(php|twig|translations\/*.yml)$/ ' , $ file );
6969 });
7070
71- echo sprintf ('Found %s staged files ' , count ($ stagedFiles )).PHP_EOL ;
72-
7371 return $ stagedFiles ;
7472}
7573
@@ -129,6 +127,29 @@ function runPhpCsFixer()
129127 return $ filesWithErrors ;
130128}
131129
130+ function runPhpstan ()
131+ {
132+ $ filesWithErrors = array ();
133+ foreach (getFilesToFix () as $ file ) {
134+ $ output = '' ;
135+ $ returnCode = null ;
136+
137+ exec (sprintf (
138+ 'docker run --workdir="/mqdev" -v "`pwd`:/mqdev" --rm enqueue/dev:latest php -d memory_limit=1024M bin/phpstan analyse -l 1 -c phpstan.neon %s ' ,
139+ $ file
140+ ), $ output , $ returnCode );
141+
142+ if ($ returnCode ) {
143+ $ filesWithErrors [] = [$ file , $ output ];
144+ }
145+ }
146+
147+ return $ filesWithErrors ;
148+ }
149+
150+
151+ echo sprintf ('Found %s staged files ' , count (getFilesToFix ())).PHP_EOL ;
152+
132153$ phpSyntaxErrors = runPhpLint ();
133154if ($ phpSyntaxErrors ) {
134155 echo "Php syntax errors were found in next files: " . PHP_EOL ;
@@ -153,4 +174,21 @@ if ($phpCSFixerErrors) {
153174 exit (1 );
154175}
155176
177+ $ phpStanErrors = runPhpstan ();
178+ var_dump ($ phpStanErrors );
179+ if ($ phpStanErrors ) {
180+ echo "Phpstan errors. " . PHP_EOL ;
181+ echo "List of changed files: " . PHP_EOL ;
182+
183+ foreach ($ phpStanErrors as list ($ file , $ error )) {
184+ echo $ file . PHP_EOL ;
185+ echo array_walk_recursive ($ error , function ($ item ) {
186+ echo $ item .PHP_EOL ;
187+ }) . PHP_EOL ;
188+ echo PHP_EOL ;
189+ }
190+
191+ exit (1 );
192+ }
193+
156194exit (0 );
0 commit comments