@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | private $aliases; |
45 | 45 | |
46 | - public function __construct(Application $application, string $namespace = null, bool $showHidden = false) |
|
46 | + public function __construct( Application $application, string $namespace = null, bool $showHidden = false ) |
|
47 | 47 | { |
48 | 48 | $this->application = $application; |
49 | 49 | $this->namespace = $namespace; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | public function getNamespaces(): array |
54 | 54 | { |
55 | - if (null === $this->namespaces) { |
|
55 | + if ( null === $this->namespaces ) { |
|
56 | 56 | $this->inspectApplication(); |
57 | 57 | } |
58 | 58 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function getCommands(): array |
66 | 66 | { |
67 | - if (null === $this->commands) { |
|
67 | + if ( null === $this->commands ) { |
|
68 | 68 | $this->inspectApplication(); |
69 | 69 | } |
70 | 70 | |
@@ -74,67 +74,67 @@ discard block |
||
74 | 74 | /** |
75 | 75 | * @throws CommandNotFoundException |
76 | 76 | */ |
77 | - public function getCommand(string $name): Command |
|
77 | + public function getCommand( string $name ): Command |
|
78 | 78 | { |
79 | - if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) { |
|
80 | - throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); |
|
79 | + if ( ! isset( $this->commands[ $name ] ) && ! isset( $this->aliases[ $name ] ) ) { |
|
80 | + throw new CommandNotFoundException( sprintf( 'Command "%s" does not exist.', $name ) ); |
|
81 | 81 | } |
82 | 82 | |
83 | - return $this->commands[$name] ?? $this->aliases[$name]; |
|
83 | + return $this->commands[ $name ] ?? $this->aliases[ $name ]; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | private function inspectApplication() |
87 | 87 | { |
88 | - $this->commands = []; |
|
89 | - $this->namespaces = []; |
|
88 | + $this->commands = [ ]; |
|
89 | + $this->namespaces = [ ]; |
|
90 | 90 | |
91 | - $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null); |
|
92 | - foreach ($this->sortCommands($all) as $namespace => $commands) { |
|
93 | - $names = []; |
|
91 | + $all = $this->application->all( $this->namespace ? $this->application->findNamespace( $this->namespace ) : null ); |
|
92 | + foreach ( $this->sortCommands( $all ) as $namespace => $commands ) { |
|
93 | + $names = [ ]; |
|
94 | 94 | |
95 | 95 | /** @var Command $command */ |
96 | - foreach ($commands as $name => $command) { |
|
97 | - if (!$command->getName() || (!$this->showHidden && $command->isHidden())) { |
|
96 | + foreach ( $commands as $name => $command ) { |
|
97 | + if ( ! $command->getName() || ( ! $this->showHidden && $command->isHidden() ) ) { |
|
98 | 98 | continue; |
99 | 99 | } |
100 | 100 | |
101 | - if ($command->getName() === $name) { |
|
102 | - $this->commands[$name] = $command; |
|
101 | + if ( $command->getName() === $name ) { |
|
102 | + $this->commands[ $name ] = $command; |
|
103 | 103 | } else { |
104 | - $this->aliases[$name] = $command; |
|
104 | + $this->aliases[ $name ] = $command; |
|
105 | 105 | } |
106 | 106 | |
107 | - $names[] = $name; |
|
107 | + $names[ ] = $name; |
|
108 | 108 | } |
109 | 109 | |
110 | - $this->namespaces[$namespace] = ['id' => $namespace, 'commands' => $names]; |
|
110 | + $this->namespaces[ $namespace ] = [ 'id' => $namespace, 'commands' => $names ]; |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
114 | - private function sortCommands(array $commands): array |
|
114 | + private function sortCommands( array $commands ): array |
|
115 | 115 | { |
116 | - $namespacedCommands = []; |
|
117 | - $globalCommands = []; |
|
118 | - $sortedCommands = []; |
|
119 | - foreach ($commands as $name => $command) { |
|
120 | - $key = $this->application->extractNamespace($name, 1); |
|
121 | - if (\in_array($key, ['', self::GLOBAL_NAMESPACE], true)) { |
|
122 | - $globalCommands[$name] = $command; |
|
116 | + $namespacedCommands = [ ]; |
|
117 | + $globalCommands = [ ]; |
|
118 | + $sortedCommands = [ ]; |
|
119 | + foreach ( $commands as $name => $command ) { |
|
120 | + $key = $this->application->extractNamespace( $name, 1 ); |
|
121 | + if ( \in_array( $key, [ '', self::GLOBAL_NAMESPACE ], true ) ) { |
|
122 | + $globalCommands[ $name ] = $command; |
|
123 | 123 | } else { |
124 | - $namespacedCommands[$key][$name] = $command; |
|
124 | + $namespacedCommands[ $key ][ $name ] = $command; |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | - if ($globalCommands) { |
|
129 | - ksort($globalCommands); |
|
130 | - $sortedCommands[self::GLOBAL_NAMESPACE] = $globalCommands; |
|
128 | + if ( $globalCommands ) { |
|
129 | + ksort( $globalCommands ); |
|
130 | + $sortedCommands[ self::GLOBAL_NAMESPACE ] = $globalCommands; |
|
131 | 131 | } |
132 | 132 | |
133 | - if ($namespacedCommands) { |
|
134 | - ksort($namespacedCommands); |
|
135 | - foreach ($namespacedCommands as $key => $commandsSet) { |
|
136 | - ksort($commandsSet); |
|
137 | - $sortedCommands[$key] = $commandsSet; |
|
133 | + if ( $namespacedCommands ) { |
|
134 | + ksort( $namespacedCommands ); |
|
135 | + foreach ( $namespacedCommands as $key => $commandsSet ) { |
|
136 | + ksort( $commandsSet ); |
|
137 | + $sortedCommands[ $key ] = $commandsSet; |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | ',' => '%2C', |
43 | 43 | ]; |
44 | 44 | |
45 | - public function __construct(OutputInterface $output) |
|
45 | + public function __construct( OutputInterface $output ) |
|
46 | 46 | { |
47 | 47 | $this->output = $output; |
48 | 48 | } |
49 | 49 | |
50 | 50 | public static function isGithubActionEnvironment(): bool |
51 | 51 | { |
52 | - return false !== getenv('GITHUB_ACTIONS'); |
|
52 | + return false !== getenv( 'GITHUB_ACTIONS' ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-error-message |
59 | 59 | */ |
60 | - public function error(string $message, string $file = null, int $line = null, int $col = null): void |
|
60 | + public function error( string $message, string $file = null, int $line = null, int $col = null ): void |
|
61 | 61 | { |
62 | - $this->log('error', $message, $file, $line, $col); |
|
62 | + $this->log( 'error', $message, $file, $line, $col ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message |
69 | 69 | */ |
70 | - public function warning(string $message, string $file = null, int $line = null, int $col = null): void |
|
70 | + public function warning( string $message, string $file = null, int $line = null, int $col = null ): void |
|
71 | 71 | { |
72 | - $this->log('warning', $message, $file, $line, $col); |
|
72 | + $this->log( 'warning', $message, $file, $line, $col ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -77,23 +77,23 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-debug-message |
79 | 79 | */ |
80 | - public function debug(string $message, string $file = null, int $line = null, int $col = null): void |
|
80 | + public function debug( string $message, string $file = null, int $line = null, int $col = null ): void |
|
81 | 81 | { |
82 | - $this->log('debug', $message, $file, $line, $col); |
|
82 | + $this->log( 'debug', $message, $file, $line, $col ); |
|
83 | 83 | } |
84 | 84 | |
85 | - private function log(string $type, string $message, string $file = null, int $line = null, int $col = null): void |
|
85 | + private function log( string $type, string $message, string $file = null, int $line = null, int $col = null ): void |
|
86 | 86 | { |
87 | 87 | // Some values must be encoded. |
88 | - $message = strtr($message, self::ESCAPED_DATA); |
|
88 | + $message = strtr( $message, self::ESCAPED_DATA ); |
|
89 | 89 | |
90 | - if (!$file) { |
|
90 | + if ( ! $file ) { |
|
91 | 91 | // No file provided, output the message solely: |
92 | - $this->output->writeln(sprintf('::%s::%s', $type, $message)); |
|
92 | + $this->output->writeln( sprintf( '::%s::%s', $type, $message ) ); |
|
93 | 93 | |
94 | 94 | return; |
95 | 95 | } |
96 | 96 | |
97 | - $this->output->writeln(sprintf('::%s file=%s,line=%s,col=%s::%s', $type, strtr($file, self::ESCAPED_PROPERTIES), strtr($line ?? 1, self::ESCAPED_PROPERTIES), strtr($col ?? 0, self::ESCAPED_PROPERTIES), $message)); |
|
97 | + $this->output->writeln( sprintf( '::%s file=%s,line=%s,col=%s::%s', $type, strtr( $file, self::ESCAPED_PROPERTIES ), strtr( $line ?? 1, self::ESCAPED_PROPERTIES ), strtr( $col ?? 0, self::ESCAPED_PROPERTIES ), $message ) ); |
|
98 | 98 | } |
99 | 99 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | ]; |
53 | 53 | private $errored = false; |
54 | 54 | |
55 | - public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = []) |
|
55 | + public function __construct( OutputInterface $output, array $verbosityLevelMap = [ ], array $formatLevelMap = [ ] ) |
|
56 | 56 | { |
57 | 57 | $this->output = $output; |
58 | 58 | $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap; |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return void |
66 | 66 | */ |
67 | - public function log($level, $message, array $context = []) |
|
67 | + public function log( $level, $message, array $context = [ ] ) |
|
68 | 68 | { |
69 | - if (!isset($this->verbosityLevelMap[$level])) { |
|
70 | - throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); |
|
69 | + if ( ! isset( $this->verbosityLevelMap[ $level ] ) ) { |
|
70 | + throw new InvalidArgumentException( sprintf( 'The log level "%s" does not exist.', $level ) ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | $output = $this->output; |
74 | 74 | |
75 | 75 | // Write to the error output if necessary and available |
76 | - if (self::ERROR === $this->formatLevelMap[$level]) { |
|
77 | - if ($this->output instanceof ConsoleOutputInterface) { |
|
76 | + if ( self::ERROR === $this->formatLevelMap[ $level ] ) { |
|
77 | + if ( $this->output instanceof ConsoleOutputInterface ) { |
|
78 | 78 | $output = $output->getErrorOutput(); |
79 | 79 | } |
80 | 80 | $this->errored = true; |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | |
83 | 83 | // the if condition check isn't necessary -- it's the same one that $output will do internally anyway. |
84 | 84 | // We only do it for efficiency here as the message formatting is relatively expensive. |
85 | - if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) { |
|
86 | - $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)), $this->verbosityLevelMap[$level]); |
|
85 | + if ( $output->getVerbosity() >= $this->verbosityLevelMap[ $level ] ) { |
|
86 | + $output->writeln( sprintf( '<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[ $level ], $level, $this->interpolate( $message, $context ) ), $this->verbosityLevelMap[ $level ] ); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
@@ -102,25 +102,25 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @author PHP Framework Interoperability Group |
104 | 104 | */ |
105 | - private function interpolate(string $message, array $context): string |
|
105 | + private function interpolate( string $message, array $context ): string |
|
106 | 106 | { |
107 | - if (!str_contains($message, '{')) { |
|
107 | + if ( ! str_contains( $message, '{' ) ) { |
|
108 | 108 | return $message; |
109 | 109 | } |
110 | 110 | |
111 | - $replacements = []; |
|
112 | - foreach ($context as $key => $val) { |
|
113 | - if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) { |
|
114 | - $replacements["{{$key}}"] = $val; |
|
115 | - } elseif ($val instanceof \DateTimeInterface) { |
|
116 | - $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339); |
|
117 | - } elseif (\is_object($val)) { |
|
118 | - $replacements["{{$key}}"] = '[object '.\get_class($val).']'; |
|
111 | + $replacements = [ ]; |
|
112 | + foreach ( $context as $key => $val ) { |
|
113 | + if ( null === $val || is_scalar( $val ) || ( \is_object( $val ) && method_exists( $val, '__toString' ) ) ) { |
|
114 | + $replacements[ "{{$key}}" ] = $val; |
|
115 | + } elseif ( $val instanceof \DateTimeInterface ) { |
|
116 | + $replacements[ "{{$key}}" ] = $val->format( \DateTime::RFC3339 ); |
|
117 | + } elseif ( \is_object( $val ) ) { |
|
118 | + $replacements[ "{{$key}}" ] = '[object ' . \get_class( $val ) . ']'; |
|
119 | 119 | } else { |
120 | - $replacements["{{$key}}"] = '['.\gettype($val).']'; |
|
120 | + $replacements[ "{{$key}}" ] = '[' . \gettype( $val ) . ']'; |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - return strtr($message, $replacements); |
|
124 | + return strtr( $message, $replacements ); |
|
125 | 125 | } |
126 | 126 | } |
@@ -26,68 +26,68 @@ |
||
26 | 26 | { |
27 | 27 | private $logger; |
28 | 28 | |
29 | - public function __construct(LoggerInterface $logger = null) |
|
29 | + public function __construct( LoggerInterface $logger = null ) |
|
30 | 30 | { |
31 | 31 | $this->logger = $logger; |
32 | 32 | } |
33 | 33 | |
34 | - public function onConsoleError(ConsoleErrorEvent $event) |
|
34 | + public function onConsoleError( ConsoleErrorEvent $event ) |
|
35 | 35 | { |
36 | - if (null === $this->logger) { |
|
36 | + if ( null === $this->logger ) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | 39 | |
40 | 40 | $error = $event->getError(); |
41 | 41 | |
42 | - if (!$inputString = $this->getInputString($event)) { |
|
43 | - $this->logger->critical('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]); |
|
42 | + if ( ! $inputString = $this->getInputString( $event ) ) { |
|
43 | + $this->logger->critical( 'An error occurred while using the console. Message: "{message}"', [ 'exception' => $error, 'message' => $error->getMessage() ] ); |
|
44 | 44 | |
45 | 45 | return; |
46 | 46 | } |
47 | 47 | |
48 | - $this->logger->critical('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]); |
|
48 | + $this->logger->critical( 'Error thrown while running command "{command}". Message: "{message}"', [ 'exception' => $error, 'command' => $inputString, 'message' => $error->getMessage() ] ); |
|
49 | 49 | } |
50 | 50 | |
51 | - public function onConsoleTerminate(ConsoleTerminateEvent $event) |
|
51 | + public function onConsoleTerminate( ConsoleTerminateEvent $event ) |
|
52 | 52 | { |
53 | - if (null === $this->logger) { |
|
53 | + if ( null === $this->logger ) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $exitCode = $event->getExitCode(); |
58 | 58 | |
59 | - if (0 === $exitCode) { |
|
59 | + if ( 0 === $exitCode ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | - if (!$inputString = $this->getInputString($event)) { |
|
64 | - $this->logger->debug('The console exited with code "{code}"', ['code' => $exitCode]); |
|
63 | + if ( ! $inputString = $this->getInputString( $event ) ) { |
|
64 | + $this->logger->debug( 'The console exited with code "{code}"', [ 'code' => $exitCode ] ); |
|
65 | 65 | |
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | - $this->logger->debug('Command "{command}" exited with code "{code}"', ['command' => $inputString, 'code' => $exitCode]); |
|
69 | + $this->logger->debug( 'Command "{command}" exited with code "{code}"', [ 'command' => $inputString, 'code' => $exitCode ] ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | public static function getSubscribedEvents() |
73 | 73 | { |
74 | 74 | return [ |
75 | - ConsoleEvents::ERROR => ['onConsoleError', -128], |
|
76 | - ConsoleEvents::TERMINATE => ['onConsoleTerminate', -128], |
|
75 | + ConsoleEvents::ERROR => [ 'onConsoleError', -128 ], |
|
76 | + ConsoleEvents::TERMINATE => [ 'onConsoleTerminate', -128 ], |
|
77 | 77 | ]; |
78 | 78 | } |
79 | 79 | |
80 | - private static function getInputString(ConsoleEvent $event): ?string |
|
80 | + private static function getInputString( ConsoleEvent $event ): ?string |
|
81 | 81 | { |
82 | 82 | $commandName = $event->getCommand() ? $event->getCommand()->getName() : null; |
83 | 83 | $input = $event->getInput(); |
84 | 84 | |
85 | - if (method_exists($input, '__toString')) { |
|
86 | - if ($commandName) { |
|
87 | - return str_replace(["'$commandName'", "\"$commandName\""], $commandName, (string) $input); |
|
85 | + if ( method_exists( $input, '__toString' ) ) { |
|
86 | + if ( $commandName ) { |
|
87 | + return str_replace( [ "'$commandName'", "\"$commandName\"" ], $commandName, (string)$input ); |
|
88 | 88 | } |
89 | 89 | |
90 | - return (string) $input; |
|
90 | + return (string)$input; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return $commandName; |
@@ -30,17 +30,17 @@ discard block |
||
30 | 30 | * @param array $choices The list of available choices |
31 | 31 | * @param mixed $default The default answer to return |
32 | 32 | */ |
33 | - public function __construct(string $question, array $choices, $default = null) |
|
33 | + public function __construct( string $question, array $choices, $default = null ) |
|
34 | 34 | { |
35 | - if (!$choices) { |
|
36 | - throw new \LogicException('Choice question must have at least 1 choice available.'); |
|
35 | + if ( ! $choices ) { |
|
36 | + throw new \LogicException( 'Choice question must have at least 1 choice available.' ); |
|
37 | 37 | } |
38 | 38 | |
39 | - parent::__construct($question, $default); |
|
39 | + parent::__construct( $question, $default ); |
|
40 | 40 | |
41 | 41 | $this->choices = $choices; |
42 | - $this->setValidator($this->getDefaultValidator()); |
|
43 | - $this->setAutocompleterValues($choices); |
|
42 | + $this->setValidator( $this->getDefaultValidator() ); |
|
43 | + $this->setAutocompleterValues( $choices ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return $this |
62 | 62 | */ |
63 | - public function setMultiselect(bool $multiselect) |
|
63 | + public function setMultiselect( bool $multiselect ) |
|
64 | 64 | { |
65 | 65 | $this->multiselect = $multiselect; |
66 | - $this->setValidator($this->getDefaultValidator()); |
|
66 | + $this->setValidator( $this->getDefaultValidator() ); |
|
67 | 67 | |
68 | 68 | return $this; |
69 | 69 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return $this |
95 | 95 | */ |
96 | - public function setPrompt(string $prompt) |
|
96 | + public function setPrompt( string $prompt ) |
|
97 | 97 | { |
98 | 98 | $this->prompt = $prompt; |
99 | 99 | |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return $this |
109 | 109 | */ |
110 | - public function setErrorMessage(string $errorMessage) |
|
110 | + public function setErrorMessage( string $errorMessage ) |
|
111 | 111 | { |
112 | 112 | $this->errorMessage = $errorMessage; |
113 | - $this->setValidator($this->getDefaultValidator()); |
|
113 | + $this->setValidator( $this->getDefaultValidator() ); |
|
114 | 114 | |
115 | 115 | return $this; |
116 | 116 | } |
@@ -120,64 +120,64 @@ discard block |
||
120 | 120 | $choices = $this->choices; |
121 | 121 | $errorMessage = $this->errorMessage; |
122 | 122 | $multiselect = $this->multiselect; |
123 | - $isAssoc = $this->isAssoc($choices); |
|
123 | + $isAssoc = $this->isAssoc( $choices ); |
|
124 | 124 | |
125 | - return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) { |
|
126 | - if ($multiselect) { |
|
125 | + return function( $selected ) use ( $choices, $errorMessage, $multiselect, $isAssoc ) { |
|
126 | + if ( $multiselect ) { |
|
127 | 127 | // Check for a separated comma values |
128 | - if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selected, $matches)) { |
|
129 | - throw new InvalidArgumentException(sprintf($errorMessage, $selected)); |
|
128 | + if ( ! preg_match( '/^[^,]+(?:,[^,]+)*$/', $selected, $matches ) ) { |
|
129 | + throw new InvalidArgumentException( sprintf( $errorMessage, $selected ) ); |
|
130 | 130 | } |
131 | 131 | |
132 | - $selectedChoices = explode(',', $selected); |
|
132 | + $selectedChoices = explode( ',', $selected ); |
|
133 | 133 | } else { |
134 | - $selectedChoices = [$selected]; |
|
134 | + $selectedChoices = [ $selected ]; |
|
135 | 135 | } |
136 | 136 | |
137 | - if ($this->isTrimmable()) { |
|
138 | - foreach ($selectedChoices as $k => $v) { |
|
139 | - $selectedChoices[$k] = trim($v); |
|
137 | + if ( $this->isTrimmable() ) { |
|
138 | + foreach ( $selectedChoices as $k => $v ) { |
|
139 | + $selectedChoices[ $k ] = trim( $v ); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - $multiselectChoices = []; |
|
144 | - foreach ($selectedChoices as $value) { |
|
145 | - $results = []; |
|
146 | - foreach ($choices as $key => $choice) { |
|
147 | - if ($choice === $value) { |
|
148 | - $results[] = $key; |
|
143 | + $multiselectChoices = [ ]; |
|
144 | + foreach ( $selectedChoices as $value ) { |
|
145 | + $results = [ ]; |
|
146 | + foreach ( $choices as $key => $choice ) { |
|
147 | + if ( $choice === $value ) { |
|
148 | + $results[ ] = $key; |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | - if (\count($results) > 1) { |
|
153 | - throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of "%s".', implode('" or "', $results))); |
|
152 | + if ( \count( $results ) > 1 ) { |
|
153 | + throw new InvalidArgumentException( sprintf( 'The provided answer is ambiguous. Value should be one of "%s".', implode( '" or "', $results ) ) ); |
|
154 | 154 | } |
155 | 155 | |
156 | - $result = array_search($value, $choices); |
|
156 | + $result = array_search( $value, $choices ); |
|
157 | 157 | |
158 | - if (!$isAssoc) { |
|
159 | - if (false !== $result) { |
|
160 | - $result = $choices[$result]; |
|
161 | - } elseif (isset($choices[$value])) { |
|
162 | - $result = $choices[$value]; |
|
158 | + if ( ! $isAssoc ) { |
|
159 | + if ( false !== $result ) { |
|
160 | + $result = $choices[ $result ]; |
|
161 | + } elseif ( isset( $choices[ $value ] ) ) { |
|
162 | + $result = $choices[ $value ]; |
|
163 | 163 | } |
164 | - } elseif (false === $result && isset($choices[$value])) { |
|
164 | + } elseif ( false === $result && isset( $choices[ $value ] ) ) { |
|
165 | 165 | $result = $value; |
166 | 166 | } |
167 | 167 | |
168 | - if (false === $result) { |
|
169 | - throw new InvalidArgumentException(sprintf($errorMessage, $value)); |
|
168 | + if ( false === $result ) { |
|
169 | + throw new InvalidArgumentException( sprintf( $errorMessage, $value ) ); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // For associative choices, consistently return the key as string: |
173 | - $multiselectChoices[] = $isAssoc ? (string) $result : $result; |
|
173 | + $multiselectChoices[ ] = $isAssoc ? (string)$result : $result; |
|
174 | 174 | } |
175 | 175 | |
176 | - if ($multiselect) { |
|
176 | + if ( $multiselect ) { |
|
177 | 177 | return $multiselectChoices; |
178 | 178 | } |
179 | 179 | |
180 | - return current($multiselectChoices); |
|
180 | + return current( $multiselectChoices ); |
|
181 | 181 | }; |
182 | 182 | } |
183 | 183 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param string $question The question to ask to the user |
37 | 37 | * @param string|bool|int|float|null $default The default answer to return if the user enters nothing |
38 | 38 | */ |
39 | - public function __construct(string $question, $default = null) |
|
39 | + public function __construct( string $question, $default = null ) |
|
40 | 40 | { |
41 | 41 | $this->question = $question; |
42 | 42 | $this->default = $default; |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return $this |
77 | 77 | */ |
78 | - public function setMultiline(bool $multiline): self |
|
78 | + public function setMultiline( bool $multiline ): self |
|
79 | 79 | { |
80 | 80 | $this->multiline = $multiline; |
81 | 81 | |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @throws LogicException In case the autocompleter is also used |
101 | 101 | */ |
102 | - public function setHidden(bool $hidden) |
|
102 | + public function setHidden( bool $hidden ) |
|
103 | 103 | { |
104 | - if ($this->autocompleterCallback) { |
|
105 | - throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
104 | + if ( $this->autocompleterCallback ) { |
|
105 | + throw new LogicException( 'A hidden question cannot use the autocompleter.' ); |
|
106 | 106 | } |
107 | 107 | |
108 | - $this->hidden = (bool) $hidden; |
|
108 | + $this->hidden = (bool)$hidden; |
|
109 | 109 | |
110 | 110 | return $this; |
111 | 111 | } |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return $this |
127 | 127 | */ |
128 | - public function setHiddenFallback(bool $fallback) |
|
128 | + public function setHiddenFallback( bool $fallback ) |
|
129 | 129 | { |
130 | - $this->hiddenFallback = (bool) $fallback; |
|
130 | + $this->hiddenFallback = (bool)$fallback; |
|
131 | 131 | |
132 | 132 | return $this; |
133 | 133 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | { |
142 | 142 | $callback = $this->getAutocompleterCallback(); |
143 | 143 | |
144 | - return $callback ? $callback('') : null; |
|
144 | + return $callback ? $callback( '' ) : null; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -151,24 +151,24 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @throws LogicException |
153 | 153 | */ |
154 | - public function setAutocompleterValues(?iterable $values) |
|
154 | + public function setAutocompleterValues( ?iterable $values ) |
|
155 | 155 | { |
156 | - if (\is_array($values)) { |
|
157 | - $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values); |
|
156 | + if ( \is_array( $values ) ) { |
|
157 | + $values = $this->isAssoc( $values ) ? array_merge( array_keys( $values ), array_values( $values ) ) : array_values( $values ); |
|
158 | 158 | |
159 | - $callback = static function () use ($values) { |
|
159 | + $callback = static function() use ( $values ) { |
|
160 | 160 | return $values; |
161 | 161 | }; |
162 | - } elseif ($values instanceof \Traversable) { |
|
162 | + } elseif ( $values instanceof \Traversable ) { |
|
163 | 163 | $valueCache = null; |
164 | - $callback = static function () use ($values, &$valueCache) { |
|
165 | - return $valueCache ?? $valueCache = iterator_to_array($values, false); |
|
164 | + $callback = static function() use ( $values, &$valueCache ) { |
|
165 | + return $valueCache ?? $valueCache = iterator_to_array( $values, false ); |
|
166 | 166 | }; |
167 | 167 | } else { |
168 | 168 | $callback = null; |
169 | 169 | } |
170 | 170 | |
171 | - return $this->setAutocompleterCallback($callback); |
|
171 | + return $this->setAutocompleterCallback( $callback ); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -186,10 +186,10 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @return $this |
188 | 188 | */ |
189 | - public function setAutocompleterCallback(callable $callback = null): self |
|
189 | + public function setAutocompleterCallback( callable $callback = null ): self |
|
190 | 190 | { |
191 | - if ($this->hidden && null !== $callback) { |
|
192 | - throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
191 | + if ( $this->hidden && null !== $callback ) { |
|
192 | + throw new LogicException( 'A hidden question cannot use the autocompleter.' ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | $this->autocompleterCallback = $callback; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @return $this |
204 | 204 | */ |
205 | - public function setValidator(callable $validator = null) |
|
205 | + public function setValidator( callable $validator = null ) |
|
206 | 206 | { |
207 | 207 | $this->validator = $validator; |
208 | 208 | |
@@ -228,12 +228,12 @@ discard block |
||
228 | 228 | * |
229 | 229 | * @throws InvalidArgumentException in case the number of attempts is invalid |
230 | 230 | */ |
231 | - public function setMaxAttempts(?int $attempts) |
|
231 | + public function setMaxAttempts( ?int $attempts ) |
|
232 | 232 | { |
233 | - if (null !== $attempts) { |
|
234 | - $attempts = (int) $attempts; |
|
235 | - if ($attempts < 1) { |
|
236 | - throw new InvalidArgumentException('Maximum number of attempts must be a positive value.'); |
|
233 | + if ( null !== $attempts ) { |
|
234 | + $attempts = (int)$attempts; |
|
235 | + if ( $attempts < 1 ) { |
|
236 | + throw new InvalidArgumentException( 'Maximum number of attempts must be a positive value.' ); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @return $this |
263 | 263 | */ |
264 | - public function setNormalizer(callable $normalizer) |
|
264 | + public function setNormalizer( callable $normalizer ) |
|
265 | 265 | { |
266 | 266 | $this->normalizer = $normalizer; |
267 | 267 | |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | return $this->normalizer; |
281 | 281 | } |
282 | 282 | |
283 | - protected function isAssoc(array $array) |
|
283 | + protected function isAssoc( array $array ) |
|
284 | 284 | { |
285 | - return (bool) \count(array_filter(array_keys($array), 'is_string')); |
|
285 | + return (bool)\count( array_filter( array_keys( $array ), 'is_string' ) ); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | public function isTrimmable(): bool |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | /** |
294 | 294 | * @return $this |
295 | 295 | */ |
296 | - public function setTrimmable(bool $trimmable): self |
|
296 | + public function setTrimmable( bool $trimmable ): self |
|
297 | 297 | { |
298 | 298 | $this->trimmable = $trimmable; |
299 | 299 |
@@ -25,12 +25,12 @@ discard block |
||
25 | 25 | * @param bool $default The default answer to return, true or false |
26 | 26 | * @param string $trueAnswerRegex A regex to match the "yes" answer |
27 | 27 | */ |
28 | - public function __construct(string $question, bool $default = true, string $trueAnswerRegex = '/^y/i') |
|
28 | + public function __construct( string $question, bool $default = true, string $trueAnswerRegex = '/^y/i' ) |
|
29 | 29 | { |
30 | - parent::__construct($question, $default); |
|
30 | + parent::__construct( $question, $default ); |
|
31 | 31 | |
32 | 32 | $this->trueAnswerRegex = $trueAnswerRegex; |
33 | - $this->setNormalizer($this->getDefaultNormalizer()); |
|
33 | + $this->setNormalizer( $this->getDefaultNormalizer() ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | $default = $this->getDefault(); |
42 | 42 | $regex = $this->trueAnswerRegex; |
43 | 43 | |
44 | - return function ($answer) use ($default, $regex) { |
|
45 | - if (\is_bool($answer)) { |
|
44 | + return function( $answer ) use ( $default, $regex ) { |
|
45 | + if ( \is_bool( $answer ) ) { |
|
46 | 46 | return $answer; |
47 | 47 | } |
48 | 48 | |
49 | - $answerIsTrue = (bool) preg_match($regex, $answer); |
|
50 | - if (false === $default) { |
|
49 | + $answerIsTrue = (bool)preg_match( $regex, $answer ); |
|
50 | + if ( false === $default ) { |
|
51 | 51 | return $answer && $answerIsTrue; |
52 | 52 | } |
53 | 53 |
@@ -43,15 +43,15 @@ discard block |
||
43 | 43 | private $lineLength; |
44 | 44 | private $bufferedOutput; |
45 | 45 | |
46 | - public function __construct(InputInterface $input, OutputInterface $output) |
|
46 | + public function __construct( InputInterface $input, OutputInterface $output ) |
|
47 | 47 | { |
48 | 48 | $this->input = $input; |
49 | - $this->bufferedOutput = new TrimmedBufferOutput(\DIRECTORY_SEPARATOR === '\\' ? 4 : 2, $output->getVerbosity(), false, clone $output->getFormatter()); |
|
49 | + $this->bufferedOutput = new TrimmedBufferOutput( \DIRECTORY_SEPARATOR === '\\' ? 4 : 2, $output->getVerbosity(), false, clone $output->getFormatter() ); |
|
50 | 50 | // Windows cmd wraps lines as soon as the terminal width is reached, whether there are following chars or not. |
51 | - $width = (new Terminal())->getWidth() ?: self::MAX_LINE_LENGTH; |
|
52 | - $this->lineLength = min($width - (int) (\DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH); |
|
51 | + $width = ( new Terminal() )->getWidth() ?: self::MAX_LINE_LENGTH; |
|
52 | + $this->lineLength = min( $width - (int)( \DIRECTORY_SEPARATOR === '\\' ), self::MAX_LINE_LENGTH ); |
|
53 | 53 | |
54 | - parent::__construct($output); |
|
54 | + parent::__construct( $output ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -59,65 +59,65 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @param string|array $messages The message to write in the block |
61 | 61 | */ |
62 | - public function block($messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true) |
|
62 | + public function block( $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true ) |
|
63 | 63 | { |
64 | - $messages = \is_array($messages) ? array_values($messages) : [$messages]; |
|
64 | + $messages = \is_array( $messages ) ? array_values( $messages ) : [ $messages ]; |
|
65 | 65 | |
66 | 66 | $this->autoPrependBlock(); |
67 | - $this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape)); |
|
67 | + $this->writeln( $this->createBlock( $messages, $type, $style, $prefix, $padding, $escape ) ); |
|
68 | 68 | $this->newLine(); |
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
72 | 72 | * {@inheritdoc} |
73 | 73 | */ |
74 | - public function title(string $message) |
|
74 | + public function title( string $message ) |
|
75 | 75 | { |
76 | 76 | $this->autoPrependBlock(); |
77 | - $this->writeln([ |
|
78 | - sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)), |
|
79 | - sprintf('<comment>%s</>', str_repeat('=', Helper::width(Helper::removeDecoration($this->getFormatter(), $message)))), |
|
80 | - ]); |
|
77 | + $this->writeln( [ |
|
78 | + sprintf( '<comment>%s</>', OutputFormatter::escapeTrailingBackslash( $message ) ), |
|
79 | + sprintf( '<comment>%s</>', str_repeat( '=', Helper::width( Helper::removeDecoration( $this->getFormatter(), $message ) ) ) ), |
|
80 | + ] ); |
|
81 | 81 | $this->newLine(); |
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * {@inheritdoc} |
86 | 86 | */ |
87 | - public function section(string $message) |
|
87 | + public function section( string $message ) |
|
88 | 88 | { |
89 | 89 | $this->autoPrependBlock(); |
90 | - $this->writeln([ |
|
91 | - sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)), |
|
92 | - sprintf('<comment>%s</>', str_repeat('-', Helper::width(Helper::removeDecoration($this->getFormatter(), $message)))), |
|
93 | - ]); |
|
90 | + $this->writeln( [ |
|
91 | + sprintf( '<comment>%s</>', OutputFormatter::escapeTrailingBackslash( $message ) ), |
|
92 | + sprintf( '<comment>%s</>', str_repeat( '-', Helper::width( Helper::removeDecoration( $this->getFormatter(), $message ) ) ) ), |
|
93 | + ] ); |
|
94 | 94 | $this->newLine(); |
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | 98 | * {@inheritdoc} |
99 | 99 | */ |
100 | - public function listing(array $elements) |
|
100 | + public function listing( array $elements ) |
|
101 | 101 | { |
102 | 102 | $this->autoPrependText(); |
103 | - $elements = array_map(function ($element) { |
|
104 | - return sprintf(' * %s', $element); |
|
105 | - }, $elements); |
|
103 | + $elements = array_map( function( $element ) { |
|
104 | + return sprintf( ' * %s', $element ); |
|
105 | + }, $elements ); |
|
106 | 106 | |
107 | - $this->writeln($elements); |
|
107 | + $this->writeln( $elements ); |
|
108 | 108 | $this->newLine(); |
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
112 | 112 | * {@inheritdoc} |
113 | 113 | */ |
114 | - public function text($message) |
|
114 | + public function text( $message ) |
|
115 | 115 | { |
116 | 116 | $this->autoPrependText(); |
117 | 117 | |
118 | - $messages = \is_array($message) ? array_values($message) : [$message]; |
|
119 | - foreach ($messages as $message) { |
|
120 | - $this->writeln(sprintf(' %s', $message)); |
|
118 | + $messages = \is_array( $message ) ? array_values( $message ) : [ $message ]; |
|
119 | + foreach ( $messages as $message ) { |
|
120 | + $this->writeln( sprintf( ' %s', $message ) ); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
@@ -126,41 +126,41 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @param string|array $message |
128 | 128 | */ |
129 | - public function comment($message) |
|
129 | + public function comment( $message ) |
|
130 | 130 | { |
131 | - $this->block($message, null, null, '<fg=default;bg=default> // </>', false, false); |
|
131 | + $this->block( $message, null, null, '<fg=default;bg=default> // </>', false, false ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | 135 | * {@inheritdoc} |
136 | 136 | */ |
137 | - public function success($message) |
|
137 | + public function success( $message ) |
|
138 | 138 | { |
139 | - $this->block($message, 'OK', 'fg=black;bg=green', ' ', true); |
|
139 | + $this->block( $message, 'OK', 'fg=black;bg=green', ' ', true ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | 143 | * {@inheritdoc} |
144 | 144 | */ |
145 | - public function error($message) |
|
145 | + public function error( $message ) |
|
146 | 146 | { |
147 | - $this->block($message, 'ERROR', 'fg=white;bg=red', ' ', true); |
|
147 | + $this->block( $message, 'ERROR', 'fg=white;bg=red', ' ', true ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
151 | 151 | * {@inheritdoc} |
152 | 152 | */ |
153 | - public function warning($message) |
|
153 | + public function warning( $message ) |
|
154 | 154 | { |
155 | - $this->block($message, 'WARNING', 'fg=black;bg=yellow', ' ', true); |
|
155 | + $this->block( $message, 'WARNING', 'fg=black;bg=yellow', ' ', true ); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * {@inheritdoc} |
160 | 160 | */ |
161 | - public function note($message) |
|
161 | + public function note( $message ) |
|
162 | 162 | { |
163 | - $this->block($message, 'NOTE', 'fg=yellow', ' ! '); |
|
163 | + $this->block( $message, 'NOTE', 'fg=yellow', ' ! ' ); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -168,31 +168,31 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @param string|array $message |
170 | 170 | */ |
171 | - public function info($message) |
|
171 | + public function info( $message ) |
|
172 | 172 | { |
173 | - $this->block($message, 'INFO', 'fg=green', ' ', true); |
|
173 | + $this->block( $message, 'INFO', 'fg=green', ' ', true ); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | 177 | * {@inheritdoc} |
178 | 178 | */ |
179 | - public function caution($message) |
|
179 | + public function caution( $message ) |
|
180 | 180 | { |
181 | - $this->block($message, 'CAUTION', 'fg=white;bg=red', ' ! ', true); |
|
181 | + $this->block( $message, 'CAUTION', 'fg=white;bg=red', ' ! ', true ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | 185 | * {@inheritdoc} |
186 | 186 | */ |
187 | - public function table(array $headers, array $rows) |
|
187 | + public function table( array $headers, array $rows ) |
|
188 | 188 | { |
189 | - $style = clone Table::getStyleDefinition('symfony-style-guide'); |
|
190 | - $style->setCellHeaderFormat('<info>%s</info>'); |
|
189 | + $style = clone Table::getStyleDefinition( 'symfony-style-guide' ); |
|
190 | + $style->setCellHeaderFormat( '<info>%s</info>' ); |
|
191 | 191 | |
192 | - $table = new Table($this); |
|
193 | - $table->setHeaders($headers); |
|
194 | - $table->setRows($rows); |
|
195 | - $table->setStyle($style); |
|
192 | + $table = new Table( $this ); |
|
193 | + $table->setHeaders( $headers ); |
|
194 | + $table->setRows( $rows ); |
|
195 | + $table->setStyle( $style ); |
|
196 | 196 | |
197 | 197 | $table->render(); |
198 | 198 | $this->newLine(); |
@@ -201,16 +201,16 @@ discard block |
||
201 | 201 | /** |
202 | 202 | * Formats a horizontal table. |
203 | 203 | */ |
204 | - public function horizontalTable(array $headers, array $rows) |
|
204 | + public function horizontalTable( array $headers, array $rows ) |
|
205 | 205 | { |
206 | - $style = clone Table::getStyleDefinition('symfony-style-guide'); |
|
207 | - $style->setCellHeaderFormat('<info>%s</info>'); |
|
206 | + $style = clone Table::getStyleDefinition( 'symfony-style-guide' ); |
|
207 | + $style->setCellHeaderFormat( '<info>%s</info>' ); |
|
208 | 208 | |
209 | - $table = new Table($this); |
|
210 | - $table->setHeaders($headers); |
|
211 | - $table->setRows($rows); |
|
212 | - $table->setStyle($style); |
|
213 | - $table->setHorizontal(true); |
|
209 | + $table = new Table( $this ); |
|
210 | + $table->setHeaders( $headers ); |
|
211 | + $table->setRows( $rows ); |
|
212 | + $table->setStyle( $style ); |
|
213 | + $table->setHorizontal( true ); |
|
214 | 214 | |
215 | 215 | $table->render(); |
216 | 216 | $this->newLine(); |
@@ -226,36 +226,36 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @param string|array|TableSeparator ...$list |
228 | 228 | */ |
229 | - public function definitionList(...$list) |
|
230 | - { |
|
231 | - $style = clone Table::getStyleDefinition('symfony-style-guide'); |
|
232 | - $style->setCellHeaderFormat('<info>%s</info>'); |
|
233 | - |
|
234 | - $table = new Table($this); |
|
235 | - $headers = []; |
|
236 | - $row = []; |
|
237 | - foreach ($list as $value) { |
|
238 | - if ($value instanceof TableSeparator) { |
|
239 | - $headers[] = $value; |
|
240 | - $row[] = $value; |
|
229 | + public function definitionList( ...$list ) |
|
230 | + { |
|
231 | + $style = clone Table::getStyleDefinition( 'symfony-style-guide' ); |
|
232 | + $style->setCellHeaderFormat( '<info>%s</info>' ); |
|
233 | + |
|
234 | + $table = new Table( $this ); |
|
235 | + $headers = [ ]; |
|
236 | + $row = [ ]; |
|
237 | + foreach ( $list as $value ) { |
|
238 | + if ( $value instanceof TableSeparator ) { |
|
239 | + $headers[ ] = $value; |
|
240 | + $row[ ] = $value; |
|
241 | 241 | continue; |
242 | 242 | } |
243 | - if (\is_string($value)) { |
|
244 | - $headers[] = new TableCell($value, ['colspan' => 2]); |
|
245 | - $row[] = null; |
|
243 | + if ( \is_string( $value ) ) { |
|
244 | + $headers[ ] = new TableCell( $value, [ 'colspan' => 2 ] ); |
|
245 | + $row[ ] = null; |
|
246 | 246 | continue; |
247 | 247 | } |
248 | - if (!\is_array($value)) { |
|
249 | - throw new InvalidArgumentException('Value should be an array, string, or an instance of TableSeparator.'); |
|
248 | + if ( ! \is_array( $value ) ) { |
|
249 | + throw new InvalidArgumentException( 'Value should be an array, string, or an instance of TableSeparator.' ); |
|
250 | 250 | } |
251 | - $headers[] = key($value); |
|
252 | - $row[] = current($value); |
|
251 | + $headers[ ] = key( $value ); |
|
252 | + $row[ ] = current( $value ); |
|
253 | 253 | } |
254 | 254 | |
255 | - $table->setHeaders($headers); |
|
256 | - $table->setRows([$row]); |
|
255 | + $table->setHeaders( $headers ); |
|
256 | + $table->setRows( [ $row ] ); |
|
257 | 257 | $table->setHorizontal(); |
258 | - $table->setStyle($style); |
|
258 | + $table->setStyle( $style ); |
|
259 | 259 | |
260 | 260 | $table->render(); |
261 | 261 | $this->newLine(); |
@@ -264,63 +264,63 @@ discard block |
||
264 | 264 | /** |
265 | 265 | * {@inheritdoc} |
266 | 266 | */ |
267 | - public function ask(string $question, string $default = null, callable $validator = null) |
|
267 | + public function ask( string $question, string $default = null, callable $validator = null ) |
|
268 | 268 | { |
269 | - $question = new Question($question, $default); |
|
270 | - $question->setValidator($validator); |
|
269 | + $question = new Question( $question, $default ); |
|
270 | + $question->setValidator( $validator ); |
|
271 | 271 | |
272 | - return $this->askQuestion($question); |
|
272 | + return $this->askQuestion( $question ); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
276 | 276 | * {@inheritdoc} |
277 | 277 | */ |
278 | - public function askHidden(string $question, callable $validator = null) |
|
278 | + public function askHidden( string $question, callable $validator = null ) |
|
279 | 279 | { |
280 | - $question = new Question($question); |
|
280 | + $question = new Question( $question ); |
|
281 | 281 | |
282 | - $question->setHidden(true); |
|
283 | - $question->setValidator($validator); |
|
282 | + $question->setHidden( true ); |
|
283 | + $question->setValidator( $validator ); |
|
284 | 284 | |
285 | - return $this->askQuestion($question); |
|
285 | + return $this->askQuestion( $question ); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
289 | 289 | * {@inheritdoc} |
290 | 290 | */ |
291 | - public function confirm(string $question, bool $default = true) |
|
291 | + public function confirm( string $question, bool $default = true ) |
|
292 | 292 | { |
293 | - return $this->askQuestion(new ConfirmationQuestion($question, $default)); |
|
293 | + return $this->askQuestion( new ConfirmationQuestion( $question, $default ) ); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | 297 | * {@inheritdoc} |
298 | 298 | */ |
299 | - public function choice(string $question, array $choices, $default = null) |
|
299 | + public function choice( string $question, array $choices, $default = null ) |
|
300 | 300 | { |
301 | - if (null !== $default) { |
|
302 | - $values = array_flip($choices); |
|
303 | - $default = $values[$default] ?? $default; |
|
301 | + if ( null !== $default ) { |
|
302 | + $values = array_flip( $choices ); |
|
303 | + $default = $values[ $default ] ?? $default; |
|
304 | 304 | } |
305 | 305 | |
306 | - return $this->askQuestion(new ChoiceQuestion($question, $choices, $default)); |
|
306 | + return $this->askQuestion( new ChoiceQuestion( $question, $choices, $default ) ); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
310 | 310 | * {@inheritdoc} |
311 | 311 | */ |
312 | - public function progressStart(int $max = 0) |
|
312 | + public function progressStart( int $max = 0 ) |
|
313 | 313 | { |
314 | - $this->progressBar = $this->createProgressBar($max); |
|
314 | + $this->progressBar = $this->createProgressBar( $max ); |
|
315 | 315 | $this->progressBar->start(); |
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
319 | 319 | * {@inheritdoc} |
320 | 320 | */ |
321 | - public function progressAdvance(int $step = 1) |
|
321 | + public function progressAdvance( int $step = 1 ) |
|
322 | 322 | { |
323 | - $this->getProgressBar()->advance($step); |
|
323 | + $this->getProgressBar()->advance( $step ); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -329,21 +329,21 @@ discard block |
||
329 | 329 | public function progressFinish() |
330 | 330 | { |
331 | 331 | $this->getProgressBar()->finish(); |
332 | - $this->newLine(2); |
|
332 | + $this->newLine( 2 ); |
|
333 | 333 | $this->progressBar = null; |
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
337 | 337 | * {@inheritdoc} |
338 | 338 | */ |
339 | - public function createProgressBar(int $max = 0) |
|
339 | + public function createProgressBar( int $max = 0 ) |
|
340 | 340 | { |
341 | - $progressBar = parent::createProgressBar($max); |
|
341 | + $progressBar = parent::createProgressBar( $max ); |
|
342 | 342 | |
343 | - if ('\\' !== \DIRECTORY_SEPARATOR || 'Hyper' === getenv('TERM_PROGRAM')) { |
|
344 | - $progressBar->setEmptyBarCharacter('░'); // light shade character \u2591 |
|
345 | - $progressBar->setProgressCharacter(''); |
|
346 | - $progressBar->setBarCharacter('▓'); // dark shade character \u2593 |
|
343 | + if ( '\\' !== \DIRECTORY_SEPARATOR || 'Hyper' === getenv( 'TERM_PROGRAM' ) ) { |
|
344 | + $progressBar->setEmptyBarCharacter( '░' ); // light shade character \u2591 |
|
345 | + $progressBar->setProgressCharacter( '' ); |
|
346 | + $progressBar->setBarCharacter( '▓' ); // dark shade character \u2593 |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | return $progressBar; |
@@ -352,21 +352,21 @@ discard block |
||
352 | 352 | /** |
353 | 353 | * @return mixed |
354 | 354 | */ |
355 | - public function askQuestion(Question $question) |
|
355 | + public function askQuestion( Question $question ) |
|
356 | 356 | { |
357 | - if ($this->input->isInteractive()) { |
|
357 | + if ( $this->input->isInteractive() ) { |
|
358 | 358 | $this->autoPrependBlock(); |
359 | 359 | } |
360 | 360 | |
361 | - if (!$this->questionHelper) { |
|
361 | + if ( ! $this->questionHelper ) { |
|
362 | 362 | $this->questionHelper = new SymfonyQuestionHelper(); |
363 | 363 | } |
364 | 364 | |
365 | - $answer = $this->questionHelper->ask($this->input, $this, $question); |
|
365 | + $answer = $this->questionHelper->ask( $this->input, $this, $question ); |
|
366 | 366 | |
367 | - if ($this->input->isInteractive()) { |
|
367 | + if ( $this->input->isInteractive() ) { |
|
368 | 368 | $this->newLine(); |
369 | - $this->bufferedOutput->write("\n"); |
|
369 | + $this->bufferedOutput->write( "\n" ); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return $answer; |
@@ -375,40 +375,40 @@ discard block |
||
375 | 375 | /** |
376 | 376 | * {@inheritdoc} |
377 | 377 | */ |
378 | - public function writeln($messages, int $type = self::OUTPUT_NORMAL) |
|
378 | + public function writeln( $messages, int $type = self::OUTPUT_NORMAL ) |
|
379 | 379 | { |
380 | - if (!is_iterable($messages)) { |
|
381 | - $messages = [$messages]; |
|
380 | + if ( ! is_iterable( $messages ) ) { |
|
381 | + $messages = [ $messages ]; |
|
382 | 382 | } |
383 | 383 | |
384 | - foreach ($messages as $message) { |
|
385 | - parent::writeln($message, $type); |
|
386 | - $this->writeBuffer($message, true, $type); |
|
384 | + foreach ( $messages as $message ) { |
|
385 | + parent::writeln( $message, $type ); |
|
386 | + $this->writeBuffer( $message, true, $type ); |
|
387 | 387 | } |
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
391 | 391 | * {@inheritdoc} |
392 | 392 | */ |
393 | - public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) |
|
393 | + public function write( $messages, bool $newline = false, int $type = self::OUTPUT_NORMAL ) |
|
394 | 394 | { |
395 | - if (!is_iterable($messages)) { |
|
396 | - $messages = [$messages]; |
|
395 | + if ( ! is_iterable( $messages ) ) { |
|
396 | + $messages = [ $messages ]; |
|
397 | 397 | } |
398 | 398 | |
399 | - foreach ($messages as $message) { |
|
400 | - parent::write($message, $newline, $type); |
|
401 | - $this->writeBuffer($message, $newline, $type); |
|
399 | + foreach ( $messages as $message ) { |
|
400 | + parent::write( $message, $newline, $type ); |
|
401 | + $this->writeBuffer( $message, $newline, $type ); |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
406 | 406 | * {@inheritdoc} |
407 | 407 | */ |
408 | - public function newLine(int $count = 1) |
|
408 | + public function newLine( int $count = 1 ) |
|
409 | 409 | { |
410 | - parent::newLine($count); |
|
411 | - $this->bufferedOutput->write(str_repeat("\n", $count)); |
|
410 | + parent::newLine( $count ); |
|
411 | + $this->bufferedOutput->write( str_repeat( "\n", $count ) ); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | /** |
@@ -418,13 +418,13 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public function getErrorStyle() |
420 | 420 | { |
421 | - return new self($this->input, $this->getErrorOutput()); |
|
421 | + return new self( $this->input, $this->getErrorOutput() ); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | private function getProgressBar(): ProgressBar |
425 | 425 | { |
426 | - if (!$this->progressBar) { |
|
427 | - throw new RuntimeException('The ProgressBar is not started.'); |
|
426 | + if ( ! $this->progressBar ) { |
|
427 | + throw new RuntimeException( 'The ProgressBar is not started.' ); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | return $this->progressBar; |
@@ -432,79 +432,79 @@ discard block |
||
432 | 432 | |
433 | 433 | private function autoPrependBlock(): void |
434 | 434 | { |
435 | - $chars = substr(str_replace(\PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2); |
|
435 | + $chars = substr( str_replace( \PHP_EOL, "\n", $this->bufferedOutput->fetch() ), -2 ); |
|
436 | 436 | |
437 | - if (!isset($chars[0])) { |
|
437 | + if ( ! isset( $chars[ 0 ] ) ) { |
|
438 | 438 | $this->newLine(); //empty history, so we should start with a new line. |
439 | 439 | |
440 | 440 | return; |
441 | 441 | } |
442 | 442 | //Prepend new line for each non LF chars (This means no blank line was output before) |
443 | - $this->newLine(2 - substr_count($chars, "\n")); |
|
443 | + $this->newLine( 2 - substr_count( $chars, "\n" ) ); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | private function autoPrependText(): void |
447 | 447 | { |
448 | 448 | $fetched = $this->bufferedOutput->fetch(); |
449 | 449 | //Prepend new line if last char isn't EOL: |
450 | - if (!str_ends_with($fetched, "\n")) { |
|
450 | + if ( ! str_ends_with( $fetched, "\n" ) ) { |
|
451 | 451 | $this->newLine(); |
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
455 | - private function writeBuffer(string $message, bool $newLine, int $type): void |
|
455 | + private function writeBuffer( string $message, bool $newLine, int $type ): void |
|
456 | 456 | { |
457 | 457 | // We need to know if the last chars are PHP_EOL |
458 | - $this->bufferedOutput->write($message, $newLine, $type); |
|
458 | + $this->bufferedOutput->write( $message, $newLine, $type ); |
|
459 | 459 | } |
460 | 460 | |
461 | - private function createBlock(iterable $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false): array |
|
461 | + private function createBlock( iterable $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false ): array |
|
462 | 462 | { |
463 | 463 | $indentLength = 0; |
464 | - $prefixLength = Helper::width(Helper::removeDecoration($this->getFormatter(), $prefix)); |
|
465 | - $lines = []; |
|
464 | + $prefixLength = Helper::width( Helper::removeDecoration( $this->getFormatter(), $prefix ) ); |
|
465 | + $lines = [ ]; |
|
466 | 466 | |
467 | - if (null !== $type) { |
|
468 | - $type = sprintf('[%s] ', $type); |
|
469 | - $indentLength = \strlen($type); |
|
470 | - $lineIndentation = str_repeat(' ', $indentLength); |
|
467 | + if ( null !== $type ) { |
|
468 | + $type = sprintf( '[%s] ', $type ); |
|
469 | + $indentLength = \strlen( $type ); |
|
470 | + $lineIndentation = str_repeat( ' ', $indentLength ); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | // wrap and add newlines for each element |
474 | - foreach ($messages as $key => $message) { |
|
475 | - if ($escape) { |
|
476 | - $message = OutputFormatter::escape($message); |
|
474 | + foreach ( $messages as $key => $message ) { |
|
475 | + if ( $escape ) { |
|
476 | + $message = OutputFormatter::escape( $message ); |
|
477 | 477 | } |
478 | 478 | |
479 | - $decorationLength = Helper::width($message) - Helper::width(Helper::removeDecoration($this->getFormatter(), $message)); |
|
480 | - $messageLineLength = min($this->lineLength - $prefixLength - $indentLength + $decorationLength, $this->lineLength); |
|
481 | - $messageLines = explode(\PHP_EOL, wordwrap($message, $messageLineLength, \PHP_EOL, true)); |
|
482 | - foreach ($messageLines as $messageLine) { |
|
483 | - $lines[] = $messageLine; |
|
479 | + $decorationLength = Helper::width( $message ) - Helper::width( Helper::removeDecoration( $this->getFormatter(), $message ) ); |
|
480 | + $messageLineLength = min( $this->lineLength - $prefixLength - $indentLength + $decorationLength, $this->lineLength ); |
|
481 | + $messageLines = explode( \PHP_EOL, wordwrap( $message, $messageLineLength, \PHP_EOL, true ) ); |
|
482 | + foreach ( $messageLines as $messageLine ) { |
|
483 | + $lines[ ] = $messageLine; |
|
484 | 484 | } |
485 | 485 | |
486 | - if (\count($messages) > 1 && $key < \count($messages) - 1) { |
|
487 | - $lines[] = ''; |
|
486 | + if ( \count( $messages ) > 1 && $key < \count( $messages ) - 1 ) { |
|
487 | + $lines[ ] = ''; |
|
488 | 488 | } |
489 | 489 | } |
490 | 490 | |
491 | 491 | $firstLineIndex = 0; |
492 | - if ($padding && $this->isDecorated()) { |
|
492 | + if ( $padding && $this->isDecorated() ) { |
|
493 | 493 | $firstLineIndex = 1; |
494 | - array_unshift($lines, ''); |
|
495 | - $lines[] = ''; |
|
494 | + array_unshift( $lines, '' ); |
|
495 | + $lines[ ] = ''; |
|
496 | 496 | } |
497 | 497 | |
498 | - foreach ($lines as $i => &$line) { |
|
499 | - if (null !== $type) { |
|
500 | - $line = $firstLineIndex === $i ? $type.$line : $lineIndentation.$line; |
|
498 | + foreach ( $lines as $i => &$line ) { |
|
499 | + if ( null !== $type ) { |
|
500 | + $line = $firstLineIndex === $i ? $type . $line : $lineIndentation . $line; |
|
501 | 501 | } |
502 | 502 | |
503 | - $line = $prefix.$line; |
|
504 | - $line .= str_repeat(' ', max($this->lineLength - Helper::width(Helper::removeDecoration($this->getFormatter(), $line)), 0)); |
|
503 | + $line = $prefix . $line; |
|
504 | + $line .= str_repeat( ' ', max( $this->lineLength - Helper::width( Helper::removeDecoration( $this->getFormatter(), $line ) ), 0 ) ); |
|
505 | 505 | |
506 | - if ($style) { |
|
507 | - $line = sprintf('<%s>%s</>', $style, $line); |
|
506 | + if ( $style ) { |
|
507 | + $line = sprintf( '<%s>%s</>', $style, $line ); |
|
508 | 508 | } |
509 | 509 | } |
510 | 510 |
@@ -21,85 +21,85 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Formats a command title. |
23 | 23 | */ |
24 | - public function title(string $message); |
|
24 | + public function title( string $message ); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Formats a section title. |
28 | 28 | */ |
29 | - public function section(string $message); |
|
29 | + public function section( string $message ); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Formats a list. |
33 | 33 | */ |
34 | - public function listing(array $elements); |
|
34 | + public function listing( array $elements ); |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Formats informational text. |
38 | 38 | * |
39 | 39 | * @param string|array $message |
40 | 40 | */ |
41 | - public function text($message); |
|
41 | + public function text( $message ); |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Formats a success result bar. |
45 | 45 | * |
46 | 46 | * @param string|array $message |
47 | 47 | */ |
48 | - public function success($message); |
|
48 | + public function success( $message ); |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Formats an error result bar. |
52 | 52 | * |
53 | 53 | * @param string|array $message |
54 | 54 | */ |
55 | - public function error($message); |
|
55 | + public function error( $message ); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Formats an warning result bar. |
59 | 59 | * |
60 | 60 | * @param string|array $message |
61 | 61 | */ |
62 | - public function warning($message); |
|
62 | + public function warning( $message ); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * Formats a note admonition. |
66 | 66 | * |
67 | 67 | * @param string|array $message |
68 | 68 | */ |
69 | - public function note($message); |
|
69 | + public function note( $message ); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Formats a caution admonition. |
73 | 73 | * |
74 | 74 | * @param string|array $message |
75 | 75 | */ |
76 | - public function caution($message); |
|
76 | + public function caution( $message ); |
|
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Formats a table. |
80 | 80 | */ |
81 | - public function table(array $headers, array $rows); |
|
81 | + public function table( array $headers, array $rows ); |
|
82 | 82 | |
83 | 83 | /** |
84 | 84 | * Asks a question. |
85 | 85 | * |
86 | 86 | * @return mixed |
87 | 87 | */ |
88 | - public function ask(string $question, string $default = null, callable $validator = null); |
|
88 | + public function ask( string $question, string $default = null, callable $validator = null ); |
|
89 | 89 | |
90 | 90 | /** |
91 | 91 | * Asks a question with the user input hidden. |
92 | 92 | * |
93 | 93 | * @return mixed |
94 | 94 | */ |
95 | - public function askHidden(string $question, callable $validator = null); |
|
95 | + public function askHidden( string $question, callable $validator = null ); |
|
96 | 96 | |
97 | 97 | /** |
98 | 98 | * Asks for confirmation. |
99 | 99 | * |
100 | 100 | * @return bool |
101 | 101 | */ |
102 | - public function confirm(string $question, bool $default = true); |
|
102 | + public function confirm( string $question, bool $default = true ); |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * Asks a choice question. |
@@ -108,22 +108,22 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return mixed |
110 | 110 | */ |
111 | - public function choice(string $question, array $choices, $default = null); |
|
111 | + public function choice( string $question, array $choices, $default = null ); |
|
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Add newline(s). |
115 | 115 | */ |
116 | - public function newLine(int $count = 1); |
|
116 | + public function newLine( int $count = 1 ); |
|
117 | 117 | |
118 | 118 | /** |
119 | 119 | * Starts the progress output. |
120 | 120 | */ |
121 | - public function progressStart(int $max = 0); |
|
121 | + public function progressStart( int $max = 0 ); |
|
122 | 122 | |
123 | 123 | /** |
124 | 124 | * Advances the progress output X steps. |
125 | 125 | */ |
126 | - public function progressAdvance(int $step = 1); |
|
126 | + public function progressAdvance( int $step = 1 ); |
|
127 | 127 | |
128 | 128 | /** |
129 | 129 | * Finishes the progress output. |