@@ -29,16 +29,16 @@ discard block |
||
29 | 29 | { |
30 | 30 | protected $definition; |
31 | 31 | protected $stream; |
32 | - protected $options = []; |
|
33 | - protected $arguments = []; |
|
32 | + protected $options = [ ]; |
|
33 | + protected $arguments = [ ]; |
|
34 | 34 | protected $interactive = true; |
35 | 35 | |
36 | - public function __construct(InputDefinition $definition = null) |
|
36 | + public function __construct( InputDefinition $definition = null ) |
|
37 | 37 | { |
38 | - if (null === $definition) { |
|
38 | + if ( null === $definition ) { |
|
39 | 39 | $this->definition = new InputDefinition(); |
40 | 40 | } else { |
41 | - $this->bind($definition); |
|
41 | + $this->bind( $definition ); |
|
42 | 42 | $this->validate(); |
43 | 43 | } |
44 | 44 | } |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * {@inheritdoc} |
48 | 48 | */ |
49 | - public function bind(InputDefinition $definition) |
|
49 | + public function bind( InputDefinition $definition ) |
|
50 | 50 | { |
51 | - $this->arguments = []; |
|
52 | - $this->options = []; |
|
51 | + $this->arguments = [ ]; |
|
52 | + $this->options = [ ]; |
|
53 | 53 | $this->definition = $definition; |
54 | 54 | |
55 | 55 | $this->parse(); |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | $definition = $this->definition; |
69 | 69 | $givenArguments = $this->arguments; |
70 | 70 | |
71 | - $missingArguments = array_filter(array_keys($definition->getArguments()), function ($argument) use ($definition, $givenArguments) { |
|
72 | - return !\array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired(); |
|
71 | + $missingArguments = array_filter( array_keys( $definition->getArguments() ), function( $argument ) use ( $definition, $givenArguments ) { |
|
72 | + return ! \array_key_exists( $argument, $givenArguments ) && $definition->getArgument( $argument )->isRequired(); |
|
73 | 73 | }); |
74 | 74 | |
75 | - if (\count($missingArguments) > 0) { |
|
76 | - throw new RuntimeException(sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArguments))); |
|
75 | + if ( \count( $missingArguments ) > 0 ) { |
|
76 | + throw new RuntimeException( sprintf( 'Not enough arguments (missing: "%s").', implode( ', ', $missingArguments ) ) ); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | /** |
89 | 89 | * {@inheritdoc} |
90 | 90 | */ |
91 | - public function setInteractive(bool $interactive) |
|
91 | + public function setInteractive( bool $interactive ) |
|
92 | 92 | { |
93 | 93 | $this->interactive = $interactive; |
94 | 94 | } |
@@ -98,39 +98,39 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function getArguments() |
100 | 100 | { |
101 | - return array_merge($this->definition->getArgumentDefaults(), $this->arguments); |
|
101 | + return array_merge( $this->definition->getArgumentDefaults(), $this->arguments ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * {@inheritdoc} |
106 | 106 | */ |
107 | - public function getArgument(string $name) |
|
107 | + public function getArgument( string $name ) |
|
108 | 108 | { |
109 | - if (!$this->definition->hasArgument($name)) { |
|
110 | - throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); |
|
109 | + if ( ! $this->definition->hasArgument( $name ) ) { |
|
110 | + throw new InvalidArgumentException( sprintf( 'The "%s" argument does not exist.', $name ) ); |
|
111 | 111 | } |
112 | 112 | |
113 | - return $this->arguments[$name] ?? $this->definition->getArgument($name)->getDefault(); |
|
113 | + return $this->arguments[ $name ] ?? $this->definition->getArgument( $name )->getDefault(); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
117 | 117 | * {@inheritdoc} |
118 | 118 | */ |
119 | - public function setArgument(string $name, $value) |
|
119 | + public function setArgument( string $name, $value ) |
|
120 | 120 | { |
121 | - if (!$this->definition->hasArgument($name)) { |
|
122 | - throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); |
|
121 | + if ( ! $this->definition->hasArgument( $name ) ) { |
|
122 | + throw new InvalidArgumentException( sprintf( 'The "%s" argument does not exist.', $name ) ); |
|
123 | 123 | } |
124 | 124 | |
125 | - $this->arguments[$name] = $value; |
|
125 | + $this->arguments[ $name ] = $value; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | 129 | * {@inheritdoc} |
130 | 130 | */ |
131 | - public function hasArgument(string $name) |
|
131 | + public function hasArgument( string $name ) |
|
132 | 132 | { |
133 | - return $this->definition->hasArgument($name); |
|
133 | + return $this->definition->hasArgument( $name ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -138,51 +138,51 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function getOptions() |
140 | 140 | { |
141 | - return array_merge($this->definition->getOptionDefaults(), $this->options); |
|
141 | + return array_merge( $this->definition->getOptionDefaults(), $this->options ); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
145 | 145 | * {@inheritdoc} |
146 | 146 | */ |
147 | - public function getOption(string $name) |
|
147 | + public function getOption( string $name ) |
|
148 | 148 | { |
149 | - if ($this->definition->hasNegation($name)) { |
|
150 | - if (null === $value = $this->getOption($this->definition->negationToName($name))) { |
|
149 | + if ( $this->definition->hasNegation( $name ) ) { |
|
150 | + if ( null === $value = $this->getOption( $this->definition->negationToName( $name ) ) ) { |
|
151 | 151 | return $value; |
152 | 152 | } |
153 | 153 | |
154 | - return !$value; |
|
154 | + return ! $value; |
|
155 | 155 | } |
156 | 156 | |
157 | - if (!$this->definition->hasOption($name)) { |
|
158 | - throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name)); |
|
157 | + if ( ! $this->definition->hasOption( $name ) ) { |
|
158 | + throw new InvalidArgumentException( sprintf( 'The "%s" option does not exist.', $name ) ); |
|
159 | 159 | } |
160 | 160 | |
161 | - return \array_key_exists($name, $this->options) ? $this->options[$name] : $this->definition->getOption($name)->getDefault(); |
|
161 | + return \array_key_exists( $name, $this->options ) ? $this->options[ $name ] : $this->definition->getOption( $name )->getDefault(); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * {@inheritdoc} |
166 | 166 | */ |
167 | - public function setOption(string $name, $value) |
|
167 | + public function setOption( string $name, $value ) |
|
168 | 168 | { |
169 | - if ($this->definition->hasNegation($name)) { |
|
170 | - $this->options[$this->definition->negationToName($name)] = !$value; |
|
169 | + if ( $this->definition->hasNegation( $name ) ) { |
|
170 | + $this->options[ $this->definition->negationToName( $name ) ] = ! $value; |
|
171 | 171 | |
172 | 172 | return; |
173 | - } elseif (!$this->definition->hasOption($name)) { |
|
174 | - throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name)); |
|
173 | + } elseif ( ! $this->definition->hasOption( $name ) ) { |
|
174 | + throw new InvalidArgumentException( sprintf( 'The "%s" option does not exist.', $name ) ); |
|
175 | 175 | } |
176 | 176 | |
177 | - $this->options[$name] = $value; |
|
177 | + $this->options[ $name ] = $value; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
181 | 181 | * {@inheritdoc} |
182 | 182 | */ |
183 | - public function hasOption(string $name) |
|
183 | + public function hasOption( string $name ) |
|
184 | 184 | { |
185 | - return $this->definition->hasOption($name) || $this->definition->hasNegation($name); |
|
185 | + return $this->definition->hasOption( $name ) || $this->definition->hasNegation( $name ); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -190,15 +190,15 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return string |
192 | 192 | */ |
193 | - public function escapeToken(string $token) |
|
193 | + public function escapeToken( string $token ) |
|
194 | 194 | { |
195 | - return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token); |
|
195 | + return preg_match( '{^[\w-]+$}', $token ) ? $token : escapeshellarg( $token ); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
199 | 199 | * {@inheritdoc} |
200 | 200 | */ |
201 | - public function setStream($stream) |
|
201 | + public function setStream( $stream ) |
|
202 | 202 | { |
203 | 203 | $this->stream = $stream; |
204 | 204 | } |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | { |
28 | 28 | private $parameters; |
29 | 29 | |
30 | - public function __construct(array $parameters, InputDefinition $definition = null) |
|
30 | + public function __construct( array $parameters, InputDefinition $definition = null ) |
|
31 | 31 | { |
32 | 32 | $this->parameters = $parameters; |
33 | 33 | |
34 | - parent::__construct($definition); |
|
34 | + parent::__construct( $definition ); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function getFirstArgument() |
41 | 41 | { |
42 | - foreach ($this->parameters as $param => $value) { |
|
43 | - if ($param && \is_string($param) && '-' === $param[0]) { |
|
42 | + foreach ( $this->parameters as $param => $value ) { |
|
43 | + if ( $param && \is_string( $param ) && '-' === $param[ 0 ] ) { |
|
44 | 44 | continue; |
45 | 45 | } |
46 | 46 | |
@@ -53,20 +53,20 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * {@inheritdoc} |
55 | 55 | */ |
56 | - public function hasParameterOption($values, bool $onlyParams = false) |
|
56 | + public function hasParameterOption( $values, bool $onlyParams = false ) |
|
57 | 57 | { |
58 | - $values = (array) $values; |
|
58 | + $values = (array)$values; |
|
59 | 59 | |
60 | - foreach ($this->parameters as $k => $v) { |
|
61 | - if (!\is_int($k)) { |
|
60 | + foreach ( $this->parameters as $k => $v ) { |
|
61 | + if ( ! \is_int( $k ) ) { |
|
62 | 62 | $v = $k; |
63 | 63 | } |
64 | 64 | |
65 | - if ($onlyParams && '--' === $v) { |
|
65 | + if ( $onlyParams && '--' === $v ) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - if (\in_array($v, $values)) { |
|
69 | + if ( \in_array( $v, $values ) ) { |
|
70 | 70 | return true; |
71 | 71 | } |
72 | 72 | } |
@@ -77,20 +77,20 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * {@inheritdoc} |
79 | 79 | */ |
80 | - public function getParameterOption($values, $default = false, bool $onlyParams = false) |
|
80 | + public function getParameterOption( $values, $default = false, bool $onlyParams = false ) |
|
81 | 81 | { |
82 | - $values = (array) $values; |
|
82 | + $values = (array)$values; |
|
83 | 83 | |
84 | - foreach ($this->parameters as $k => $v) { |
|
85 | - if ($onlyParams && ('--' === $k || (\is_int($k) && '--' === $v))) { |
|
84 | + foreach ( $this->parameters as $k => $v ) { |
|
85 | + if ( $onlyParams && ( '--' === $k || ( \is_int( $k ) && '--' === $v ) ) ) { |
|
86 | 86 | return $default; |
87 | 87 | } |
88 | 88 | |
89 | - if (\is_int($k)) { |
|
90 | - if (\in_array($v, $values)) { |
|
89 | + if ( \is_int( $k ) ) { |
|
90 | + if ( \in_array( $v, $values ) ) { |
|
91 | 91 | return true; |
92 | 92 | } |
93 | - } elseif (\in_array($k, $values)) { |
|
93 | + } elseif ( \in_array( $k, $values ) ) { |
|
94 | 94 | return $v; |
95 | 95 | } |
96 | 96 | } |
@@ -105,23 +105,23 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function __toString() |
107 | 107 | { |
108 | - $params = []; |
|
109 | - foreach ($this->parameters as $param => $val) { |
|
110 | - if ($param && \is_string($param) && '-' === $param[0]) { |
|
111 | - $glue = ('-' === $param[1]) ? '=' : ' '; |
|
112 | - if (\is_array($val)) { |
|
113 | - foreach ($val as $v) { |
|
114 | - $params[] = $param.('' != $v ? $glue.$this->escapeToken($v) : ''); |
|
108 | + $params = [ ]; |
|
109 | + foreach ( $this->parameters as $param => $val ) { |
|
110 | + if ( $param && \is_string( $param ) && '-' === $param[ 0 ] ) { |
|
111 | + $glue = ( '-' === $param[ 1 ] ) ? '=' : ' '; |
|
112 | + if ( \is_array( $val ) ) { |
|
113 | + foreach ( $val as $v ) { |
|
114 | + $params[ ] = $param . ( '' != $v ? $glue . $this->escapeToken( $v ) : '' ); |
|
115 | 115 | } |
116 | 116 | } else { |
117 | - $params[] = $param.('' != $val ? $glue.$this->escapeToken($val) : ''); |
|
117 | + $params[ ] = $param . ( '' != $val ? $glue . $this->escapeToken( $val ) : '' ); |
|
118 | 118 | } |
119 | 119 | } else { |
120 | - $params[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val); |
|
120 | + $params[ ] = \is_array( $val ) ? implode( ' ', array_map( [ $this, 'escapeToken' ], $val ) ) : $this->escapeToken( $val ); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - return implode(' ', $params); |
|
124 | + return implode( ' ', $params ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,16 +129,16 @@ discard block |
||
129 | 129 | */ |
130 | 130 | protected function parse() |
131 | 131 | { |
132 | - foreach ($this->parameters as $key => $value) { |
|
133 | - if ('--' === $key) { |
|
132 | + foreach ( $this->parameters as $key => $value ) { |
|
133 | + if ( '--' === $key ) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | - if (str_starts_with($key, '--')) { |
|
137 | - $this->addLongOption(substr($key, 2), $value); |
|
138 | - } elseif (str_starts_with($key, '-')) { |
|
139 | - $this->addShortOption(substr($key, 1), $value); |
|
136 | + if ( str_starts_with( $key, '--' ) ) { |
|
137 | + $this->addLongOption( substr( $key, 2 ), $value ); |
|
138 | + } elseif ( str_starts_with( $key, '-' ) ) { |
|
139 | + $this->addShortOption( substr( $key, 1 ), $value ); |
|
140 | 140 | } else { |
141 | - $this->addArgument($key, $value); |
|
141 | + $this->addArgument( $key, $value ); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | } |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @throws InvalidOptionException When option given doesn't exist |
150 | 150 | */ |
151 | - private function addShortOption(string $shortcut, $value) |
|
151 | + private function addShortOption( string $shortcut, $value ) |
|
152 | 152 | { |
153 | - if (!$this->definition->hasShortcut($shortcut)) { |
|
154 | - throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut)); |
|
153 | + if ( ! $this->definition->hasShortcut( $shortcut ) ) { |
|
154 | + throw new InvalidOptionException( sprintf( 'The "-%s" option does not exist.', $shortcut ) ); |
|
155 | 155 | } |
156 | 156 | |
157 | - $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value); |
|
157 | + $this->addLongOption( $this->definition->getOptionForShortcut( $shortcut )->getName(), $value ); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -163,32 +163,32 @@ discard block |
||
163 | 163 | * @throws InvalidOptionException When option given doesn't exist |
164 | 164 | * @throws InvalidOptionException When a required value is missing |
165 | 165 | */ |
166 | - private function addLongOption(string $name, $value) |
|
166 | + private function addLongOption( string $name, $value ) |
|
167 | 167 | { |
168 | - if (!$this->definition->hasOption($name)) { |
|
169 | - if (!$this->definition->hasNegation($name)) { |
|
170 | - throw new InvalidOptionException(sprintf('The "--%s" option does not exist.', $name)); |
|
168 | + if ( ! $this->definition->hasOption( $name ) ) { |
|
169 | + if ( ! $this->definition->hasNegation( $name ) ) { |
|
170 | + throw new InvalidOptionException( sprintf( 'The "--%s" option does not exist.', $name ) ); |
|
171 | 171 | } |
172 | 172 | |
173 | - $optionName = $this->definition->negationToName($name); |
|
174 | - $this->options[$optionName] = false; |
|
173 | + $optionName = $this->definition->negationToName( $name ); |
|
174 | + $this->options[ $optionName ] = false; |
|
175 | 175 | |
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | - $option = $this->definition->getOption($name); |
|
179 | + $option = $this->definition->getOption( $name ); |
|
180 | 180 | |
181 | - if (null === $value) { |
|
182 | - if ($option->isValueRequired()) { |
|
183 | - throw new InvalidOptionException(sprintf('The "--%s" option requires a value.', $name)); |
|
181 | + if ( null === $value ) { |
|
182 | + if ( $option->isValueRequired() ) { |
|
183 | + throw new InvalidOptionException( sprintf( 'The "--%s" option requires a value.', $name ) ); |
|
184 | 184 | } |
185 | 185 | |
186 | - if (!$option->isValueOptional()) { |
|
186 | + if ( ! $option->isValueOptional() ) { |
|
187 | 187 | $value = true; |
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - $this->options[$name] = $value; |
|
191 | + $this->options[ $name ] = $value; |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -199,12 +199,12 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @throws InvalidArgumentException When argument given doesn't exist |
201 | 201 | */ |
202 | - private function addArgument($name, $value) |
|
202 | + private function addArgument( $name, $value ) |
|
203 | 203 | { |
204 | - if (!$this->definition->hasArgument($name)) { |
|
205 | - throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); |
|
204 | + if ( ! $this->definition->hasArgument( $name ) ) { |
|
205 | + throw new InvalidArgumentException( sprintf( 'The "%s" argument does not exist.', $name ) ); |
|
206 | 206 | } |
207 | 207 | |
208 | - $this->arguments[$name] = $value; |
|
208 | + $this->arguments[ $name ] = $value; |
|
209 | 209 | } |
210 | 210 | } |
@@ -13,37 +13,37 @@ discard block |
||
13 | 13 | |
14 | 14 | final class SignalRegistry |
15 | 15 | { |
16 | - private $signalHandlers = []; |
|
16 | + private $signalHandlers = [ ]; |
|
17 | 17 | |
18 | 18 | public function __construct() |
19 | 19 | { |
20 | - if (\function_exists('pcntl_async_signals')) { |
|
21 | - pcntl_async_signals(true); |
|
20 | + if ( \function_exists( 'pcntl_async_signals' ) ) { |
|
21 | + pcntl_async_signals( true ); |
|
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
25 | - public function register(int $signal, callable $signalHandler): void |
|
25 | + public function register( int $signal, callable $signalHandler ): void |
|
26 | 26 | { |
27 | - if (!isset($this->signalHandlers[$signal])) { |
|
28 | - $previousCallback = pcntl_signal_get_handler($signal); |
|
27 | + if ( ! isset( $this->signalHandlers[ $signal ] ) ) { |
|
28 | + $previousCallback = pcntl_signal_get_handler( $signal ); |
|
29 | 29 | |
30 | - if (\is_callable($previousCallback)) { |
|
31 | - $this->signalHandlers[$signal][] = $previousCallback; |
|
30 | + if ( \is_callable( $previousCallback ) ) { |
|
31 | + $this->signalHandlers[ $signal ][ ] = $previousCallback; |
|
32 | 32 | } |
33 | 33 | } |
34 | 34 | |
35 | - $this->signalHandlers[$signal][] = $signalHandler; |
|
35 | + $this->signalHandlers[ $signal ][ ] = $signalHandler; |
|
36 | 36 | |
37 | - pcntl_signal($signal, [$this, 'handle']); |
|
37 | + pcntl_signal( $signal, [ $this, 'handle' ] ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public static function isSupported(): bool |
41 | 41 | { |
42 | - if (!\function_exists('pcntl_signal')) { |
|
42 | + if ( ! \function_exists( 'pcntl_signal' ) ) { |
|
43 | 43 | return false; |
44 | 44 | } |
45 | 45 | |
46 | - if (\in_array('pcntl_signal', explode(',', ini_get('disable_functions')))) { |
|
46 | + if ( \in_array( 'pcntl_signal', explode( ',', ini_get( 'disable_functions' ) ) ) ) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @internal |
55 | 55 | */ |
56 | - public function handle(int $signal): void |
|
56 | + public function handle( int $signal ): void |
|
57 | 57 | { |
58 | - $count = \count($this->signalHandlers[$signal]); |
|
58 | + $count = \count( $this->signalHandlers[ $signal ] ); |
|
59 | 59 | |
60 | - foreach ($this->signalHandlers[$signal] as $i => $signalHandler) { |
|
60 | + foreach ( $this->signalHandlers[ $signal ] as $i => $signalHandler ) { |
|
61 | 61 | $hasNext = $i !== $count - 1; |
62 | - $signalHandler($signal, $hasNext); |
|
62 | + $signalHandler( $signal, $hasNext ); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @param callable[] $factories Indexed by command names |
27 | 27 | */ |
28 | - public function __construct(array $factories) |
|
28 | + public function __construct( array $factories ) |
|
29 | 29 | { |
30 | 30 | $this->factories = $factories; |
31 | 31 | } |
@@ -33,21 +33,21 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * {@inheritdoc} |
35 | 35 | */ |
36 | - public function has(string $name) |
|
36 | + public function has( string $name ) |
|
37 | 37 | { |
38 | - return isset($this->factories[$name]); |
|
38 | + return isset( $this->factories[ $name ] ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * {@inheritdoc} |
43 | 43 | */ |
44 | - public function get(string $name) |
|
44 | + public function get( string $name ) |
|
45 | 45 | { |
46 | - if (!isset($this->factories[$name])) { |
|
47 | - throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); |
|
46 | + if ( ! isset( $this->factories[ $name ] ) ) { |
|
47 | + throw new CommandNotFoundException( sprintf( 'Command "%s" does not exist.', $name ) ); |
|
48 | 48 | } |
49 | 49 | |
50 | - $factory = $this->factories[$name]; |
|
50 | + $factory = $this->factories[ $name ]; |
|
51 | 51 | |
52 | 52 | return $factory(); |
53 | 53 | } |
@@ -57,6 +57,6 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function getNames() |
59 | 59 | { |
60 | - return array_keys($this->factories); |
|
60 | + return array_keys( $this->factories ); |
|
61 | 61 | } |
62 | 62 | } |
@@ -26,14 +26,14 @@ |
||
26 | 26 | * |
27 | 27 | * @throws CommandNotFoundException |
28 | 28 | */ |
29 | - public function get(string $name); |
|
29 | + public function get( string $name ); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Checks if a command exists. |
33 | 33 | * |
34 | 34 | * @return bool |
35 | 35 | */ |
36 | - public function has(string $name); |
|
36 | + public function has( string $name ); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @return string[] All registered command names |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * @param array $commandMap An array with command names as keys and service ids as values |
29 | 29 | */ |
30 | - public function __construct(ContainerInterface $container, array $commandMap) |
|
30 | + public function __construct( ContainerInterface $container, array $commandMap ) |
|
31 | 31 | { |
32 | 32 | $this->container = $container; |
33 | 33 | $this->commandMap = $commandMap; |
@@ -36,21 +36,21 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * {@inheritdoc} |
38 | 38 | */ |
39 | - public function get(string $name) |
|
39 | + public function get( string $name ) |
|
40 | 40 | { |
41 | - if (!$this->has($name)) { |
|
42 | - throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); |
|
41 | + if ( ! $this->has( $name ) ) { |
|
42 | + throw new CommandNotFoundException( sprintf( 'Command "%s" does not exist.', $name ) ); |
|
43 | 43 | } |
44 | 44 | |
45 | - return $this->container->get($this->commandMap[$name]); |
|
45 | + return $this->container->get( $this->commandMap[ $name ] ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | 49 | * {@inheritdoc} |
50 | 50 | */ |
51 | - public function has(string $name) |
|
51 | + public function has( string $name ) |
|
52 | 52 | { |
53 | - return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]); |
|
53 | + return isset( $this->commandMap[ $name ] ) && $this->container->has( $this->commandMap[ $name ] ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -58,6 +58,6 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function getNames() |
60 | 60 | { |
61 | - return array_keys($this->commandMap); |
|
61 | + return array_keys( $this->commandMap ); |
|
62 | 62 | } |
63 | 63 | } |
@@ -42,139 +42,139 @@ |
||
42 | 42 | ]; |
43 | 43 | |
44 | 44 | private const AVAILABLE_OPTIONS = [ |
45 | - 'bold' => ['set' => 1, 'unset' => 22], |
|
46 | - 'underscore' => ['set' => 4, 'unset' => 24], |
|
47 | - 'blink' => ['set' => 5, 'unset' => 25], |
|
48 | - 'reverse' => ['set' => 7, 'unset' => 27], |
|
49 | - 'conceal' => ['set' => 8, 'unset' => 28], |
|
45 | + 'bold' => [ 'set' => 1, 'unset' => 22 ], |
|
46 | + 'underscore' => [ 'set' => 4, 'unset' => 24 ], |
|
47 | + 'blink' => [ 'set' => 5, 'unset' => 25 ], |
|
48 | + 'reverse' => [ 'set' => 7, 'unset' => 27 ], |
|
49 | + 'conceal' => [ 'set' => 8, 'unset' => 28 ], |
|
50 | 50 | ]; |
51 | 51 | |
52 | 52 | private $foreground; |
53 | 53 | private $background; |
54 | - private $options = []; |
|
54 | + private $options = [ ]; |
|
55 | 55 | |
56 | - public function __construct(string $foreground = '', string $background = '', array $options = []) |
|
56 | + public function __construct( string $foreground = '', string $background = '', array $options = [ ] ) |
|
57 | 57 | { |
58 | - $this->foreground = $this->parseColor($foreground); |
|
59 | - $this->background = $this->parseColor($background, true); |
|
58 | + $this->foreground = $this->parseColor( $foreground ); |
|
59 | + $this->background = $this->parseColor( $background, true ); |
|
60 | 60 | |
61 | - foreach ($options as $option) { |
|
62 | - if (!isset(self::AVAILABLE_OPTIONS[$option])) { |
|
63 | - throw new InvalidArgumentException(sprintf('Invalid option specified: "%s". Expected one of (%s).', $option, implode(', ', array_keys(self::AVAILABLE_OPTIONS)))); |
|
61 | + foreach ( $options as $option ) { |
|
62 | + if ( ! isset( self::AVAILABLE_OPTIONS[ $option ] ) ) { |
|
63 | + throw new InvalidArgumentException( sprintf( 'Invalid option specified: "%s". Expected one of (%s).', $option, implode( ', ', array_keys( self::AVAILABLE_OPTIONS ) ) ) ); |
|
64 | 64 | } |
65 | 65 | |
66 | - $this->options[$option] = self::AVAILABLE_OPTIONS[$option]; |
|
66 | + $this->options[ $option ] = self::AVAILABLE_OPTIONS[ $option ]; |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | - public function apply(string $text): string |
|
70 | + public function apply( string $text ): string |
|
71 | 71 | { |
72 | - return $this->set().$text.$this->unset(); |
|
72 | + return $this->set() . $text . $this->unset(); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | public function set(): string |
76 | 76 | { |
77 | - $setCodes = []; |
|
78 | - if ('' !== $this->foreground) { |
|
79 | - $setCodes[] = $this->foreground; |
|
77 | + $setCodes = [ ]; |
|
78 | + if ( '' !== $this->foreground ) { |
|
79 | + $setCodes[ ] = $this->foreground; |
|
80 | 80 | } |
81 | - if ('' !== $this->background) { |
|
82 | - $setCodes[] = $this->background; |
|
81 | + if ( '' !== $this->background ) { |
|
82 | + $setCodes[ ] = $this->background; |
|
83 | 83 | } |
84 | - foreach ($this->options as $option) { |
|
85 | - $setCodes[] = $option['set']; |
|
84 | + foreach ( $this->options as $option ) { |
|
85 | + $setCodes[ ] = $option[ 'set' ]; |
|
86 | 86 | } |
87 | - if (0 === \count($setCodes)) { |
|
87 | + if ( 0 === \count( $setCodes ) ) { |
|
88 | 88 | return ''; |
89 | 89 | } |
90 | 90 | |
91 | - return sprintf("\033[%sm", implode(';', $setCodes)); |
|
91 | + return sprintf( "\033[%sm", implode( ';', $setCodes ) ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | public function unset(): string |
95 | 95 | { |
96 | - $unsetCodes = []; |
|
97 | - if ('' !== $this->foreground) { |
|
98 | - $unsetCodes[] = 39; |
|
96 | + $unsetCodes = [ ]; |
|
97 | + if ( '' !== $this->foreground ) { |
|
98 | + $unsetCodes[ ] = 39; |
|
99 | 99 | } |
100 | - if ('' !== $this->background) { |
|
101 | - $unsetCodes[] = 49; |
|
100 | + if ( '' !== $this->background ) { |
|
101 | + $unsetCodes[ ] = 49; |
|
102 | 102 | } |
103 | - foreach ($this->options as $option) { |
|
104 | - $unsetCodes[] = $option['unset']; |
|
103 | + foreach ( $this->options as $option ) { |
|
104 | + $unsetCodes[ ] = $option[ 'unset' ]; |
|
105 | 105 | } |
106 | - if (0 === \count($unsetCodes)) { |
|
106 | + if ( 0 === \count( $unsetCodes ) ) { |
|
107 | 107 | return ''; |
108 | 108 | } |
109 | 109 | |
110 | - return sprintf("\033[%sm", implode(';', $unsetCodes)); |
|
110 | + return sprintf( "\033[%sm", implode( ';', $unsetCodes ) ); |
|
111 | 111 | } |
112 | 112 | |
113 | - private function parseColor(string $color, bool $background = false): string |
|
113 | + private function parseColor( string $color, bool $background = false ): string |
|
114 | 114 | { |
115 | - if ('' === $color) { |
|
115 | + if ( '' === $color ) { |
|
116 | 116 | return ''; |
117 | 117 | } |
118 | 118 | |
119 | - if ('#' === $color[0]) { |
|
120 | - $color = substr($color, 1); |
|
119 | + if ( '#' === $color[ 0 ] ) { |
|
120 | + $color = substr( $color, 1 ); |
|
121 | 121 | |
122 | - if (3 === \strlen($color)) { |
|
123 | - $color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2]; |
|
122 | + if ( 3 === \strlen( $color ) ) { |
|
123 | + $color = $color[ 0 ] . $color[ 0 ] . $color[ 1 ] . $color[ 1 ] . $color[ 2 ] . $color[ 2 ]; |
|
124 | 124 | } |
125 | 125 | |
126 | - if (6 !== \strlen($color)) { |
|
127 | - throw new InvalidArgumentException(sprintf('Invalid "%s" color.', $color)); |
|
126 | + if ( 6 !== \strlen( $color ) ) { |
|
127 | + throw new InvalidArgumentException( sprintf( 'Invalid "%s" color.', $color ) ); |
|
128 | 128 | } |
129 | 129 | |
130 | - return ($background ? '4' : '3').$this->convertHexColorToAnsi(hexdec($color)); |
|
130 | + return ( $background ? '4' : '3' ) . $this->convertHexColorToAnsi( hexdec( $color ) ); |
|
131 | 131 | } |
132 | 132 | |
133 | - if (isset(self::COLORS[$color])) { |
|
134 | - return ($background ? '4' : '3').self::COLORS[$color]; |
|
133 | + if ( isset( self::COLORS[ $color ] ) ) { |
|
134 | + return ( $background ? '4' : '3' ) . self::COLORS[ $color ]; |
|
135 | 135 | } |
136 | 136 | |
137 | - if (isset(self::BRIGHT_COLORS[$color])) { |
|
138 | - return ($background ? '10' : '9').self::BRIGHT_COLORS[$color]; |
|
137 | + if ( isset( self::BRIGHT_COLORS[ $color ] ) ) { |
|
138 | + return ( $background ? '10' : '9' ) . self::BRIGHT_COLORS[ $color ]; |
|
139 | 139 | } |
140 | 140 | |
141 | - throw new InvalidArgumentException(sprintf('Invalid "%s" color; expected one of (%s).', $color, implode(', ', array_merge(array_keys(self::COLORS), array_keys(self::BRIGHT_COLORS))))); |
|
141 | + throw new InvalidArgumentException( sprintf( 'Invalid "%s" color; expected one of (%s).', $color, implode( ', ', array_merge( array_keys( self::COLORS ), array_keys( self::BRIGHT_COLORS ) ) ) ) ); |
|
142 | 142 | } |
143 | 143 | |
144 | - private function convertHexColorToAnsi(int $color): string |
|
144 | + private function convertHexColorToAnsi( int $color ): string |
|
145 | 145 | { |
146 | - $r = ($color >> 16) & 255; |
|
147 | - $g = ($color >> 8) & 255; |
|
146 | + $r = ( $color >> 16 ) & 255; |
|
147 | + $g = ( $color >> 8 ) & 255; |
|
148 | 148 | $b = $color & 255; |
149 | 149 | |
150 | 150 | // see https://github.com/termstandard/colors/ for more information about true color support |
151 | - if ('truecolor' !== getenv('COLORTERM')) { |
|
152 | - return (string) $this->degradeHexColorToAnsi($r, $g, $b); |
|
151 | + if ( 'truecolor' !== getenv( 'COLORTERM' ) ) { |
|
152 | + return (string)$this->degradeHexColorToAnsi( $r, $g, $b ); |
|
153 | 153 | } |
154 | 154 | |
155 | - return sprintf('8;2;%d;%d;%d', $r, $g, $b); |
|
155 | + return sprintf( '8;2;%d;%d;%d', $r, $g, $b ); |
|
156 | 156 | } |
157 | 157 | |
158 | - private function degradeHexColorToAnsi(int $r, int $g, int $b): int |
|
158 | + private function degradeHexColorToAnsi( int $r, int $g, int $b ): int |
|
159 | 159 | { |
160 | - if (0 === round($this->getSaturation($r, $g, $b) / 50)) { |
|
160 | + if ( 0 === round( $this->getSaturation( $r, $g, $b ) / 50 ) ) { |
|
161 | 161 | return 0; |
162 | 162 | } |
163 | 163 | |
164 | - return (round($b / 255) << 2) | (round($g / 255) << 1) | round($r / 255); |
|
164 | + return ( round( $b / 255 ) << 2 ) | ( round( $g / 255 ) << 1 ) | round( $r / 255 ); |
|
165 | 165 | } |
166 | 166 | |
167 | - private function getSaturation(int $r, int $g, int $b): int |
|
167 | + private function getSaturation( int $r, int $g, int $b ): int |
|
168 | 168 | { |
169 | 169 | $r = $r / 255; |
170 | 170 | $g = $g / 255; |
171 | 171 | $b = $b / 255; |
172 | - $v = max($r, $g, $b); |
|
172 | + $v = max( $r, $g, $b ); |
|
173 | 173 | |
174 | - if (0 === $diff = $v - min($r, $g, $b)) { |
|
174 | + if ( 0 === $diff = $v - min( $r, $g, $b ) ) { |
|
175 | 175 | return 0; |
176 | 176 | } |
177 | 177 | |
178 | - return (int) $diff * 100 / $v; |
|
178 | + return (int)$diff * 100 / $v; |
|
179 | 179 | } |
180 | 180 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | class Application implements ResetInterface |
68 | 68 | { |
69 | - private $commands = []; |
|
69 | + private $commands = [ ]; |
|
70 | 70 | private $wantHelps = false; |
71 | 71 | private $runningCommand; |
72 | 72 | private $name; |
@@ -82,43 +82,43 @@ discard block |
||
82 | 82 | private $singleCommand = false; |
83 | 83 | private $initialized; |
84 | 84 | private $signalRegistry; |
85 | - private $signalsToDispatchEvent = []; |
|
85 | + private $signalsToDispatchEvent = [ ]; |
|
86 | 86 | |
87 | - public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN') |
|
87 | + public function __construct( string $name = 'UNKNOWN', string $version = 'UNKNOWN' ) |
|
88 | 88 | { |
89 | 89 | $this->name = $name; |
90 | 90 | $this->version = $version; |
91 | 91 | $this->terminal = new Terminal(); |
92 | 92 | $this->defaultCommand = 'list'; |
93 | - if (\defined('SIGINT') && SignalRegistry::isSupported()) { |
|
93 | + if ( \defined( 'SIGINT' ) && SignalRegistry::isSupported() ) { |
|
94 | 94 | $this->signalRegistry = new SignalRegistry(); |
95 | - $this->signalsToDispatchEvent = [\SIGINT, \SIGTERM, \SIGUSR1, \SIGUSR2]; |
|
95 | + $this->signalsToDispatchEvent = [ \SIGINT, \SIGTERM, \SIGUSR1, \SIGUSR2 ]; |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * @final |
101 | 101 | */ |
102 | - public function setDispatcher(EventDispatcherInterface $dispatcher) |
|
102 | + public function setDispatcher( EventDispatcherInterface $dispatcher ) |
|
103 | 103 | { |
104 | 104 | $this->dispatcher = $dispatcher; |
105 | 105 | } |
106 | 106 | |
107 | - public function setCommandLoader(CommandLoaderInterface $commandLoader) |
|
107 | + public function setCommandLoader( CommandLoaderInterface $commandLoader ) |
|
108 | 108 | { |
109 | 109 | $this->commandLoader = $commandLoader; |
110 | 110 | } |
111 | 111 | |
112 | 112 | public function getSignalRegistry(): SignalRegistry |
113 | 113 | { |
114 | - if (!$this->signalRegistry) { |
|
115 | - throw new RuntimeException('Signals are not supported. Make sure that the `pcntl` extension is installed and that "pcntl_*" functions are not disabled by your php.ini\'s "disable_functions" directive.'); |
|
114 | + if ( ! $this->signalRegistry ) { |
|
115 | + throw new RuntimeException( 'Signals are not supported. Make sure that the `pcntl` extension is installed and that "pcntl_*" functions are not disabled by your php.ini\'s "disable_functions" directive.' ); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | return $this->signalRegistry; |
119 | 119 | } |
120 | 120 | |
121 | - public function setSignalsToDispatchEvent(int ...$signalsToDispatchEvent) |
|
121 | + public function setSignalsToDispatchEvent( int ...$signalsToDispatchEvent ) |
|
122 | 122 | { |
123 | 123 | $this->signalsToDispatchEvent = $signalsToDispatchEvent; |
124 | 124 | } |
@@ -130,52 +130,52 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @throws \Exception When running fails. Bypass this when {@link setCatchExceptions()}. |
132 | 132 | */ |
133 | - public function run(InputInterface $input = null, OutputInterface $output = null) |
|
133 | + public function run( InputInterface $input = null, OutputInterface $output = null ) |
|
134 | 134 | { |
135 | - if (\function_exists('putenv')) { |
|
136 | - @putenv('LINES='.$this->terminal->getHeight()); |
|
137 | - @putenv('COLUMNS='.$this->terminal->getWidth()); |
|
135 | + if ( \function_exists( 'putenv' ) ) { |
|
136 | + @putenv( 'LINES=' . $this->terminal->getHeight() ); |
|
137 | + @putenv( 'COLUMNS=' . $this->terminal->getWidth() ); |
|
138 | 138 | } |
139 | 139 | |
140 | - if (null === $input) { |
|
140 | + if ( null === $input ) { |
|
141 | 141 | $input = new ArgvInput(); |
142 | 142 | } |
143 | 143 | |
144 | - if (null === $output) { |
|
144 | + if ( null === $output ) { |
|
145 | 145 | $output = new ConsoleOutput(); |
146 | 146 | } |
147 | 147 | |
148 | - $renderException = function (\Throwable $e) use ($output) { |
|
149 | - if ($output instanceof ConsoleOutputInterface) { |
|
150 | - $this->renderThrowable($e, $output->getErrorOutput()); |
|
148 | + $renderException = function( \Throwable $e ) use ( $output ) { |
|
149 | + if ( $output instanceof ConsoleOutputInterface ) { |
|
150 | + $this->renderThrowable( $e, $output->getErrorOutput() ); |
|
151 | 151 | } else { |
152 | - $this->renderThrowable($e, $output); |
|
152 | + $this->renderThrowable( $e, $output ); |
|
153 | 153 | } |
154 | 154 | }; |
155 | - if ($phpHandler = set_exception_handler($renderException)) { |
|
155 | + if ( $phpHandler = set_exception_handler( $renderException ) ) { |
|
156 | 156 | restore_exception_handler(); |
157 | - if (!\is_array($phpHandler) || !$phpHandler[0] instanceof ErrorHandler) { |
|
157 | + if ( ! \is_array( $phpHandler ) || ! $phpHandler[ 0 ] instanceof ErrorHandler ) { |
|
158 | 158 | $errorHandler = true; |
159 | - } elseif ($errorHandler = $phpHandler[0]->setExceptionHandler($renderException)) { |
|
160 | - $phpHandler[0]->setExceptionHandler($errorHandler); |
|
159 | + } elseif ( $errorHandler = $phpHandler[ 0 ]->setExceptionHandler( $renderException ) ) { |
|
160 | + $phpHandler[ 0 ]->setExceptionHandler( $errorHandler ); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | - $this->configureIO($input, $output); |
|
164 | + $this->configureIO( $input, $output ); |
|
165 | 165 | |
166 | 166 | try { |
167 | - $exitCode = $this->doRun($input, $output); |
|
168 | - } catch (\Exception $e) { |
|
169 | - if (!$this->catchExceptions) { |
|
167 | + $exitCode = $this->doRun( $input, $output ); |
|
168 | + } catch ( \Exception $e ) { |
|
169 | + if ( ! $this->catchExceptions ) { |
|
170 | 170 | throw $e; |
171 | 171 | } |
172 | 172 | |
173 | - $renderException($e); |
|
173 | + $renderException( $e ); |
|
174 | 174 | |
175 | 175 | $exitCode = $e->getCode(); |
176 | - if (is_numeric($exitCode)) { |
|
177 | - $exitCode = (int) $exitCode; |
|
178 | - if (0 === $exitCode) { |
|
176 | + if ( is_numeric( $exitCode ) ) { |
|
177 | + $exitCode = (int)$exitCode; |
|
178 | + if ( 0 === $exitCode ) { |
|
179 | 179 | $exitCode = 1; |
180 | 180 | } |
181 | 181 | } else { |
@@ -184,25 +184,25 @@ discard block |
||
184 | 184 | } finally { |
185 | 185 | // if the exception handler changed, keep it |
186 | 186 | // otherwise, unregister $renderException |
187 | - if (!$phpHandler) { |
|
188 | - if (set_exception_handler($renderException) === $renderException) { |
|
187 | + if ( ! $phpHandler ) { |
|
188 | + if ( set_exception_handler( $renderException ) === $renderException ) { |
|
189 | 189 | restore_exception_handler(); |
190 | 190 | } |
191 | 191 | restore_exception_handler(); |
192 | - } elseif (!$errorHandler) { |
|
193 | - $finalHandler = $phpHandler[0]->setExceptionHandler(null); |
|
194 | - if ($finalHandler !== $renderException) { |
|
195 | - $phpHandler[0]->setExceptionHandler($finalHandler); |
|
192 | + } elseif ( ! $errorHandler ) { |
|
193 | + $finalHandler = $phpHandler[ 0 ]->setExceptionHandler( null ); |
|
194 | + if ( $finalHandler !== $renderException ) { |
|
195 | + $phpHandler[ 0 ]->setExceptionHandler( $finalHandler ); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | - if ($this->autoExit) { |
|
201 | - if ($exitCode > 255) { |
|
200 | + if ( $this->autoExit ) { |
|
201 | + if ( $exitCode > 255 ) { |
|
202 | 202 | $exitCode = 255; |
203 | 203 | } |
204 | 204 | |
205 | - exit($exitCode); |
|
205 | + exit( $exitCode ); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | return $exitCode; |
@@ -213,53 +213,53 @@ discard block |
||
213 | 213 | * |
214 | 214 | * @return int 0 if everything went fine, or an error code |
215 | 215 | */ |
216 | - public function doRun(InputInterface $input, OutputInterface $output) |
|
216 | + public function doRun( InputInterface $input, OutputInterface $output ) |
|
217 | 217 | { |
218 | - if (true === $input->hasParameterOption(['--version', '-V'], true)) { |
|
219 | - $output->writeln($this->getLongVersion()); |
|
218 | + if ( true === $input->hasParameterOption( [ '--version', '-V' ], true ) ) { |
|
219 | + $output->writeln( $this->getLongVersion() ); |
|
220 | 220 | |
221 | 221 | return 0; |
222 | 222 | } |
223 | 223 | |
224 | 224 | try { |
225 | 225 | // Makes ArgvInput::getFirstArgument() able to distinguish an option from an argument. |
226 | - $input->bind($this->getDefinition()); |
|
227 | - } catch (ExceptionInterface $e) { |
|
226 | + $input->bind( $this->getDefinition() ); |
|
227 | + } catch ( ExceptionInterface $e ) { |
|
228 | 228 | // Errors must be ignored, full binding/validation happens later when the command is known. |
229 | 229 | } |
230 | 230 | |
231 | - $name = $this->getCommandName($input); |
|
232 | - if (true === $input->hasParameterOption(['--help', '-h'], true)) { |
|
233 | - if (!$name) { |
|
231 | + $name = $this->getCommandName( $input ); |
|
232 | + if ( true === $input->hasParameterOption( [ '--help', '-h' ], true ) ) { |
|
233 | + if ( ! $name ) { |
|
234 | 234 | $name = 'help'; |
235 | - $input = new ArrayInput(['command_name' => $this->defaultCommand]); |
|
235 | + $input = new ArrayInput( [ 'command_name' => $this->defaultCommand ] ); |
|
236 | 236 | } else { |
237 | 237 | $this->wantHelps = true; |
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | - if (!$name) { |
|
241 | + if ( ! $name ) { |
|
242 | 242 | $name = $this->defaultCommand; |
243 | 243 | $definition = $this->getDefinition(); |
244 | - $definition->setArguments(array_merge( |
|
244 | + $definition->setArguments( array_merge( |
|
245 | 245 | $definition->getArguments(), |
246 | 246 | [ |
247 | - 'command' => new InputArgument('command', InputArgument::OPTIONAL, $definition->getArgument('command')->getDescription(), $name), |
|
247 | + 'command' => new InputArgument( 'command', InputArgument::OPTIONAL, $definition->getArgument( 'command' )->getDescription(), $name ), |
|
248 | 248 | ] |
249 | - )); |
|
249 | + ) ); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | try { |
253 | 253 | $this->runningCommand = null; |
254 | 254 | // the command name MUST be the first element of the input |
255 | - $command = $this->find($name); |
|
256 | - } catch (\Throwable $e) { |
|
257 | - if (!($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) || 1 !== \count($alternatives = $e->getAlternatives()) || !$input->isInteractive()) { |
|
258 | - if (null !== $this->dispatcher) { |
|
259 | - $event = new ConsoleErrorEvent($input, $output, $e); |
|
260 | - $this->dispatcher->dispatch($event, ConsoleEvents::ERROR); |
|
261 | - |
|
262 | - if (0 === $event->getExitCode()) { |
|
255 | + $command = $this->find( $name ); |
|
256 | + } catch ( \Throwable $e ) { |
|
257 | + if ( ! ( $e instanceof CommandNotFoundException && ! $e instanceof NamespaceNotFoundException ) || 1 !== \count( $alternatives = $e->getAlternatives() ) || ! $input->isInteractive() ) { |
|
258 | + if ( null !== $this->dispatcher ) { |
|
259 | + $event = new ConsoleErrorEvent( $input, $output, $e ); |
|
260 | + $this->dispatcher->dispatch( $event, ConsoleEvents::ERROR ); |
|
261 | + |
|
262 | + if ( 0 === $event->getExitCode() ) { |
|
263 | 263 | return 0; |
264 | 264 | } |
265 | 265 | |
@@ -269,14 +269,14 @@ discard block |
||
269 | 269 | throw $e; |
270 | 270 | } |
271 | 271 | |
272 | - $alternative = $alternatives[0]; |
|
272 | + $alternative = $alternatives[ 0 ]; |
|
273 | 273 | |
274 | - $style = new SymfonyStyle($input, $output); |
|
275 | - $style->block(sprintf("\nCommand \"%s\" is not defined.\n", $name), null, 'error'); |
|
276 | - if (!$style->confirm(sprintf('Do you want to run "%s" instead? ', $alternative), false)) { |
|
277 | - if (null !== $this->dispatcher) { |
|
278 | - $event = new ConsoleErrorEvent($input, $output, $e); |
|
279 | - $this->dispatcher->dispatch($event, ConsoleEvents::ERROR); |
|
274 | + $style = new SymfonyStyle( $input, $output ); |
|
275 | + $style->block( sprintf( "\nCommand \"%s\" is not defined.\n", $name ), null, 'error' ); |
|
276 | + if ( ! $style->confirm( sprintf( 'Do you want to run "%s" instead? ', $alternative ), false ) ) { |
|
277 | + if ( null !== $this->dispatcher ) { |
|
278 | + $event = new ConsoleErrorEvent( $input, $output, $e ); |
|
279 | + $this->dispatcher->dispatch( $event, ConsoleEvents::ERROR ); |
|
280 | 280 | |
281 | 281 | return $event->getExitCode(); |
282 | 282 | } |
@@ -284,15 +284,15 @@ discard block |
||
284 | 284 | return 1; |
285 | 285 | } |
286 | 286 | |
287 | - $command = $this->find($alternative); |
|
287 | + $command = $this->find( $alternative ); |
|
288 | 288 | } |
289 | 289 | |
290 | - if ($command instanceof LazyCommand) { |
|
290 | + if ( $command instanceof LazyCommand ) { |
|
291 | 291 | $command = $command->getCommand(); |
292 | 292 | } |
293 | 293 | |
294 | 294 | $this->runningCommand = $command; |
295 | - $exitCode = $this->doRunCommand($command, $input, $output); |
|
295 | + $exitCode = $this->doRunCommand( $command, $input, $output ); |
|
296 | 296 | $this->runningCommand = null; |
297 | 297 | |
298 | 298 | return $exitCode; |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | { |
306 | 306 | } |
307 | 307 | |
308 | - public function setHelperSet(HelperSet $helperSet) |
|
308 | + public function setHelperSet( HelperSet $helperSet ) |
|
309 | 309 | { |
310 | 310 | $this->helperSet = $helperSet; |
311 | 311 | } |
@@ -317,14 +317,14 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function getHelperSet() |
319 | 319 | { |
320 | - if (!$this->helperSet) { |
|
320 | + if ( ! $this->helperSet ) { |
|
321 | 321 | $this->helperSet = $this->getDefaultHelperSet(); |
322 | 322 | } |
323 | 323 | |
324 | 324 | return $this->helperSet; |
325 | 325 | } |
326 | 326 | |
327 | - public function setDefinition(InputDefinition $definition) |
|
327 | + public function setDefinition( InputDefinition $definition ) |
|
328 | 328 | { |
329 | 329 | $this->definition = $definition; |
330 | 330 | } |
@@ -336,11 +336,11 @@ discard block |
||
336 | 336 | */ |
337 | 337 | public function getDefinition() |
338 | 338 | { |
339 | - if (!$this->definition) { |
|
339 | + if ( ! $this->definition ) { |
|
340 | 340 | $this->definition = $this->getDefaultInputDefinition(); |
341 | 341 | } |
342 | 342 | |
343 | - if ($this->singleCommand) { |
|
343 | + if ( $this->singleCommand ) { |
|
344 | 344 | $inputDefinition = $this->definition; |
345 | 345 | $inputDefinition->setArguments(); |
346 | 346 | |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | /** |
374 | 374 | * Sets whether to catch exceptions or not during commands execution. |
375 | 375 | */ |
376 | - public function setCatchExceptions(bool $boolean) |
|
376 | + public function setCatchExceptions( bool $boolean ) |
|
377 | 377 | { |
378 | 378 | $this->catchExceptions = $boolean; |
379 | 379 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | /** |
392 | 392 | * Sets whether to automatically exit after a command execution or not. |
393 | 393 | */ |
394 | - public function setAutoExit(bool $boolean) |
|
394 | + public function setAutoExit( bool $boolean ) |
|
395 | 395 | { |
396 | 396 | $this->autoExit = $boolean; |
397 | 397 | } |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | /** |
410 | 410 | * Sets the application name. |
411 | 411 | **/ |
412 | - public function setName(string $name) |
|
412 | + public function setName( string $name ) |
|
413 | 413 | { |
414 | 414 | $this->name = $name; |
415 | 415 | } |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | /** |
428 | 428 | * Sets the application version. |
429 | 429 | */ |
430 | - public function setVersion(string $version) |
|
430 | + public function setVersion( string $version ) |
|
431 | 431 | { |
432 | 432 | $this->version = $version; |
433 | 433 | } |
@@ -439,9 +439,9 @@ discard block |
||
439 | 439 | */ |
440 | 440 | public function getLongVersion() |
441 | 441 | { |
442 | - if ('UNKNOWN' !== $this->getName()) { |
|
443 | - if ('UNKNOWN' !== $this->getVersion()) { |
|
444 | - return sprintf('%s <info>%s</info>', $this->getName(), $this->getVersion()); |
|
442 | + if ( 'UNKNOWN' !== $this->getName() ) { |
|
443 | + if ( 'UNKNOWN' !== $this->getVersion() ) { |
|
444 | + return sprintf( '%s <info>%s</info>', $this->getName(), $this->getVersion() ); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | return $this->getName(); |
@@ -455,9 +455,9 @@ discard block |
||
455 | 455 | * |
456 | 456 | * @return Command The newly created command |
457 | 457 | */ |
458 | - public function register(string $name) |
|
458 | + public function register( string $name ) |
|
459 | 459 | { |
460 | - return $this->add(new Command($name)); |
|
460 | + return $this->add( new Command( $name ) ); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
@@ -467,10 +467,10 @@ discard block |
||
467 | 467 | * |
468 | 468 | * @param Command[] $commands An array of commands |
469 | 469 | */ |
470 | - public function addCommands(array $commands) |
|
470 | + public function addCommands( array $commands ) |
|
471 | 471 | { |
472 | - foreach ($commands as $command) { |
|
473 | - $this->add($command); |
|
472 | + foreach ( $commands as $command ) { |
|
473 | + $this->add( $command ); |
|
474 | 474 | } |
475 | 475 | } |
476 | 476 | |
@@ -482,31 +482,31 @@ discard block |
||
482 | 482 | * |
483 | 483 | * @return Command|null The registered command if enabled or null |
484 | 484 | */ |
485 | - public function add(Command $command) |
|
485 | + public function add( Command $command ) |
|
486 | 486 | { |
487 | 487 | $this->init(); |
488 | 488 | |
489 | - $command->setApplication($this); |
|
489 | + $command->setApplication( $this ); |
|
490 | 490 | |
491 | - if (!$command->isEnabled()) { |
|
492 | - $command->setApplication(null); |
|
491 | + if ( ! $command->isEnabled() ) { |
|
492 | + $command->setApplication( null ); |
|
493 | 493 | |
494 | 494 | return null; |
495 | 495 | } |
496 | 496 | |
497 | - if (!$command instanceof LazyCommand) { |
|
497 | + if ( ! $command instanceof LazyCommand ) { |
|
498 | 498 | // Will throw if the command is not correctly initialized. |
499 | 499 | $command->getDefinition(); |
500 | 500 | } |
501 | 501 | |
502 | - if (!$command->getName()) { |
|
503 | - throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_debug_type($command))); |
|
502 | + if ( ! $command->getName() ) { |
|
503 | + throw new LogicException( sprintf( 'The command defined in "%s" cannot have an empty name.', get_debug_type( $command ) ) ); |
|
504 | 504 | } |
505 | 505 | |
506 | - $this->commands[$command->getName()] = $command; |
|
506 | + $this->commands[ $command->getName() ] = $command; |
|
507 | 507 | |
508 | - foreach ($command->getAliases() as $alias) { |
|
509 | - $this->commands[$alias] = $command; |
|
508 | + foreach ( $command->getAliases() as $alias ) { |
|
509 | + $this->commands[ $alias ] = $command; |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | return $command; |
@@ -519,26 +519,26 @@ discard block |
||
519 | 519 | * |
520 | 520 | * @throws CommandNotFoundException When given command name does not exist |
521 | 521 | */ |
522 | - public function get(string $name) |
|
522 | + public function get( string $name ) |
|
523 | 523 | { |
524 | 524 | $this->init(); |
525 | 525 | |
526 | - if (!$this->has($name)) { |
|
527 | - throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name)); |
|
526 | + if ( ! $this->has( $name ) ) { |
|
527 | + throw new CommandNotFoundException( sprintf( 'The command "%s" does not exist.', $name ) ); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | // When the command has a different name than the one used at the command loader level |
531 | - if (!isset($this->commands[$name])) { |
|
532 | - throw new CommandNotFoundException(sprintf('The "%s" command cannot be found because it is registered under multiple names. Make sure you don\'t set a different name via constructor or "setName()".', $name)); |
|
531 | + if ( ! isset( $this->commands[ $name ] ) ) { |
|
532 | + throw new CommandNotFoundException( sprintf( 'The "%s" command cannot be found because it is registered under multiple names. Make sure you don\'t set a different name via constructor or "setName()".', $name ) ); |
|
533 | 533 | } |
534 | 534 | |
535 | - $command = $this->commands[$name]; |
|
535 | + $command = $this->commands[ $name ]; |
|
536 | 536 | |
537 | - if ($this->wantHelps) { |
|
537 | + if ( $this->wantHelps ) { |
|
538 | 538 | $this->wantHelps = false; |
539 | 539 | |
540 | - $helpCommand = $this->get('help'); |
|
541 | - $helpCommand->setCommand($command); |
|
540 | + $helpCommand = $this->get( 'help' ); |
|
541 | + $helpCommand->setCommand( $command ); |
|
542 | 542 | |
543 | 543 | return $helpCommand; |
544 | 544 | } |
@@ -551,11 +551,11 @@ discard block |
||
551 | 551 | * |
552 | 552 | * @return bool true if the command exists, false otherwise |
553 | 553 | */ |
554 | - public function has(string $name) |
|
554 | + public function has( string $name ) |
|
555 | 555 | { |
556 | 556 | $this->init(); |
557 | 557 | |
558 | - return isset($this->commands[$name]) || ($this->commandLoader && $this->commandLoader->has($name) && $this->add($this->commandLoader->get($name))); |
|
558 | + return isset( $this->commands[ $name ] ) || ( $this->commandLoader && $this->commandLoader->has( $name ) && $this->add( $this->commandLoader->get( $name ) ) ); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | /** |
@@ -567,20 +567,20 @@ discard block |
||
567 | 567 | */ |
568 | 568 | public function getNamespaces() |
569 | 569 | { |
570 | - $namespaces = []; |
|
571 | - foreach ($this->all() as $command) { |
|
572 | - if ($command->isHidden()) { |
|
570 | + $namespaces = [ ]; |
|
571 | + foreach ( $this->all() as $command ) { |
|
572 | + if ( $command->isHidden() ) { |
|
573 | 573 | continue; |
574 | 574 | } |
575 | 575 | |
576 | - $namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName())); |
|
576 | + $namespaces = array_merge( $namespaces, $this->extractAllNamespaces( $command->getName() ) ); |
|
577 | 577 | |
578 | - foreach ($command->getAliases() as $alias) { |
|
579 | - $namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias)); |
|
578 | + foreach ( $command->getAliases() as $alias ) { |
|
579 | + $namespaces = array_merge( $namespaces, $this->extractAllNamespaces( $alias ) ); |
|
580 | 580 | } |
581 | 581 | } |
582 | 582 | |
583 | - return array_values(array_unique(array_filter($namespaces))); |
|
583 | + return array_values( array_unique( array_filter( $namespaces ) ) ); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -590,34 +590,34 @@ discard block |
||
590 | 590 | * |
591 | 591 | * @throws NamespaceNotFoundException When namespace is incorrect or ambiguous |
592 | 592 | */ |
593 | - public function findNamespace(string $namespace) |
|
593 | + public function findNamespace( string $namespace ) |
|
594 | 594 | { |
595 | 595 | $allNamespaces = $this->getNamespaces(); |
596 | - $expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))).'[^:]*'; |
|
597 | - $namespaces = preg_grep('{^'.$expr.'}', $allNamespaces); |
|
596 | + $expr = implode( '[^:]*:', array_map( 'preg_quote', explode( ':', $namespace ) ) ) . '[^:]*'; |
|
597 | + $namespaces = preg_grep( '{^' . $expr . '}', $allNamespaces ); |
|
598 | 598 | |
599 | - if (empty($namespaces)) { |
|
600 | - $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace); |
|
599 | + if ( empty( $namespaces ) ) { |
|
600 | + $message = sprintf( 'There are no commands defined in the "%s" namespace.', $namespace ); |
|
601 | 601 | |
602 | - if ($alternatives = $this->findAlternatives($namespace, $allNamespaces)) { |
|
603 | - if (1 == \count($alternatives)) { |
|
602 | + if ( $alternatives = $this->findAlternatives( $namespace, $allNamespaces ) ) { |
|
603 | + if ( 1 == \count( $alternatives ) ) { |
|
604 | 604 | $message .= "\n\nDid you mean this?\n "; |
605 | 605 | } else { |
606 | 606 | $message .= "\n\nDid you mean one of these?\n "; |
607 | 607 | } |
608 | 608 | |
609 | - $message .= implode("\n ", $alternatives); |
|
609 | + $message .= implode( "\n ", $alternatives ); |
|
610 | 610 | } |
611 | 611 | |
612 | - throw new NamespaceNotFoundException($message, $alternatives); |
|
612 | + throw new NamespaceNotFoundException( $message, $alternatives ); |
|
613 | 613 | } |
614 | 614 | |
615 | - $exact = \in_array($namespace, $namespaces, true); |
|
616 | - if (\count($namespaces) > 1 && !$exact) { |
|
617 | - throw new NamespaceNotFoundException(sprintf("The namespace \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))), array_values($namespaces)); |
|
615 | + $exact = \in_array( $namespace, $namespaces, true ); |
|
616 | + if ( \count( $namespaces ) > 1 && ! $exact ) { |
|
617 | + throw new NamespaceNotFoundException( sprintf( "The namespace \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", $namespace, $this->getAbbreviationSuggestions( array_values( $namespaces ) ) ), array_values( $namespaces ) ); |
|
618 | 618 | } |
619 | 619 | |
620 | - return $exact ? $namespace : reset($namespaces); |
|
620 | + return $exact ? $namespace : reset( $namespaces ); |
|
621 | 621 | } |
622 | 622 | |
623 | 623 | /** |
@@ -630,104 +630,104 @@ discard block |
||
630 | 630 | * |
631 | 631 | * @throws CommandNotFoundException When command name is incorrect or ambiguous |
632 | 632 | */ |
633 | - public function find(string $name) |
|
633 | + public function find( string $name ) |
|
634 | 634 | { |
635 | 635 | $this->init(); |
636 | 636 | |
637 | - $aliases = []; |
|
637 | + $aliases = [ ]; |
|
638 | 638 | |
639 | - foreach ($this->commands as $command) { |
|
640 | - foreach ($command->getAliases() as $alias) { |
|
641 | - if (!$this->has($alias)) { |
|
642 | - $this->commands[$alias] = $command; |
|
639 | + foreach ( $this->commands as $command ) { |
|
640 | + foreach ( $command->getAliases() as $alias ) { |
|
641 | + if ( ! $this->has( $alias ) ) { |
|
642 | + $this->commands[ $alias ] = $command; |
|
643 | 643 | } |
644 | 644 | } |
645 | 645 | } |
646 | 646 | |
647 | - if ($this->has($name)) { |
|
648 | - return $this->get($name); |
|
647 | + if ( $this->has( $name ) ) { |
|
648 | + return $this->get( $name ); |
|
649 | 649 | } |
650 | 650 | |
651 | - $allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands); |
|
652 | - $expr = implode('[^:]*:', array_map('preg_quote', explode(':', $name))).'[^:]*'; |
|
653 | - $commands = preg_grep('{^'.$expr.'}', $allCommands); |
|
651 | + $allCommands = $this->commandLoader ? array_merge( $this->commandLoader->getNames(), array_keys( $this->commands ) ) : array_keys( $this->commands ); |
|
652 | + $expr = implode( '[^:]*:', array_map( 'preg_quote', explode( ':', $name ) ) ) . '[^:]*'; |
|
653 | + $commands = preg_grep( '{^' . $expr . '}', $allCommands ); |
|
654 | 654 | |
655 | - if (empty($commands)) { |
|
656 | - $commands = preg_grep('{^'.$expr.'}i', $allCommands); |
|
655 | + if ( empty( $commands ) ) { |
|
656 | + $commands = preg_grep( '{^' . $expr . '}i', $allCommands ); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | // if no commands matched or we just matched namespaces |
660 | - if (empty($commands) || \count(preg_grep('{^'.$expr.'$}i', $commands)) < 1) { |
|
661 | - if (false !== $pos = strrpos($name, ':')) { |
|
660 | + if ( empty( $commands ) || \count( preg_grep( '{^' . $expr . '$}i', $commands ) ) < 1 ) { |
|
661 | + if ( false !== $pos = strrpos( $name, ':' ) ) { |
|
662 | 662 | // check if a namespace exists and contains commands |
663 | - $this->findNamespace(substr($name, 0, $pos)); |
|
663 | + $this->findNamespace( substr( $name, 0, $pos ) ); |
|
664 | 664 | } |
665 | 665 | |
666 | - $message = sprintf('Command "%s" is not defined.', $name); |
|
666 | + $message = sprintf( 'Command "%s" is not defined.', $name ); |
|
667 | 667 | |
668 | - if ($alternatives = $this->findAlternatives($name, $allCommands)) { |
|
668 | + if ( $alternatives = $this->findAlternatives( $name, $allCommands ) ) { |
|
669 | 669 | // remove hidden commands |
670 | - $alternatives = array_filter($alternatives, function ($name) { |
|
671 | - return !$this->get($name)->isHidden(); |
|
670 | + $alternatives = array_filter( $alternatives, function( $name ) { |
|
671 | + return ! $this->get( $name )->isHidden(); |
|
672 | 672 | }); |
673 | 673 | |
674 | - if (1 == \count($alternatives)) { |
|
674 | + if ( 1 == \count( $alternatives ) ) { |
|
675 | 675 | $message .= "\n\nDid you mean this?\n "; |
676 | 676 | } else { |
677 | 677 | $message .= "\n\nDid you mean one of these?\n "; |
678 | 678 | } |
679 | - $message .= implode("\n ", $alternatives); |
|
679 | + $message .= implode( "\n ", $alternatives ); |
|
680 | 680 | } |
681 | 681 | |
682 | - throw new CommandNotFoundException($message, array_values($alternatives)); |
|
682 | + throw new CommandNotFoundException( $message, array_values( $alternatives ) ); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | // filter out aliases for commands which are already on the list |
686 | - if (\count($commands) > 1) { |
|
687 | - $commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands; |
|
688 | - $commands = array_unique(array_filter($commands, function ($nameOrAlias) use (&$commandList, $commands, &$aliases) { |
|
689 | - if (!$commandList[$nameOrAlias] instanceof Command) { |
|
690 | - $commandList[$nameOrAlias] = $this->commandLoader->get($nameOrAlias); |
|
686 | + if ( \count( $commands ) > 1 ) { |
|
687 | + $commandList = $this->commandLoader ? array_merge( array_flip( $this->commandLoader->getNames() ), $this->commands ) : $this->commands; |
|
688 | + $commands = array_unique( array_filter( $commands, function( $nameOrAlias ) use ( &$commandList, $commands, &$aliases ) { |
|
689 | + if ( ! $commandList[ $nameOrAlias ] instanceof Command ) { |
|
690 | + $commandList[ $nameOrAlias ] = $this->commandLoader->get( $nameOrAlias ); |
|
691 | 691 | } |
692 | 692 | |
693 | - $commandName = $commandList[$nameOrAlias]->getName(); |
|
693 | + $commandName = $commandList[ $nameOrAlias ]->getName(); |
|
694 | 694 | |
695 | - $aliases[$nameOrAlias] = $commandName; |
|
695 | + $aliases[ $nameOrAlias ] = $commandName; |
|
696 | 696 | |
697 | - return $commandName === $nameOrAlias || !\in_array($commandName, $commands); |
|
698 | - })); |
|
697 | + return $commandName === $nameOrAlias || ! \in_array( $commandName, $commands ); |
|
698 | + }) ); |
|
699 | 699 | } |
700 | 700 | |
701 | - if (\count($commands) > 1) { |
|
701 | + if ( \count( $commands ) > 1 ) { |
|
702 | 702 | $usableWidth = $this->terminal->getWidth() - 10; |
703 | - $abbrevs = array_values($commands); |
|
703 | + $abbrevs = array_values( $commands ); |
|
704 | 704 | $maxLen = 0; |
705 | - foreach ($abbrevs as $abbrev) { |
|
706 | - $maxLen = max(Helper::width($abbrev), $maxLen); |
|
705 | + foreach ( $abbrevs as $abbrev ) { |
|
706 | + $maxLen = max( Helper::width( $abbrev ), $maxLen ); |
|
707 | 707 | } |
708 | - $abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen, &$commands) { |
|
709 | - if ($commandList[$cmd]->isHidden()) { |
|
710 | - unset($commands[array_search($cmd, $commands)]); |
|
708 | + $abbrevs = array_map( function( $cmd ) use ( $commandList, $usableWidth, $maxLen, &$commands ) { |
|
709 | + if ( $commandList[ $cmd ]->isHidden() ) { |
|
710 | + unset( $commands[ array_search( $cmd, $commands ) ] ); |
|
711 | 711 | |
712 | 712 | return false; |
713 | 713 | } |
714 | 714 | |
715 | - $abbrev = str_pad($cmd, $maxLen, ' ').' '.$commandList[$cmd]->getDescription(); |
|
715 | + $abbrev = str_pad( $cmd, $maxLen, ' ' ) . ' ' . $commandList[ $cmd ]->getDescription(); |
|
716 | 716 | |
717 | - return Helper::width($abbrev) > $usableWidth ? Helper::substr($abbrev, 0, $usableWidth - 3).'...' : $abbrev; |
|
718 | - }, array_values($commands)); |
|
717 | + return Helper::width( $abbrev ) > $usableWidth ? Helper::substr( $abbrev, 0, $usableWidth - 3 ) . '...' : $abbrev; |
|
718 | + }, array_values( $commands ) ); |
|
719 | 719 | |
720 | - if (\count($commands) > 1) { |
|
721 | - $suggestions = $this->getAbbreviationSuggestions(array_filter($abbrevs)); |
|
720 | + if ( \count( $commands ) > 1 ) { |
|
721 | + $suggestions = $this->getAbbreviationSuggestions( array_filter( $abbrevs ) ); |
|
722 | 722 | |
723 | - throw new CommandNotFoundException(sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", $name, $suggestions), array_values($commands)); |
|
723 | + throw new CommandNotFoundException( sprintf( "Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", $name, $suggestions ), array_values( $commands ) ); |
|
724 | 724 | } |
725 | 725 | } |
726 | 726 | |
727 | - $command = $this->get(reset($commands)); |
|
727 | + $command = $this->get( reset( $commands ) ); |
|
728 | 728 | |
729 | - if ($command->isHidden()) { |
|
730 | - throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name)); |
|
729 | + if ( $command->isHidden() ) { |
|
730 | + throw new CommandNotFoundException( sprintf( 'The command "%s" does not exist.', $name ) ); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | return $command; |
@@ -740,36 +740,36 @@ discard block |
||
740 | 740 | * |
741 | 741 | * @return Command[] An array of Command instances |
742 | 742 | */ |
743 | - public function all(string $namespace = null) |
|
743 | + public function all( string $namespace = null ) |
|
744 | 744 | { |
745 | 745 | $this->init(); |
746 | 746 | |
747 | - if (null === $namespace) { |
|
748 | - if (!$this->commandLoader) { |
|
747 | + if ( null === $namespace ) { |
|
748 | + if ( ! $this->commandLoader ) { |
|
749 | 749 | return $this->commands; |
750 | 750 | } |
751 | 751 | |
752 | 752 | $commands = $this->commands; |
753 | - foreach ($this->commandLoader->getNames() as $name) { |
|
754 | - if (!isset($commands[$name]) && $this->has($name)) { |
|
755 | - $commands[$name] = $this->get($name); |
|
753 | + foreach ( $this->commandLoader->getNames() as $name ) { |
|
754 | + if ( ! isset( $commands[ $name ] ) && $this->has( $name ) ) { |
|
755 | + $commands[ $name ] = $this->get( $name ); |
|
756 | 756 | } |
757 | 757 | } |
758 | 758 | |
759 | 759 | return $commands; |
760 | 760 | } |
761 | 761 | |
762 | - $commands = []; |
|
763 | - foreach ($this->commands as $name => $command) { |
|
764 | - if ($namespace === $this->extractNamespace($name, substr_count($namespace, ':') + 1)) { |
|
765 | - $commands[$name] = $command; |
|
762 | + $commands = [ ]; |
|
763 | + foreach ( $this->commands as $name => $command ) { |
|
764 | + if ( $namespace === $this->extractNamespace( $name, substr_count( $namespace, ':' ) + 1 ) ) { |
|
765 | + $commands[ $name ] = $command; |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | |
769 | - if ($this->commandLoader) { |
|
770 | - foreach ($this->commandLoader->getNames() as $name) { |
|
771 | - if (!isset($commands[$name]) && $namespace === $this->extractNamespace($name, substr_count($namespace, ':') + 1) && $this->has($name)) { |
|
772 | - $commands[$name] = $this->get($name); |
|
769 | + if ( $this->commandLoader ) { |
|
770 | + foreach ( $this->commandLoader->getNames() as $name ) { |
|
771 | + if ( ! isset( $commands[ $name ] ) && $namespace === $this->extractNamespace( $name, substr_count( $namespace, ':' ) + 1 ) && $this->has( $name ) ) { |
|
772 | + $commands[ $name ] = $this->get( $name ); |
|
773 | 773 | } |
774 | 774 | } |
775 | 775 | } |
@@ -782,153 +782,153 @@ discard block |
||
782 | 782 | * |
783 | 783 | * @return string[][] An array of abbreviations |
784 | 784 | */ |
785 | - public static function getAbbreviations(array $names) |
|
785 | + public static function getAbbreviations( array $names ) |
|
786 | 786 | { |
787 | - $abbrevs = []; |
|
788 | - foreach ($names as $name) { |
|
789 | - for ($len = \strlen($name); $len > 0; --$len) { |
|
790 | - $abbrev = substr($name, 0, $len); |
|
791 | - $abbrevs[$abbrev][] = $name; |
|
787 | + $abbrevs = [ ]; |
|
788 | + foreach ( $names as $name ) { |
|
789 | + for ( $len = \strlen( $name ); $len > 0; --$len ) { |
|
790 | + $abbrev = substr( $name, 0, $len ); |
|
791 | + $abbrevs[ $abbrev ][ ] = $name; |
|
792 | 792 | } |
793 | 793 | } |
794 | 794 | |
795 | 795 | return $abbrevs; |
796 | 796 | } |
797 | 797 | |
798 | - public function renderThrowable(\Throwable $e, OutputInterface $output): void |
|
798 | + public function renderThrowable( \Throwable $e, OutputInterface $output ): void |
|
799 | 799 | { |
800 | - $output->writeln('', OutputInterface::VERBOSITY_QUIET); |
|
800 | + $output->writeln( '', OutputInterface::VERBOSITY_QUIET ); |
|
801 | 801 | |
802 | - $this->doRenderThrowable($e, $output); |
|
802 | + $this->doRenderThrowable( $e, $output ); |
|
803 | 803 | |
804 | - if (null !== $this->runningCommand) { |
|
805 | - $output->writeln(sprintf('<info>%s</info>', OutputFormatter::escape(sprintf($this->runningCommand->getSynopsis(), $this->getName()))), OutputInterface::VERBOSITY_QUIET); |
|
806 | - $output->writeln('', OutputInterface::VERBOSITY_QUIET); |
|
804 | + if ( null !== $this->runningCommand ) { |
|
805 | + $output->writeln( sprintf( '<info>%s</info>', OutputFormatter::escape( sprintf( $this->runningCommand->getSynopsis(), $this->getName() ) ) ), OutputInterface::VERBOSITY_QUIET ); |
|
806 | + $output->writeln( '', OutputInterface::VERBOSITY_QUIET ); |
|
807 | 807 | } |
808 | 808 | } |
809 | 809 | |
810 | - protected function doRenderThrowable(\Throwable $e, OutputInterface $output): void |
|
810 | + protected function doRenderThrowable( \Throwable $e, OutputInterface $output ): void |
|
811 | 811 | { |
812 | 812 | do { |
813 | - $message = trim($e->getMessage()); |
|
814 | - if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
815 | - $class = get_debug_type($e); |
|
816 | - $title = sprintf(' [%s%s] ', $class, 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : ''); |
|
817 | - $len = Helper::width($title); |
|
813 | + $message = trim( $e->getMessage() ); |
|
814 | + if ( '' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity() ) { |
|
815 | + $class = get_debug_type( $e ); |
|
816 | + $title = sprintf( ' [%s%s] ', $class, 0 !== ( $code = $e->getCode() ) ? ' (' . $code . ')' : '' ); |
|
817 | + $len = Helper::width( $title ); |
|
818 | 818 | } else { |
819 | 819 | $len = 0; |
820 | 820 | } |
821 | 821 | |
822 | - if (str_contains($message, "@anonymous\0")) { |
|
823 | - $message = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) { |
|
824 | - return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0]; |
|
825 | - }, $message); |
|
822 | + if ( str_contains( $message, "@anonymous\0" ) ) { |
|
823 | + $message = preg_replace_callback( '/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function( $m ) { |
|
824 | + return class_exists( $m[ 0 ], false ) ? ( get_parent_class( $m[ 0 ] ) ?: key( class_implements( $m[ 0 ] ) ) ?: 'class' ) . '@anonymous' : $m[ 0 ]; |
|
825 | + }, $message ); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | $width = $this->terminal->getWidth() ? $this->terminal->getWidth() - 1 : \PHP_INT_MAX; |
829 | - $lines = []; |
|
830 | - foreach ('' !== $message ? preg_split('/\r?\n/', $message) : [] as $line) { |
|
831 | - foreach ($this->splitStringByWidth($line, $width - 4) as $line) { |
|
829 | + $lines = [ ]; |
|
830 | + foreach ( '' !== $message ? preg_split( '/\r?\n/', $message ) : [ ] as $line ) { |
|
831 | + foreach ( $this->splitStringByWidth( $line, $width - 4 ) as $line ) { |
|
832 | 832 | // pre-format lines to get the right string length |
833 | - $lineLength = Helper::width($line) + 4; |
|
834 | - $lines[] = [$line, $lineLength]; |
|
833 | + $lineLength = Helper::width( $line ) + 4; |
|
834 | + $lines[ ] = [ $line, $lineLength ]; |
|
835 | 835 | |
836 | - $len = max($lineLength, $len); |
|
836 | + $len = max( $lineLength, $len ); |
|
837 | 837 | } |
838 | 838 | } |
839 | 839 | |
840 | - $messages = []; |
|
841 | - if (!$e instanceof ExceptionInterface || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
842 | - $messages[] = sprintf('<comment>%s</comment>', OutputFormatter::escape(sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a'))); |
|
840 | + $messages = [ ]; |
|
841 | + if ( ! $e instanceof ExceptionInterface || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity() ) { |
|
842 | + $messages[ ] = sprintf( '<comment>%s</comment>', OutputFormatter::escape( sprintf( 'In %s line %s:', basename( $e->getFile() ) ?: 'n/a', $e->getLine() ?: 'n/a' ) ) ); |
|
843 | 843 | } |
844 | - $messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len)); |
|
845 | - if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
846 | - $messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::width($title)))); |
|
844 | + $messages[ ] = $emptyLine = sprintf( '<error>%s</error>', str_repeat( ' ', $len ) ); |
|
845 | + if ( '' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity() ) { |
|
846 | + $messages[ ] = sprintf( '<error>%s%s</error>', $title, str_repeat( ' ', max( 0, $len - Helper::width( $title ) ) ) ); |
|
847 | 847 | } |
848 | - foreach ($lines as $line) { |
|
849 | - $messages[] = sprintf('<error> %s %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1])); |
|
848 | + foreach ( $lines as $line ) { |
|
849 | + $messages[ ] = sprintf( '<error> %s %s</error>', OutputFormatter::escape( $line[ 0 ] ), str_repeat( ' ', $len - $line[ 1 ] ) ); |
|
850 | 850 | } |
851 | - $messages[] = $emptyLine; |
|
852 | - $messages[] = ''; |
|
851 | + $messages[ ] = $emptyLine; |
|
852 | + $messages[ ] = ''; |
|
853 | 853 | |
854 | - $output->writeln($messages, OutputInterface::VERBOSITY_QUIET); |
|
854 | + $output->writeln( $messages, OutputInterface::VERBOSITY_QUIET ); |
|
855 | 855 | |
856 | - if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
857 | - $output->writeln('<comment>Exception trace:</comment>', OutputInterface::VERBOSITY_QUIET); |
|
856 | + if ( OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity() ) { |
|
857 | + $output->writeln( '<comment>Exception trace:</comment>', OutputInterface::VERBOSITY_QUIET ); |
|
858 | 858 | |
859 | 859 | // exception related properties |
860 | 860 | $trace = $e->getTrace(); |
861 | 861 | |
862 | - array_unshift($trace, [ |
|
862 | + array_unshift( $trace, [ |
|
863 | 863 | 'function' => '', |
864 | 864 | 'file' => $e->getFile() ?: 'n/a', |
865 | 865 | 'line' => $e->getLine() ?: 'n/a', |
866 | - 'args' => [], |
|
867 | - ]); |
|
866 | + 'args' => [ ], |
|
867 | + ] ); |
|
868 | 868 | |
869 | - for ($i = 0, $count = \count($trace); $i < $count; ++$i) { |
|
870 | - $class = $trace[$i]['class'] ?? ''; |
|
871 | - $type = $trace[$i]['type'] ?? ''; |
|
872 | - $function = $trace[$i]['function'] ?? ''; |
|
873 | - $file = $trace[$i]['file'] ?? 'n/a'; |
|
874 | - $line = $trace[$i]['line'] ?? 'n/a'; |
|
869 | + for ( $i = 0, $count = \count( $trace ); $i < $count; ++$i ) { |
|
870 | + $class = $trace[ $i ][ 'class' ] ?? ''; |
|
871 | + $type = $trace[ $i ][ 'type' ] ?? ''; |
|
872 | + $function = $trace[ $i ][ 'function' ] ?? ''; |
|
873 | + $file = $trace[ $i ][ 'file' ] ?? 'n/a'; |
|
874 | + $line = $trace[ $i ][ 'line' ] ?? 'n/a'; |
|
875 | 875 | |
876 | - $output->writeln(sprintf(' %s%s at <info>%s:%s</info>', $class, $function ? $type.$function.'()' : '', $file, $line), OutputInterface::VERBOSITY_QUIET); |
|
876 | + $output->writeln( sprintf( ' %s%s at <info>%s:%s</info>', $class, $function ? $type . $function . '()' : '', $file, $line ), OutputInterface::VERBOSITY_QUIET ); |
|
877 | 877 | } |
878 | 878 | |
879 | - $output->writeln('', OutputInterface::VERBOSITY_QUIET); |
|
879 | + $output->writeln( '', OutputInterface::VERBOSITY_QUIET ); |
|
880 | 880 | } |
881 | - } while ($e = $e->getPrevious()); |
|
881 | + } while ( $e = $e->getPrevious() ); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | /** |
885 | 885 | * Configures the input and output instances based on the user arguments and options. |
886 | 886 | */ |
887 | - protected function configureIO(InputInterface $input, OutputInterface $output) |
|
887 | + protected function configureIO( InputInterface $input, OutputInterface $output ) |
|
888 | 888 | { |
889 | - if (true === $input->hasParameterOption(['--ansi'], true)) { |
|
890 | - $output->setDecorated(true); |
|
891 | - } elseif (true === $input->hasParameterOption(['--no-ansi'], true)) { |
|
892 | - $output->setDecorated(false); |
|
889 | + if ( true === $input->hasParameterOption( [ '--ansi' ], true ) ) { |
|
890 | + $output->setDecorated( true ); |
|
891 | + } elseif ( true === $input->hasParameterOption( [ '--no-ansi' ], true ) ) { |
|
892 | + $output->setDecorated( false ); |
|
893 | 893 | } |
894 | 894 | |
895 | - if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) { |
|
896 | - $input->setInteractive(false); |
|
895 | + if ( true === $input->hasParameterOption( [ '--no-interaction', '-n' ], true ) ) { |
|
896 | + $input->setInteractive( false ); |
|
897 | 897 | } |
898 | 898 | |
899 | - switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) { |
|
900 | - case -1: $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); break; |
|
901 | - case 1: $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); break; |
|
902 | - case 2: $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); break; |
|
903 | - case 3: $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); break; |
|
899 | + switch ( $shellVerbosity = (int)getenv( 'SHELL_VERBOSITY' ) ) { |
|
900 | + case -1: $output->setVerbosity( OutputInterface::VERBOSITY_QUIET ); break; |
|
901 | + case 1: $output->setVerbosity( OutputInterface::VERBOSITY_VERBOSE ); break; |
|
902 | + case 2: $output->setVerbosity( OutputInterface::VERBOSITY_VERY_VERBOSE ); break; |
|
903 | + case 3: $output->setVerbosity( OutputInterface::VERBOSITY_DEBUG ); break; |
|
904 | 904 | default: $shellVerbosity = 0; break; |
905 | 905 | } |
906 | 906 | |
907 | - if (true === $input->hasParameterOption(['--quiet', '-q'], true)) { |
|
908 | - $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
|
907 | + if ( true === $input->hasParameterOption( [ '--quiet', '-q' ], true ) ) { |
|
908 | + $output->setVerbosity( OutputInterface::VERBOSITY_QUIET ); |
|
909 | 909 | $shellVerbosity = -1; |
910 | 910 | } else { |
911 | - if ($input->hasParameterOption('-vvv', true) || $input->hasParameterOption('--verbose=3', true) || 3 === $input->getParameterOption('--verbose', false, true)) { |
|
912 | - $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); |
|
911 | + if ( $input->hasParameterOption( '-vvv', true ) || $input->hasParameterOption( '--verbose=3', true ) || 3 === $input->getParameterOption( '--verbose', false, true ) ) { |
|
912 | + $output->setVerbosity( OutputInterface::VERBOSITY_DEBUG ); |
|
913 | 913 | $shellVerbosity = 3; |
914 | - } elseif ($input->hasParameterOption('-vv', true) || $input->hasParameterOption('--verbose=2', true) || 2 === $input->getParameterOption('--verbose', false, true)) { |
|
915 | - $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
914 | + } elseif ( $input->hasParameterOption( '-vv', true ) || $input->hasParameterOption( '--verbose=2', true ) || 2 === $input->getParameterOption( '--verbose', false, true ) ) { |
|
915 | + $output->setVerbosity( OutputInterface::VERBOSITY_VERY_VERBOSE ); |
|
916 | 916 | $shellVerbosity = 2; |
917 | - } elseif ($input->hasParameterOption('-v', true) || $input->hasParameterOption('--verbose=1', true) || $input->hasParameterOption('--verbose', true) || $input->getParameterOption('--verbose', false, true)) { |
|
918 | - $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
917 | + } elseif ( $input->hasParameterOption( '-v', true ) || $input->hasParameterOption( '--verbose=1', true ) || $input->hasParameterOption( '--verbose', true ) || $input->getParameterOption( '--verbose', false, true ) ) { |
|
918 | + $output->setVerbosity( OutputInterface::VERBOSITY_VERBOSE ); |
|
919 | 919 | $shellVerbosity = 1; |
920 | 920 | } |
921 | 921 | } |
922 | 922 | |
923 | 923 | if (-1 === $shellVerbosity) { |
924 | - $input->setInteractive(false); |
|
924 | + $input->setInteractive( false ); |
|
925 | 925 | } |
926 | 926 | |
927 | - if (\function_exists('putenv')) { |
|
928 | - @putenv('SHELL_VERBOSITY='.$shellVerbosity); |
|
927 | + if ( \function_exists( 'putenv' ) ) { |
|
928 | + @putenv( 'SHELL_VERBOSITY=' . $shellVerbosity ); |
|
929 | 929 | } |
930 | - $_ENV['SHELL_VERBOSITY'] = $shellVerbosity; |
|
931 | - $_SERVER['SHELL_VERBOSITY'] = $shellVerbosity; |
|
930 | + $_ENV[ 'SHELL_VERBOSITY' ] = $shellVerbosity; |
|
931 | + $_SERVER[ 'SHELL_VERBOSITY' ] = $shellVerbosity; |
|
932 | 932 | } |
933 | 933 | |
934 | 934 | /** |
@@ -939,78 +939,78 @@ discard block |
||
939 | 939 | * |
940 | 940 | * @return int 0 if everything went fine, or an error code |
941 | 941 | */ |
942 | - protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output) |
|
942 | + protected function doRunCommand( Command $command, InputInterface $input, OutputInterface $output ) |
|
943 | 943 | { |
944 | - foreach ($command->getHelperSet() as $helper) { |
|
945 | - if ($helper instanceof InputAwareInterface) { |
|
946 | - $helper->setInput($input); |
|
944 | + foreach ( $command->getHelperSet() as $helper ) { |
|
945 | + if ( $helper instanceof InputAwareInterface ) { |
|
946 | + $helper->setInput( $input ); |
|
947 | 947 | } |
948 | 948 | } |
949 | 949 | |
950 | - if ($command instanceof SignalableCommandInterface && ($this->signalsToDispatchEvent || $command->getSubscribedSignals())) { |
|
951 | - if (!$this->signalRegistry) { |
|
952 | - throw new RuntimeException('Unable to subscribe to signal events. Make sure that the `pcntl` extension is installed and that "pcntl_*" functions are not disabled by your php.ini\'s "disable_functions" directive.'); |
|
950 | + if ( $command instanceof SignalableCommandInterface && ( $this->signalsToDispatchEvent || $command->getSubscribedSignals() ) ) { |
|
951 | + if ( ! $this->signalRegistry ) { |
|
952 | + throw new RuntimeException( 'Unable to subscribe to signal events. Make sure that the `pcntl` extension is installed and that "pcntl_*" functions are not disabled by your php.ini\'s "disable_functions" directive.' ); |
|
953 | 953 | } |
954 | 954 | |
955 | - if ($this->dispatcher) { |
|
956 | - foreach ($this->signalsToDispatchEvent as $signal) { |
|
957 | - $event = new ConsoleSignalEvent($command, $input, $output, $signal); |
|
955 | + if ( $this->dispatcher ) { |
|
956 | + foreach ( $this->signalsToDispatchEvent as $signal ) { |
|
957 | + $event = new ConsoleSignalEvent( $command, $input, $output, $signal ); |
|
958 | 958 | |
959 | - $this->signalRegistry->register($signal, function ($signal, $hasNext) use ($event) { |
|
960 | - $this->dispatcher->dispatch($event, ConsoleEvents::SIGNAL); |
|
959 | + $this->signalRegistry->register( $signal, function( $signal, $hasNext ) use ( $event ) { |
|
960 | + $this->dispatcher->dispatch( $event, ConsoleEvents::SIGNAL ); |
|
961 | 961 | |
962 | 962 | // No more handlers, we try to simulate PHP default behavior |
963 | - if (!$hasNext) { |
|
964 | - if (!\in_array($signal, [\SIGUSR1, \SIGUSR2], true)) { |
|
965 | - exit(0); |
|
963 | + if ( ! $hasNext ) { |
|
964 | + if ( ! \in_array( $signal, [ \SIGUSR1, \SIGUSR2 ], true ) ) { |
|
965 | + exit( 0 ); |
|
966 | 966 | } |
967 | 967 | } |
968 | 968 | }); |
969 | 969 | } |
970 | 970 | } |
971 | 971 | |
972 | - foreach ($command->getSubscribedSignals() as $signal) { |
|
973 | - $this->signalRegistry->register($signal, [$command, 'handleSignal']); |
|
972 | + foreach ( $command->getSubscribedSignals() as $signal ) { |
|
973 | + $this->signalRegistry->register( $signal, [ $command, 'handleSignal' ] ); |
|
974 | 974 | } |
975 | 975 | } |
976 | 976 | |
977 | - if (null === $this->dispatcher) { |
|
978 | - return $command->run($input, $output); |
|
977 | + if ( null === $this->dispatcher ) { |
|
978 | + return $command->run( $input, $output ); |
|
979 | 979 | } |
980 | 980 | |
981 | 981 | // bind before the console.command event, so the listeners have access to input options/arguments |
982 | 982 | try { |
983 | 983 | $command->mergeApplicationDefinition(); |
984 | - $input->bind($command->getDefinition()); |
|
985 | - } catch (ExceptionInterface $e) { |
|
984 | + $input->bind( $command->getDefinition() ); |
|
985 | + } catch ( ExceptionInterface $e ) { |
|
986 | 986 | // ignore invalid options/arguments for now, to allow the event listeners to customize the InputDefinition |
987 | 987 | } |
988 | 988 | |
989 | - $event = new ConsoleCommandEvent($command, $input, $output); |
|
989 | + $event = new ConsoleCommandEvent( $command, $input, $output ); |
|
990 | 990 | $e = null; |
991 | 991 | |
992 | 992 | try { |
993 | - $this->dispatcher->dispatch($event, ConsoleEvents::COMMAND); |
|
993 | + $this->dispatcher->dispatch( $event, ConsoleEvents::COMMAND ); |
|
994 | 994 | |
995 | - if ($event->commandShouldRun()) { |
|
996 | - $exitCode = $command->run($input, $output); |
|
995 | + if ( $event->commandShouldRun() ) { |
|
996 | + $exitCode = $command->run( $input, $output ); |
|
997 | 997 | } else { |
998 | 998 | $exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED; |
999 | 999 | } |
1000 | - } catch (\Throwable $e) { |
|
1001 | - $event = new ConsoleErrorEvent($input, $output, $e, $command); |
|
1002 | - $this->dispatcher->dispatch($event, ConsoleEvents::ERROR); |
|
1000 | + } catch ( \Throwable $e ) { |
|
1001 | + $event = new ConsoleErrorEvent( $input, $output, $e, $command ); |
|
1002 | + $this->dispatcher->dispatch( $event, ConsoleEvents::ERROR ); |
|
1003 | 1003 | $e = $event->getError(); |
1004 | 1004 | |
1005 | - if (0 === $exitCode = $event->getExitCode()) { |
|
1005 | + if ( 0 === $exitCode = $event->getExitCode() ) { |
|
1006 | 1006 | $e = null; |
1007 | 1007 | } |
1008 | 1008 | } |
1009 | 1009 | |
1010 | - $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode); |
|
1011 | - $this->dispatcher->dispatch($event, ConsoleEvents::TERMINATE); |
|
1010 | + $event = new ConsoleTerminateEvent( $command, $input, $output, $exitCode ); |
|
1011 | + $this->dispatcher->dispatch( $event, ConsoleEvents::TERMINATE ); |
|
1012 | 1012 | |
1013 | - if (null !== $e) { |
|
1013 | + if ( null !== $e ) { |
|
1014 | 1014 | throw $e; |
1015 | 1015 | } |
1016 | 1016 | |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | * |
1023 | 1023 | * @return string|null |
1024 | 1024 | */ |
1025 | - protected function getCommandName(InputInterface $input) |
|
1025 | + protected function getCommandName( InputInterface $input ) |
|
1026 | 1026 | { |
1027 | 1027 | return $this->singleCommand ? $this->defaultCommand : $input->getFirstArgument(); |
1028 | 1028 | } |
@@ -1034,15 +1034,15 @@ discard block |
||
1034 | 1034 | */ |
1035 | 1035 | protected function getDefaultInputDefinition() |
1036 | 1036 | { |
1037 | - return new InputDefinition([ |
|
1038 | - new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'), |
|
1039 | - new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display help for the given command. When no command is given display help for the <info>'.$this->defaultCommand.'</info> command'), |
|
1040 | - new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'), |
|
1041 | - new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'), |
|
1042 | - new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version'), |
|
1043 | - new InputOption('--ansi', '', InputOption::VALUE_NEGATABLE, 'Force (or disable --no-ansi) ANSI output', false), |
|
1044 | - new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question'), |
|
1045 | - ]); |
|
1037 | + return new InputDefinition( [ |
|
1038 | + new InputArgument( 'command', InputArgument::REQUIRED, 'The command to execute' ), |
|
1039 | + new InputOption( '--help', '-h', InputOption::VALUE_NONE, 'Display help for the given command. When no command is given display help for the <info>' . $this->defaultCommand . '</info> command' ), |
|
1040 | + new InputOption( '--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message' ), |
|
1041 | + new InputOption( '--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug' ), |
|
1042 | + new InputOption( '--version', '-V', InputOption::VALUE_NONE, 'Display this application version' ), |
|
1043 | + new InputOption( '--ansi', '', InputOption::VALUE_NEGATABLE, 'Force (or disable --no-ansi) ANSI output', false ), |
|
1044 | + new InputOption( '--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question' ), |
|
1045 | + ] ); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | /** |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | */ |
1053 | 1053 | protected function getDefaultCommands() |
1054 | 1054 | { |
1055 | - return [new HelpCommand(), new ListCommand()]; |
|
1055 | + return [ new HelpCommand(), new ListCommand() ]; |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | /** |
@@ -1062,20 +1062,20 @@ discard block |
||
1062 | 1062 | */ |
1063 | 1063 | protected function getDefaultHelperSet() |
1064 | 1064 | { |
1065 | - return new HelperSet([ |
|
1065 | + return new HelperSet( [ |
|
1066 | 1066 | new FormatterHelper(), |
1067 | 1067 | new DebugFormatterHelper(), |
1068 | 1068 | new ProcessHelper(), |
1069 | 1069 | new QuestionHelper(), |
1070 | - ]); |
|
1070 | + ] ); |
|
1071 | 1071 | } |
1072 | 1072 | |
1073 | 1073 | /** |
1074 | 1074 | * Returns abbreviated suggestions in string format. |
1075 | 1075 | */ |
1076 | - private function getAbbreviationSuggestions(array $abbrevs): string |
|
1076 | + private function getAbbreviationSuggestions( array $abbrevs ): string |
|
1077 | 1077 | { |
1078 | - return ' '.implode("\n ", $abbrevs); |
|
1078 | + return ' ' . implode( "\n ", $abbrevs ); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
@@ -1085,11 +1085,11 @@ discard block |
||
1085 | 1085 | * |
1086 | 1086 | * @return string The namespace of the command |
1087 | 1087 | */ |
1088 | - public function extractNamespace(string $name, int $limit = null) |
|
1088 | + public function extractNamespace( string $name, int $limit = null ) |
|
1089 | 1089 | { |
1090 | - $parts = explode(':', $name, -1); |
|
1090 | + $parts = explode( ':', $name, -1 ); |
|
1091 | 1091 | |
1092 | - return implode(':', null === $limit ? $parts : \array_slice($parts, 0, $limit)); |
|
1092 | + return implode( ':', null === $limit ? $parts : \array_slice( $parts, 0, $limit ) ); |
|
1093 | 1093 | } |
1094 | 1094 | |
1095 | 1095 | /** |
@@ -1098,46 +1098,46 @@ discard block |
||
1098 | 1098 | * |
1099 | 1099 | * @return string[] A sorted array of similar string |
1100 | 1100 | */ |
1101 | - private function findAlternatives(string $name, iterable $collection): array |
|
1101 | + private function findAlternatives( string $name, iterable $collection ): array |
|
1102 | 1102 | { |
1103 | 1103 | $threshold = 1e3; |
1104 | - $alternatives = []; |
|
1104 | + $alternatives = [ ]; |
|
1105 | 1105 | |
1106 | - $collectionParts = []; |
|
1107 | - foreach ($collection as $item) { |
|
1108 | - $collectionParts[$item] = explode(':', $item); |
|
1106 | + $collectionParts = [ ]; |
|
1107 | + foreach ( $collection as $item ) { |
|
1108 | + $collectionParts[ $item ] = explode( ':', $item ); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | - foreach (explode(':', $name) as $i => $subname) { |
|
1112 | - foreach ($collectionParts as $collectionName => $parts) { |
|
1113 | - $exists = isset($alternatives[$collectionName]); |
|
1114 | - if (!isset($parts[$i]) && $exists) { |
|
1115 | - $alternatives[$collectionName] += $threshold; |
|
1111 | + foreach ( explode( ':', $name ) as $i => $subname ) { |
|
1112 | + foreach ( $collectionParts as $collectionName => $parts ) { |
|
1113 | + $exists = isset( $alternatives[ $collectionName ] ); |
|
1114 | + if ( ! isset( $parts[ $i ] ) && $exists ) { |
|
1115 | + $alternatives[ $collectionName ] += $threshold; |
|
1116 | 1116 | continue; |
1117 | - } elseif (!isset($parts[$i])) { |
|
1117 | + } elseif ( ! isset( $parts[ $i ] ) ) { |
|
1118 | 1118 | continue; |
1119 | 1119 | } |
1120 | 1120 | |
1121 | - $lev = levenshtein($subname, $parts[$i]); |
|
1122 | - if ($lev <= \strlen($subname) / 3 || '' !== $subname && str_contains($parts[$i], $subname)) { |
|
1123 | - $alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev; |
|
1124 | - } elseif ($exists) { |
|
1125 | - $alternatives[$collectionName] += $threshold; |
|
1121 | + $lev = levenshtein( $subname, $parts[ $i ] ); |
|
1122 | + if ( $lev <= \strlen( $subname ) / 3 || '' !== $subname && str_contains( $parts[ $i ], $subname ) ) { |
|
1123 | + $alternatives[ $collectionName ] = $exists ? $alternatives[ $collectionName ] + $lev : $lev; |
|
1124 | + } elseif ( $exists ) { |
|
1125 | + $alternatives[ $collectionName ] += $threshold; |
|
1126 | 1126 | } |
1127 | 1127 | } |
1128 | 1128 | } |
1129 | 1129 | |
1130 | - foreach ($collection as $item) { |
|
1131 | - $lev = levenshtein($name, $item); |
|
1132 | - if ($lev <= \strlen($name) / 3 || str_contains($item, $name)) { |
|
1133 | - $alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev; |
|
1130 | + foreach ( $collection as $item ) { |
|
1131 | + $lev = levenshtein( $name, $item ); |
|
1132 | + if ( $lev <= \strlen( $name ) / 3 || str_contains( $item, $name ) ) { |
|
1133 | + $alternatives[ $item ] = isset( $alternatives[ $item ] ) ? $alternatives[ $item ] - $lev : $lev; |
|
1134 | 1134 | } |
1135 | 1135 | } |
1136 | 1136 | |
1137 | - $alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2 * $threshold; }); |
|
1138 | - ksort($alternatives, \SORT_NATURAL | \SORT_FLAG_CASE); |
|
1137 | + $alternatives = array_filter( $alternatives, function( $lev ) use ( $threshold ) { return $lev < 2 * $threshold; }); |
|
1138 | + ksort( $alternatives, \SORT_NATURAL | \SORT_FLAG_CASE ); |
|
1139 | 1139 | |
1140 | - return array_keys($alternatives); |
|
1140 | + return array_keys( $alternatives ); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | /** |
@@ -1145,13 +1145,13 @@ discard block |
||
1145 | 1145 | * |
1146 | 1146 | * @return self |
1147 | 1147 | */ |
1148 | - public function setDefaultCommand(string $commandName, bool $isSingleCommand = false) |
|
1148 | + public function setDefaultCommand( string $commandName, bool $isSingleCommand = false ) |
|
1149 | 1149 | { |
1150 | - $this->defaultCommand = explode('|', ltrim($commandName, '|'))[0]; |
|
1150 | + $this->defaultCommand = explode( '|', ltrim( $commandName, '|' ) )[ 0 ]; |
|
1151 | 1151 | |
1152 | - if ($isSingleCommand) { |
|
1152 | + if ( $isSingleCommand ) { |
|
1153 | 1153 | // Ensure the command exist |
1154 | - $this->find($commandName); |
|
1154 | + $this->find( $commandName ); |
|
1155 | 1155 | |
1156 | 1156 | $this->singleCommand = true; |
1157 | 1157 | } |
@@ -1167,38 +1167,38 @@ discard block |
||
1167 | 1167 | return $this->singleCommand; |
1168 | 1168 | } |
1169 | 1169 | |
1170 | - private function splitStringByWidth(string $string, int $width): array |
|
1170 | + private function splitStringByWidth( string $string, int $width ): array |
|
1171 | 1171 | { |
1172 | 1172 | // str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly. |
1173 | 1173 | // additionally, array_slice() is not enough as some character has doubled width. |
1174 | 1174 | // we need a function to split string not by character count but by string width |
1175 | - if (false === $encoding = mb_detect_encoding($string, null, true)) { |
|
1176 | - return str_split($string, $width); |
|
1175 | + if ( false === $encoding = mb_detect_encoding( $string, null, true ) ) { |
|
1176 | + return str_split( $string, $width ); |
|
1177 | 1177 | } |
1178 | 1178 | |
1179 | - $utf8String = mb_convert_encoding($string, 'utf8', $encoding); |
|
1180 | - $lines = []; |
|
1179 | + $utf8String = mb_convert_encoding( $string, 'utf8', $encoding ); |
|
1180 | + $lines = [ ]; |
|
1181 | 1181 | $line = ''; |
1182 | 1182 | |
1183 | 1183 | $offset = 0; |
1184 | - while (preg_match('/.{1,10000}/u', $utf8String, $m, 0, $offset)) { |
|
1185 | - $offset += \strlen($m[0]); |
|
1184 | + while ( preg_match( '/.{1,10000}/u', $utf8String, $m, 0, $offset ) ) { |
|
1185 | + $offset += \strlen( $m[ 0 ] ); |
|
1186 | 1186 | |
1187 | - foreach (preg_split('//u', $m[0]) as $char) { |
|
1187 | + foreach ( preg_split( '//u', $m[ 0 ] ) as $char ) { |
|
1188 | 1188 | // test if $char could be appended to current line |
1189 | - if (mb_strwidth($line.$char, 'utf8') <= $width) { |
|
1189 | + if ( mb_strwidth( $line . $char, 'utf8' ) <= $width ) { |
|
1190 | 1190 | $line .= $char; |
1191 | 1191 | continue; |
1192 | 1192 | } |
1193 | 1193 | // if not, push current line to array and make new line |
1194 | - $lines[] = str_pad($line, $width); |
|
1194 | + $lines[ ] = str_pad( $line, $width ); |
|
1195 | 1195 | $line = $char; |
1196 | 1196 | } |
1197 | 1197 | } |
1198 | 1198 | |
1199 | - $lines[] = \count($lines) ? str_pad($line, $width) : $line; |
|
1199 | + $lines[ ] = \count( $lines ) ? str_pad( $line, $width ) : $line; |
|
1200 | 1200 | |
1201 | - mb_convert_variables($encoding, 'utf8', $lines); |
|
1201 | + mb_convert_variables( $encoding, 'utf8', $lines ); |
|
1202 | 1202 | |
1203 | 1203 | return $lines; |
1204 | 1204 | } |
@@ -1208,17 +1208,17 @@ discard block |
||
1208 | 1208 | * |
1209 | 1209 | * @return string[] The namespaces of the command |
1210 | 1210 | */ |
1211 | - private function extractAllNamespaces(string $name): array |
|
1211 | + private function extractAllNamespaces( string $name ): array |
|
1212 | 1212 | { |
1213 | 1213 | // -1 as third argument is needed to skip the command short name when exploding |
1214 | - $parts = explode(':', $name, -1); |
|
1215 | - $namespaces = []; |
|
1214 | + $parts = explode( ':', $name, -1 ); |
|
1215 | + $namespaces = [ ]; |
|
1216 | 1216 | |
1217 | - foreach ($parts as $part) { |
|
1218 | - if (\count($namespaces)) { |
|
1219 | - $namespaces[] = end($namespaces).':'.$part; |
|
1217 | + foreach ( $parts as $part ) { |
|
1218 | + if ( \count( $namespaces ) ) { |
|
1219 | + $namespaces[ ] = end( $namespaces ) . ':' . $part; |
|
1220 | 1220 | } else { |
1221 | - $namespaces[] = $part; |
|
1221 | + $namespaces[ ] = $part; |
|
1222 | 1222 | } |
1223 | 1223 | } |
1224 | 1224 | |
@@ -1227,13 +1227,13 @@ discard block |
||
1227 | 1227 | |
1228 | 1228 | private function init() |
1229 | 1229 | { |
1230 | - if ($this->initialized) { |
|
1230 | + if ( $this->initialized ) { |
|
1231 | 1231 | return; |
1232 | 1232 | } |
1233 | 1233 | $this->initialized = true; |
1234 | 1234 | |
1235 | - foreach ($this->getDefaultCommands() as $command) { |
|
1236 | - $this->add($command); |
|
1235 | + foreach ( $this->getDefaultCommands() as $command ) { |
|
1236 | + $this->add( $command ); |
|
1237 | 1237 | } |
1238 | 1238 | } |
1239 | 1239 | } |
@@ -24,12 +24,12 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function getWidth() |
26 | 26 | { |
27 | - $width = getenv('COLUMNS'); |
|
28 | - if (false !== $width) { |
|
29 | - return (int) trim($width); |
|
27 | + $width = getenv( 'COLUMNS' ); |
|
28 | + if ( false !== $width ) { |
|
29 | + return (int)trim( $width ); |
|
30 | 30 | } |
31 | 31 | |
32 | - if (null === self::$width) { |
|
32 | + if ( null === self::$width ) { |
|
33 | 33 | self::initDimensions(); |
34 | 34 | } |
35 | 35 | |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function getHeight() |
45 | 45 | { |
46 | - $height = getenv('LINES'); |
|
47 | - if (false !== $height) { |
|
48 | - return (int) trim($height); |
|
46 | + $height = getenv( 'LINES' ); |
|
47 | + if ( false !== $height ) { |
|
48 | + return (int)trim( $height ); |
|
49 | 49 | } |
50 | 50 | |
51 | - if (null === self::$height) { |
|
51 | + if ( null === self::$height ) { |
|
52 | 52 | self::initDimensions(); |
53 | 53 | } |
54 | 54 | |
@@ -62,36 +62,36 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public static function hasSttyAvailable() |
64 | 64 | { |
65 | - if (null !== self::$stty) { |
|
65 | + if ( null !== self::$stty ) { |
|
66 | 66 | return self::$stty; |
67 | 67 | } |
68 | 68 | |
69 | 69 | // skip check if exec function is disabled |
70 | - if (!\function_exists('exec')) { |
|
70 | + if ( ! \function_exists( 'exec' ) ) { |
|
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | |
74 | - exec('stty 2>&1', $output, $exitcode); |
|
74 | + exec( 'stty 2>&1', $output, $exitcode ); |
|
75 | 75 | |
76 | 76 | return self::$stty = 0 === $exitcode; |
77 | 77 | } |
78 | 78 | |
79 | 79 | private static function initDimensions() |
80 | 80 | { |
81 | - if ('\\' === \DIRECTORY_SEPARATOR) { |
|
82 | - if (preg_match('/^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$/', trim(getenv('ANSICON')), $matches)) { |
|
81 | + if ( '\\' === \DIRECTORY_SEPARATOR ) { |
|
82 | + if ( preg_match( '/^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$/', trim( getenv( 'ANSICON' ) ), $matches ) ) { |
|
83 | 83 | // extract [w, H] from "wxh (WxH)" |
84 | 84 | // or [w, h] from "wxh" |
85 | - self::$width = (int) $matches[1]; |
|
86 | - self::$height = isset($matches[4]) ? (int) $matches[4] : (int) $matches[2]; |
|
87 | - } elseif (!self::hasVt100Support() && self::hasSttyAvailable()) { |
|
85 | + self::$width = (int)$matches[ 1 ]; |
|
86 | + self::$height = isset( $matches[ 4 ] ) ? (int)$matches[ 4 ] : (int)$matches[ 2 ]; |
|
87 | + } elseif ( ! self::hasVt100Support() && self::hasSttyAvailable() ) { |
|
88 | 88 | // only use stty on Windows if the terminal does not support vt100 (e.g. Windows 7 + git-bash) |
89 | 89 | // testing for stty in a Windows 10 vt100-enabled console will implicitly disable vt100 support on STDOUT |
90 | 90 | self::initDimensionsUsingStty(); |
91 | - } elseif (null !== $dimensions = self::getConsoleMode()) { |
|
91 | + } elseif ( null !== $dimensions = self::getConsoleMode() ) { |
|
92 | 92 | // extract [w, h] from "wxh" |
93 | - self::$width = (int) $dimensions[0]; |
|
94 | - self::$height = (int) $dimensions[1]; |
|
93 | + self::$width = (int)$dimensions[ 0 ]; |
|
94 | + self::$height = (int)$dimensions[ 1 ]; |
|
95 | 95 | } |
96 | 96 | } else { |
97 | 97 | self::initDimensionsUsingStty(); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | private static function hasVt100Support(): bool |
105 | 105 | { |
106 | - return \function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(fopen('php://stdout', 'w')); |
|
106 | + return \function_exists( 'sapi_windows_vt100_support' ) && sapi_windows_vt100_support( fopen( 'php://stdout', 'w' ) ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -111,15 +111,15 @@ discard block |
||
111 | 111 | */ |
112 | 112 | private static function initDimensionsUsingStty() |
113 | 113 | { |
114 | - if ($sttyString = self::getSttyColumns()) { |
|
115 | - if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) { |
|
114 | + if ( $sttyString = self::getSttyColumns() ) { |
|
115 | + if ( preg_match( '/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches ) ) { |
|
116 | 116 | // extract [w, h] from "rows h; columns w;" |
117 | - self::$width = (int) $matches[2]; |
|
118 | - self::$height = (int) $matches[1]; |
|
119 | - } elseif (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) { |
|
117 | + self::$width = (int)$matches[ 2 ]; |
|
118 | + self::$height = (int)$matches[ 1 ]; |
|
119 | + } elseif ( preg_match( '/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches ) ) { |
|
120 | 120 | // extract [w, h] from "; h rows; w columns" |
121 | - self::$width = (int) $matches[2]; |
|
122 | - self::$height = (int) $matches[1]; |
|
121 | + self::$width = (int)$matches[ 2 ]; |
|
122 | + self::$height = (int)$matches[ 1 ]; |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | } |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | */ |
132 | 132 | private static function getConsoleMode(): ?array |
133 | 133 | { |
134 | - $info = self::readFromProcess('mode CON'); |
|
134 | + $info = self::readFromProcess( 'mode CON' ); |
|
135 | 135 | |
136 | - if (null === $info || !preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) { |
|
136 | + if ( null === $info || ! preg_match( '/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches ) ) { |
|
137 | 137 | return null; |
138 | 138 | } |
139 | 139 | |
140 | - return [(int) $matches[2], (int) $matches[1]]; |
|
140 | + return [ (int)$matches[ 2 ], (int)$matches[ 1 ] ]; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -145,29 +145,29 @@ discard block |
||
145 | 145 | */ |
146 | 146 | private static function getSttyColumns(): ?string |
147 | 147 | { |
148 | - return self::readFromProcess('stty -a | grep columns'); |
|
148 | + return self::readFromProcess( 'stty -a | grep columns' ); |
|
149 | 149 | } |
150 | 150 | |
151 | - private static function readFromProcess(string $command): ?string |
|
151 | + private static function readFromProcess( string $command ): ?string |
|
152 | 152 | { |
153 | - if (!\function_exists('proc_open')) { |
|
153 | + if ( ! \function_exists( 'proc_open' ) ) { |
|
154 | 154 | return null; |
155 | 155 | } |
156 | 156 | |
157 | 157 | $descriptorspec = [ |
158 | - 1 => ['pipe', 'w'], |
|
159 | - 2 => ['pipe', 'w'], |
|
158 | + 1 => [ 'pipe', 'w' ], |
|
159 | + 2 => [ 'pipe', 'w' ], |
|
160 | 160 | ]; |
161 | 161 | |
162 | - $process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true]); |
|
163 | - if (!\is_resource($process)) { |
|
162 | + $process = proc_open( $command, $descriptorspec, $pipes, null, null, [ 'suppress_errors' => true ] ); |
|
163 | + if ( ! \is_resource( $process ) ) { |
|
164 | 164 | return null; |
165 | 165 | } |
166 | 166 | |
167 | - $info = stream_get_contents($pipes[1]); |
|
168 | - fclose($pipes[1]); |
|
169 | - fclose($pipes[2]); |
|
170 | - proc_close($process); |
|
167 | + $info = stream_get_contents( $pipes[ 1 ] ); |
|
168 | + fclose( $pipes[ 1 ] ); |
|
169 | + fclose( $pipes[ 2 ] ); |
|
170 | + proc_close( $process ); |
|
171 | 171 | |
172 | 172 | return $info; |
173 | 173 | } |