@@ -68,7 +68,9 @@ 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 ;
71+ $ stagedFiles = array_filter ($ stagedFiles , function ($ file ) {
72+ return (bool ) preg_match ('/^pkg\// ' , $ file );
73+ });
7274
7375 return $ stagedFiles ;
7476}
@@ -77,18 +79,18 @@ function runPhpLint()
7779{
7880 global $ phpBin , $ projectRootDir ;
7981
80- $ filesWithErrors = array () ;
82+ $ output = [] ;
8183 foreach (getFilesToFix () as $ file ) {
82- $ output = '' ;
84+ $ commandOutput = null ;
8385 $ returnCode = null ;
84- exec (sprintf ('%s -l %s 2>/dev/null ' , $ phpBin , $ projectRootDir .'/ ' .$ file ), $ output , $ returnCode );
86+ exec (sprintf ('%s -l %s ' , $ phpBin , $ projectRootDir .'/ ' .$ file ), $ commandOutput , $ returnCode );
8587
8688 if ($ returnCode ) {
87- $ filesWithErrors [] = $ file ;
89+ $ output [] = $ commandOutput ;
8890 }
8991 }
9092
91- return $ filesWithErrors ;
93+ return $ output ;
9294}
9395
9496function runPhpCsFixer ()
@@ -101,40 +103,41 @@ function runPhpCsFixer()
101103 }
102104
103105 $ filesWithErrors = array ();
104- foreach (getFilesToFix () as $ file ) {
105- $ output = '' ;
106- $ returnCode = null ;
106+ $ output = '' ;
107+ $ returnCode = null ;
107108
108- exec (sprintf (
109- '%s %s fix %s --dry-run ' ,
110- $ phpBin ,
111- $ phpCsFixerBin ,
112- $ projectRootDir . ' / ' . $ file
113- ), $ output , $ returnCode );
109+ exec (sprintf (
110+ '%s %s fix --config=.php_cs.php --no-interaction -v --path-mode=intersection -- %s ' ,
111+ $ phpBin ,
112+ $ phpCsFixerBin ,
113+ implode ( ' ' , getFilesToFix ())
114+ ), $ output , $ returnCode );
114115
115- if ( $ returnCode ) {
116- $ output = '' ;
116+ return $ returnCode ? $ output : false ;
117+ }
117118
118- exec (sprintf (
119- '%s %s fix %s ' ,
120- $ phpBin ,
121- $ phpCsFixerBin ,
122- $ projectRootDir .'/ ' .$ file
123- ), $ output );
119+ function runPhpstan ()
120+ {
121+ $ output = '' ;
122+ $ returnCode = null ;
124123
125- $ filesWithErrors [] = $ file ;
126- }
127- }
124+ exec (sprintf (
125+ '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 ' ,
126+ implode (' ' , getFilesToFix ())
127+ ), $ output , $ returnCode );
128128
129- return $ filesWithErrors ;
129+ return $ returnCode ? $ output : false ;
130130}
131131
132+ echo sprintf ('Found %s staged files ' , count (getFilesToFix ())).PHP_EOL ;
133+
132134$ phpSyntaxErrors = runPhpLint ();
133135if ($ phpSyntaxErrors ) {
134136 echo "Php syntax errors were found in next files: " . PHP_EOL ;
135-
136- foreach ($ phpSyntaxErrors as $ error ) {
137- echo $ error . PHP_EOL ;
137+ foreach ($ phpSyntaxErrors as $ phpSyntaxErrors ) {
138+ echo array_walk_recursive ($ phpSyntaxErrors , function ($ item ) {
139+ echo $ item .PHP_EOL ;
140+ }) . PHP_EOL ;
138141 }
139142
140143 exit (1 );
@@ -144,11 +147,22 @@ $phpCSFixerErrors = runPhpCsFixer();
144147if ($ phpCSFixerErrors ) {
145148 echo "Incorrect coding standards were detected and fixed. " . PHP_EOL ;
146149 echo "Please stash changes and run commit again. " . PHP_EOL ;
147- echo "List of changed files: " . PHP_EOL ;
150+ echo "Output: " . PHP_EOL . PHP_EOL ;
148151
149- foreach ($ phpCSFixerErrors as $ error ) {
150- echo $ error . PHP_EOL ;
151- }
152+ echo array_walk_recursive ($ phpStanErrors , function ($ item ) {
153+ echo $ item .PHP_EOL ;
154+ }) . PHP_EOL ;
155+ echo PHP_EOL ;
156+
157+ exit (1 );
158+ }
159+
160+ $ phpStanErrors = runPhpstan ();
161+ if ($ phpStanErrors ) {
162+ echo array_walk_recursive ($ phpStanErrors , function ($ item ) {
163+ echo $ item .PHP_EOL ;
164+ }) . PHP_EOL ;
165+ echo PHP_EOL ;
152166
153167 exit (1 );
154168}
0 commit comments