1616use CleverAge \ProcessBundle \Event \ConsoleProcessEvent ;
1717use CleverAge \ProcessBundle \Filesystem \JsonStreamFile ;
1818use CleverAge \ProcessBundle \Manager \ProcessManager ;
19- use InvalidArgumentException ;
2019use Psr \EventDispatcher \EventDispatcherInterface ;
2120use Symfony \Component \Console \Attribute \AsCommand ;
2221use Symfony \Component \Console \Command \Command ;
2625use Symfony \Component \Console \Output \OutputInterface ;
2726use Symfony \Component \VarDumper \VarDumper ;
2827use Symfony \Component \Yaml \Parser ;
29- use function count ;
30- use function is_array ;
3128
3229/**
33- * Run a process from the command line interface
30+ * Run a process from the command line interface.
3431 */
35- #[AsCommand(name: 'cleverage:process:execute ' , description: 'Execute a process ' ,)]
32+ #[AsCommand(name: 'cleverage:process:execute ' , description: 'Execute a process ' , )]
3633class ExecuteProcessCommand extends Command
3734{
3835 final public const OUTPUT_STDOUT = '- ' ;
@@ -79,8 +76,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7976 $ inputData = $ input ->getOption ('input ' );
8077 if ($ input ->getOption ('input-from-stdin ' )) {
8178 $ inputData = '' ;
82- while (! feof (STDIN )) {
83- $ inputData .= fread (STDIN , 8192 );
79+ while (!feof (\ STDIN )) {
80+ $ inputData .= fread (\ STDIN , 8192 );
8481 }
8582 }
8683
@@ -89,15 +86,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8986 $ this ->eventDispatcher ->dispatch (new ConsoleProcessEvent ($ input , $ output , $ inputData , $ context ));
9087
9188 foreach ($ input ->getArgument ('processCodes ' ) as $ code ) {
92- if (! $ output ->isQuiet ()) {
89+ if (!$ output ->isQuiet ()) {
9390 $ output ->writeln ("<comment>Starting process ' {$ code }'...</comment> " );
9491 }
9592
9693 // Execute each process
9794 $ returnValue = $ this ->processManager ->execute ($ code , $ inputData , $ context );
9895 $ this ->handleOutputData ($ returnValue , $ input , $ output );
9996
100- if (! $ output ->isQuiet ()) {
97+ if (!$ output ->isQuiet ()) {
10198 $ output ->writeln ("<info>Process ' {$ code }' executed successfully</info> " );
10299 }
103100 }
@@ -117,9 +114,9 @@ protected function parseContextValues(InputInterface $input): array
117114 $ context = [];
118115 foreach ($ contextValues as $ contextValue ) {
119116 preg_match ($ pattern , (string ) $ contextValue , $ parts );
120- if (count ( $ parts ) !== 3
117+ if (3 !== \count ( $ parts )
121118 || $ parts [0 ] !== $ contextValue ) {
122- throw new InvalidArgumentException (sprintf ('Invalid context %s ' , $ contextValue ));
119+ throw new \ InvalidArgumentException (sprintf ('Invalid context %s ' , $ contextValue ));
123120 }
124121 $ context [$ parts [1 ]] = $ parser ->parse ($ parts [2 ]);
125122 }
@@ -130,29 +127,29 @@ protected function parseContextValues(InputInterface $input): array
130127 protected function handleOutputData (mixed $ data , InputInterface $ input , OutputInterface $ output ): void
131128 {
132129 // Skip all if undefined
133- if (! $ input ->getOption ('output-format ' )) {
130+ if (!$ input ->getOption ('output-format ' )) {
134131 return ;
135132 }
136133
137134 // Handle printing the output
138- if ($ input ->getOption ('output ' ) === self :: OUTPUT_STDOUT ) {
135+ if (self :: OUTPUT_STDOUT === $ input ->getOption ('output ' )) {
139136 if ($ output ->isVeryVerbose ()) {
140- if (class_exists (VarDumper::class) && ($ input ->getOption (
137+ if (class_exists (VarDumper::class) && (self :: OUTPUT_FORMAT_DUMP === $ input ->getOption (
141138 'output-format '
142- ) === self :: OUTPUT_FORMAT_DUMP )) {
139+ ))) {
143140 VarDumper::dump ($ data );
144- } elseif ($ input ->getOption ('output-format ' ) === self :: OUTPUT_FORMAT_JSON ) {
145- $ output ->writeln (json_encode ($ data , JSON_THROW_ON_ERROR ));
141+ } elseif (self :: OUTPUT_FORMAT_JSON === $ input ->getOption ('output-format ' )) {
142+ $ output ->writeln (json_encode ($ data , \ JSON_THROW_ON_ERROR ));
146143 } else {
147- throw new InvalidArgumentException (
144+ throw new \ InvalidArgumentException (
148145 sprintf ("Cannot handle data output with format '%s' " , $ input ->getOption ('output-format ' ))
149146 );
150147 }
151148 }
152- } elseif ($ input ->getOption ('output-format ' ) === self :: OUTPUT_FORMAT_JSON ) {
149+ } elseif (self :: OUTPUT_FORMAT_JSON === $ input ->getOption ('output-format ' )) {
153150 // JsonStreamFile::writeLine only takes an array...
154151 // TODO how to handle other cases ?
155- if (is_array ($ data )) {
152+ if (\ is_array ($ data )) {
156153 $ outputFile = new JsonStreamFile ($ input ->getOption ('output ' ), 'wb ' );
157154 $ outputFile ->writeLine ($ data );
158155 }
@@ -161,7 +158,7 @@ protected function handleOutputData(mixed $data, InputInterface $input, OutputIn
161158 $ output ->writeln (sprintf ("Output stored in '%s' " , $ input ->getOption ('output ' )));
162159 }
163160 } else {
164- throw new InvalidArgumentException (
161+ throw new \ InvalidArgumentException (
165162 sprintf ("Cannot handle data output with format '%s' " , $ input ->getOption ('output-format ' ))
166163 );
167164 }
0 commit comments