Completed
Push — develop ( d12426...aff1bc )
by Zack
18:32
created
vendor/symfony/console/Input/InputAwareInterface.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@
 block discarded – undo
19 19
  */
20 20
 interface InputAwareInterface
21 21
 {
22
-    /**
23
-     * Sets the Console Input.
24
-     */
25
-    public function setInput(InputInterface $input);
22
+	/**
23
+	 * Sets the Console Input.
24
+	 */
25
+	public function setInput(InputInterface $input);
26 26
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,5 +22,5 @@
 block discarded – undo
22 22
     /**
23 23
      * Sets the Console Input.
24 24
      */
25
-    public function setInput(InputInterface $input);
25
+    public function setInput( InputInterface $input );
26 26
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@
 block discarded – undo
17 17
  *
18 18
  * @author Wouter J <[email protected]>
19 19
  */
20
-interface InputAwareInterface
21
-{
20
+interface InputAwareInterface {
22 21
     /**
23 22
      * Sets the Console Input.
24 23
      */
Please login to merge, or discard this patch.
vendor/symfony/console/Input/Input.php 3 patches
Indentation   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -27,187 +27,187 @@
 block discarded – undo
27 27
  */
28 28
 abstract class Input implements InputInterface, StreamableInputInterface
29 29
 {
30
-    protected $definition;
31
-    protected $stream;
32
-    protected $options = [];
33
-    protected $arguments = [];
34
-    protected $interactive = true;
35
-
36
-    public function __construct(InputDefinition $definition = null)
37
-    {
38
-        if (null === $definition) {
39
-            $this->definition = new InputDefinition();
40
-        } else {
41
-            $this->bind($definition);
42
-            $this->validate();
43
-        }
44
-    }
45
-
46
-    /**
47
-     * {@inheritdoc}
48
-     */
49
-    public function bind(InputDefinition $definition)
50
-    {
51
-        $this->arguments = [];
52
-        $this->options = [];
53
-        $this->definition = $definition;
54
-
55
-        $this->parse();
56
-    }
57
-
58
-    /**
59
-     * Processes command line arguments.
60
-     */
61
-    abstract protected function parse();
62
-
63
-    /**
64
-     * {@inheritdoc}
65
-     */
66
-    public function validate()
67
-    {
68
-        $definition = $this->definition;
69
-        $givenArguments = $this->arguments;
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();
73
-        });
74
-
75
-        if (\count($missingArguments) > 0) {
76
-            throw new RuntimeException(sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArguments)));
77
-        }
78
-    }
79
-
80
-    /**
81
-     * {@inheritdoc}
82
-     */
83
-    public function isInteractive()
84
-    {
85
-        return $this->interactive;
86
-    }
87
-
88
-    /**
89
-     * {@inheritdoc}
90
-     */
91
-    public function setInteractive(bool $interactive)
92
-    {
93
-        $this->interactive = $interactive;
94
-    }
95
-
96
-    /**
97
-     * {@inheritdoc}
98
-     */
99
-    public function getArguments()
100
-    {
101
-        return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
102
-    }
103
-
104
-    /**
105
-     * {@inheritdoc}
106
-     */
107
-    public function getArgument(string $name)
108
-    {
109
-        if (!$this->definition->hasArgument($name)) {
110
-            throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
111
-        }
112
-
113
-        return $this->arguments[$name] ?? $this->definition->getArgument($name)->getDefault();
114
-    }
115
-
116
-    /**
117
-     * {@inheritdoc}
118
-     */
119
-    public function setArgument(string $name, $value)
120
-    {
121
-        if (!$this->definition->hasArgument($name)) {
122
-            throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
123
-        }
124
-
125
-        $this->arguments[$name] = $value;
126
-    }
127
-
128
-    /**
129
-     * {@inheritdoc}
130
-     */
131
-    public function hasArgument(string $name)
132
-    {
133
-        return $this->definition->hasArgument($name);
134
-    }
135
-
136
-    /**
137
-     * {@inheritdoc}
138
-     */
139
-    public function getOptions()
140
-    {
141
-        return array_merge($this->definition->getOptionDefaults(), $this->options);
142
-    }
143
-
144
-    /**
145
-     * {@inheritdoc}
146
-     */
147
-    public function getOption(string $name)
148
-    {
149
-        if ($this->definition->hasNegation($name)) {
150
-            if (null === $value = $this->getOption($this->definition->negationToName($name))) {
151
-                return $value;
152
-            }
153
-
154
-            return !$value;
155
-        }
156
-
157
-        if (!$this->definition->hasOption($name)) {
158
-            throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
159
-        }
160
-
161
-        return \array_key_exists($name, $this->options) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
162
-    }
163
-
164
-    /**
165
-     * {@inheritdoc}
166
-     */
167
-    public function setOption(string $name, $value)
168
-    {
169
-        if ($this->definition->hasNegation($name)) {
170
-            $this->options[$this->definition->negationToName($name)] = !$value;
171
-
172
-            return;
173
-        } elseif (!$this->definition->hasOption($name)) {
174
-            throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
175
-        }
176
-
177
-        $this->options[$name] = $value;
178
-    }
179
-
180
-    /**
181
-     * {@inheritdoc}
182
-     */
183
-    public function hasOption(string $name)
184
-    {
185
-        return $this->definition->hasOption($name) || $this->definition->hasNegation($name);
186
-    }
187
-
188
-    /**
189
-     * Escapes a token through escapeshellarg if it contains unsafe chars.
190
-     *
191
-     * @return string
192
-     */
193
-    public function escapeToken(string $token)
194
-    {
195
-        return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
196
-    }
197
-
198
-    /**
199
-     * {@inheritdoc}
200
-     */
201
-    public function setStream($stream)
202
-    {
203
-        $this->stream = $stream;
204
-    }
205
-
206
-    /**
207
-     * {@inheritdoc}
208
-     */
209
-    public function getStream()
210
-    {
211
-        return $this->stream;
212
-    }
30
+	protected $definition;
31
+	protected $stream;
32
+	protected $options = [];
33
+	protected $arguments = [];
34
+	protected $interactive = true;
35
+
36
+	public function __construct(InputDefinition $definition = null)
37
+	{
38
+		if (null === $definition) {
39
+			$this->definition = new InputDefinition();
40
+		} else {
41
+			$this->bind($definition);
42
+			$this->validate();
43
+		}
44
+	}
45
+
46
+	/**
47
+	 * {@inheritdoc}
48
+	 */
49
+	public function bind(InputDefinition $definition)
50
+	{
51
+		$this->arguments = [];
52
+		$this->options = [];
53
+		$this->definition = $definition;
54
+
55
+		$this->parse();
56
+	}
57
+
58
+	/**
59
+	 * Processes command line arguments.
60
+	 */
61
+	abstract protected function parse();
62
+
63
+	/**
64
+	 * {@inheritdoc}
65
+	 */
66
+	public function validate()
67
+	{
68
+		$definition = $this->definition;
69
+		$givenArguments = $this->arguments;
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();
73
+		});
74
+
75
+		if (\count($missingArguments) > 0) {
76
+			throw new RuntimeException(sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArguments)));
77
+		}
78
+	}
79
+
80
+	/**
81
+	 * {@inheritdoc}
82
+	 */
83
+	public function isInteractive()
84
+	{
85
+		return $this->interactive;
86
+	}
87
+
88
+	/**
89
+	 * {@inheritdoc}
90
+	 */
91
+	public function setInteractive(bool $interactive)
92
+	{
93
+		$this->interactive = $interactive;
94
+	}
95
+
96
+	/**
97
+	 * {@inheritdoc}
98
+	 */
99
+	public function getArguments()
100
+	{
101
+		return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
102
+	}
103
+
104
+	/**
105
+	 * {@inheritdoc}
106
+	 */
107
+	public function getArgument(string $name)
108
+	{
109
+		if (!$this->definition->hasArgument($name)) {
110
+			throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
111
+		}
112
+
113
+		return $this->arguments[$name] ?? $this->definition->getArgument($name)->getDefault();
114
+	}
115
+
116
+	/**
117
+	 * {@inheritdoc}
118
+	 */
119
+	public function setArgument(string $name, $value)
120
+	{
121
+		if (!$this->definition->hasArgument($name)) {
122
+			throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
123
+		}
124
+
125
+		$this->arguments[$name] = $value;
126
+	}
127
+
128
+	/**
129
+	 * {@inheritdoc}
130
+	 */
131
+	public function hasArgument(string $name)
132
+	{
133
+		return $this->definition->hasArgument($name);
134
+	}
135
+
136
+	/**
137
+	 * {@inheritdoc}
138
+	 */
139
+	public function getOptions()
140
+	{
141
+		return array_merge($this->definition->getOptionDefaults(), $this->options);
142
+	}
143
+
144
+	/**
145
+	 * {@inheritdoc}
146
+	 */
147
+	public function getOption(string $name)
148
+	{
149
+		if ($this->definition->hasNegation($name)) {
150
+			if (null === $value = $this->getOption($this->definition->negationToName($name))) {
151
+				return $value;
152
+			}
153
+
154
+			return !$value;
155
+		}
156
+
157
+		if (!$this->definition->hasOption($name)) {
158
+			throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
159
+		}
160
+
161
+		return \array_key_exists($name, $this->options) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
162
+	}
163
+
164
+	/**
165
+	 * {@inheritdoc}
166
+	 */
167
+	public function setOption(string $name, $value)
168
+	{
169
+		if ($this->definition->hasNegation($name)) {
170
+			$this->options[$this->definition->negationToName($name)] = !$value;
171
+
172
+			return;
173
+		} elseif (!$this->definition->hasOption($name)) {
174
+			throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
175
+		}
176
+
177
+		$this->options[$name] = $value;
178
+	}
179
+
180
+	/**
181
+	 * {@inheritdoc}
182
+	 */
183
+	public function hasOption(string $name)
184
+	{
185
+		return $this->definition->hasOption($name) || $this->definition->hasNegation($name);
186
+	}
187
+
188
+	/**
189
+	 * Escapes a token through escapeshellarg if it contains unsafe chars.
190
+	 *
191
+	 * @return string
192
+	 */
193
+	public function escapeToken(string $token)
194
+	{
195
+		return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
196
+	}
197
+
198
+	/**
199
+	 * {@inheritdoc}
200
+	 */
201
+	public function setStream($stream)
202
+	{
203
+		$this->stream = $stream;
204
+	}
205
+
206
+	/**
207
+	 * {@inheritdoc}
208
+	 */
209
+	public function getStream()
210
+	{
211
+		return $this->stream;
212
+	}
213 213
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -29,16 +29,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Braces   +16 added lines, -32 removed lines patch added patch discarded remove patch
@@ -33,8 +33,7 @@  discard block
 block discarded – undo
33 33
     protected $arguments = [];
34 34
     protected $interactive = true;
35 35
 
36
-    public function __construct(InputDefinition $definition = null)
37
-    {
36
+    public function __construct(InputDefinition $definition = null) {
38 37
         if (null === $definition) {
39 38
             $this->definition = new InputDefinition();
40 39
         } else {
@@ -46,8 +45,7 @@  discard block
 block discarded – undo
46 45
     /**
47 46
      * {@inheritdoc}
48 47
      */
49
-    public function bind(InputDefinition $definition)
50
-    {
48
+    public function bind(InputDefinition $definition) {
51 49
         $this->arguments = [];
52 50
         $this->options = [];
53 51
         $this->definition = $definition;
@@ -63,8 +61,7 @@  discard block
 block discarded – undo
63 61
     /**
64 62
      * {@inheritdoc}
65 63
      */
66
-    public function validate()
67
-    {
64
+    public function validate() {
68 65
         $definition = $this->definition;
69 66
         $givenArguments = $this->arguments;
70 67
 
@@ -80,32 +77,28 @@  discard block
 block discarded – undo
80 77
     /**
81 78
      * {@inheritdoc}
82 79
      */
83
-    public function isInteractive()
84
-    {
80
+    public function isInteractive() {
85 81
         return $this->interactive;
86 82
     }
87 83
 
88 84
     /**
89 85
      * {@inheritdoc}
90 86
      */
91
-    public function setInteractive(bool $interactive)
92
-    {
87
+    public function setInteractive(bool $interactive) {
93 88
         $this->interactive = $interactive;
94 89
     }
95 90
 
96 91
     /**
97 92
      * {@inheritdoc}
98 93
      */
99
-    public function getArguments()
100
-    {
94
+    public function getArguments() {
101 95
         return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
102 96
     }
103 97
 
104 98
     /**
105 99
      * {@inheritdoc}
106 100
      */
107
-    public function getArgument(string $name)
108
-    {
101
+    public function getArgument(string $name) {
109 102
         if (!$this->definition->hasArgument($name)) {
110 103
             throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
111 104
         }
@@ -116,8 +109,7 @@  discard block
 block discarded – undo
116 109
     /**
117 110
      * {@inheritdoc}
118 111
      */
119
-    public function setArgument(string $name, $value)
120
-    {
112
+    public function setArgument(string $name, $value) {
121 113
         if (!$this->definition->hasArgument($name)) {
122 114
             throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
123 115
         }
@@ -128,24 +120,21 @@  discard block
 block discarded – undo
128 120
     /**
129 121
      * {@inheritdoc}
130 122
      */
131
-    public function hasArgument(string $name)
132
-    {
123
+    public function hasArgument(string $name) {
133 124
         return $this->definition->hasArgument($name);
134 125
     }
135 126
 
136 127
     /**
137 128
      * {@inheritdoc}
138 129
      */
139
-    public function getOptions()
140
-    {
130
+    public function getOptions() {
141 131
         return array_merge($this->definition->getOptionDefaults(), $this->options);
142 132
     }
143 133
 
144 134
     /**
145 135
      * {@inheritdoc}
146 136
      */
147
-    public function getOption(string $name)
148
-    {
137
+    public function getOption(string $name) {
149 138
         if ($this->definition->hasNegation($name)) {
150 139
             if (null === $value = $this->getOption($this->definition->negationToName($name))) {
151 140
                 return $value;
@@ -164,8 +153,7 @@  discard block
 block discarded – undo
164 153
     /**
165 154
      * {@inheritdoc}
166 155
      */
167
-    public function setOption(string $name, $value)
168
-    {
156
+    public function setOption(string $name, $value) {
169 157
         if ($this->definition->hasNegation($name)) {
170 158
             $this->options[$this->definition->negationToName($name)] = !$value;
171 159
 
@@ -180,8 +168,7 @@  discard block
 block discarded – undo
180 168
     /**
181 169
      * {@inheritdoc}
182 170
      */
183
-    public function hasOption(string $name)
184
-    {
171
+    public function hasOption(string $name) {
185 172
         return $this->definition->hasOption($name) || $this->definition->hasNegation($name);
186 173
     }
187 174
 
@@ -190,24 +177,21 @@  discard block
 block discarded – undo
190 177
      *
191 178
      * @return string
192 179
      */
193
-    public function escapeToken(string $token)
194
-    {
180
+    public function escapeToken(string $token) {
195 181
         return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
196 182
     }
197 183
 
198 184
     /**
199 185
      * {@inheritdoc}
200 186
      */
201
-    public function setStream($stream)
202
-    {
187
+    public function setStream($stream) {
203 188
         $this->stream = $stream;
204 189
     }
205 190
 
206 191
     /**
207 192
      * {@inheritdoc}
208 193
      */
209
-    public function getStream()
210
-    {
194
+    public function getStream() {
211 195
         return $this->stream;
212 196
     }
213 197
 }
Please login to merge, or discard this patch.
vendor/symfony/console/Input/ArrayInput.php 3 patches
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -25,186 +25,186 @@
 block discarded – undo
25 25
  */
26 26
 class ArrayInput extends Input
27 27
 {
28
-    private $parameters;
29
-
30
-    public function __construct(array $parameters, InputDefinition $definition = null)
31
-    {
32
-        $this->parameters = $parameters;
33
-
34
-        parent::__construct($definition);
35
-    }
36
-
37
-    /**
38
-     * {@inheritdoc}
39
-     */
40
-    public function getFirstArgument()
41
-    {
42
-        foreach ($this->parameters as $param => $value) {
43
-            if ($param && \is_string($param) && '-' === $param[0]) {
44
-                continue;
45
-            }
46
-
47
-            return $value;
48
-        }
49
-
50
-        return null;
51
-    }
52
-
53
-    /**
54
-     * {@inheritdoc}
55
-     */
56
-    public function hasParameterOption($values, bool $onlyParams = false)
57
-    {
58
-        $values = (array) $values;
59
-
60
-        foreach ($this->parameters as $k => $v) {
61
-            if (!\is_int($k)) {
62
-                $v = $k;
63
-            }
64
-
65
-            if ($onlyParams && '--' === $v) {
66
-                return false;
67
-            }
68
-
69
-            if (\in_array($v, $values)) {
70
-                return true;
71
-            }
72
-        }
73
-
74
-        return false;
75
-    }
76
-
77
-    /**
78
-     * {@inheritdoc}
79
-     */
80
-    public function getParameterOption($values, $default = false, bool $onlyParams = false)
81
-    {
82
-        $values = (array) $values;
83
-
84
-        foreach ($this->parameters as $k => $v) {
85
-            if ($onlyParams && ('--' === $k || (\is_int($k) && '--' === $v))) {
86
-                return $default;
87
-            }
88
-
89
-            if (\is_int($k)) {
90
-                if (\in_array($v, $values)) {
91
-                    return true;
92
-                }
93
-            } elseif (\in_array($k, $values)) {
94
-                return $v;
95
-            }
96
-        }
97
-
98
-        return $default;
99
-    }
100
-
101
-    /**
102
-     * Returns a stringified representation of the args passed to the command.
103
-     *
104
-     * @return string
105
-     */
106
-    public function __toString()
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) : '');
115
-                    }
116
-                } else {
117
-                    $params[] = $param.('' != $val ? $glue.$this->escapeToken($val) : '');
118
-                }
119
-            } else {
120
-                $params[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val);
121
-            }
122
-        }
123
-
124
-        return implode(' ', $params);
125
-    }
126
-
127
-    /**
128
-     * {@inheritdoc}
129
-     */
130
-    protected function parse()
131
-    {
132
-        foreach ($this->parameters as $key => $value) {
133
-            if ('--' === $key) {
134
-                return;
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);
140
-            } else {
141
-                $this->addArgument($key, $value);
142
-            }
143
-        }
144
-    }
145
-
146
-    /**
147
-     * Adds a short option value.
148
-     *
149
-     * @throws InvalidOptionException When option given doesn't exist
150
-     */
151
-    private function addShortOption(string $shortcut, $value)
152
-    {
153
-        if (!$this->definition->hasShortcut($shortcut)) {
154
-            throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut));
155
-        }
156
-
157
-        $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
158
-    }
159
-
160
-    /**
161
-     * Adds a long option value.
162
-     *
163
-     * @throws InvalidOptionException When option given doesn't exist
164
-     * @throws InvalidOptionException When a required value is missing
165
-     */
166
-    private function addLongOption(string $name, $value)
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));
171
-            }
172
-
173
-            $optionName = $this->definition->negationToName($name);
174
-            $this->options[$optionName] = false;
175
-
176
-            return;
177
-        }
178
-
179
-        $option = $this->definition->getOption($name);
180
-
181
-        if (null === $value) {
182
-            if ($option->isValueRequired()) {
183
-                throw new InvalidOptionException(sprintf('The "--%s" option requires a value.', $name));
184
-            }
185
-
186
-            if (!$option->isValueOptional()) {
187
-                $value = true;
188
-            }
189
-        }
190
-
191
-        $this->options[$name] = $value;
192
-    }
193
-
194
-    /**
195
-     * Adds an argument value.
196
-     *
197
-     * @param string|int $name  The argument name
198
-     * @param mixed      $value The value for the argument
199
-     *
200
-     * @throws InvalidArgumentException When argument given doesn't exist
201
-     */
202
-    private function addArgument($name, $value)
203
-    {
204
-        if (!$this->definition->hasArgument($name)) {
205
-            throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
206
-        }
207
-
208
-        $this->arguments[$name] = $value;
209
-    }
28
+	private $parameters;
29
+
30
+	public function __construct(array $parameters, InputDefinition $definition = null)
31
+	{
32
+		$this->parameters = $parameters;
33
+
34
+		parent::__construct($definition);
35
+	}
36
+
37
+	/**
38
+	 * {@inheritdoc}
39
+	 */
40
+	public function getFirstArgument()
41
+	{
42
+		foreach ($this->parameters as $param => $value) {
43
+			if ($param && \is_string($param) && '-' === $param[0]) {
44
+				continue;
45
+			}
46
+
47
+			return $value;
48
+		}
49
+
50
+		return null;
51
+	}
52
+
53
+	/**
54
+	 * {@inheritdoc}
55
+	 */
56
+	public function hasParameterOption($values, bool $onlyParams = false)
57
+	{
58
+		$values = (array) $values;
59
+
60
+		foreach ($this->parameters as $k => $v) {
61
+			if (!\is_int($k)) {
62
+				$v = $k;
63
+			}
64
+
65
+			if ($onlyParams && '--' === $v) {
66
+				return false;
67
+			}
68
+
69
+			if (\in_array($v, $values)) {
70
+				return true;
71
+			}
72
+		}
73
+
74
+		return false;
75
+	}
76
+
77
+	/**
78
+	 * {@inheritdoc}
79
+	 */
80
+	public function getParameterOption($values, $default = false, bool $onlyParams = false)
81
+	{
82
+		$values = (array) $values;
83
+
84
+		foreach ($this->parameters as $k => $v) {
85
+			if ($onlyParams && ('--' === $k || (\is_int($k) && '--' === $v))) {
86
+				return $default;
87
+			}
88
+
89
+			if (\is_int($k)) {
90
+				if (\in_array($v, $values)) {
91
+					return true;
92
+				}
93
+			} elseif (\in_array($k, $values)) {
94
+				return $v;
95
+			}
96
+		}
97
+
98
+		return $default;
99
+	}
100
+
101
+	/**
102
+	 * Returns a stringified representation of the args passed to the command.
103
+	 *
104
+	 * @return string
105
+	 */
106
+	public function __toString()
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) : '');
115
+					}
116
+				} else {
117
+					$params[] = $param.('' != $val ? $glue.$this->escapeToken($val) : '');
118
+				}
119
+			} else {
120
+				$params[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val);
121
+			}
122
+		}
123
+
124
+		return implode(' ', $params);
125
+	}
126
+
127
+	/**
128
+	 * {@inheritdoc}
129
+	 */
130
+	protected function parse()
131
+	{
132
+		foreach ($this->parameters as $key => $value) {
133
+			if ('--' === $key) {
134
+				return;
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);
140
+			} else {
141
+				$this->addArgument($key, $value);
142
+			}
143
+		}
144
+	}
145
+
146
+	/**
147
+	 * Adds a short option value.
148
+	 *
149
+	 * @throws InvalidOptionException When option given doesn't exist
150
+	 */
151
+	private function addShortOption(string $shortcut, $value)
152
+	{
153
+		if (!$this->definition->hasShortcut($shortcut)) {
154
+			throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut));
155
+		}
156
+
157
+		$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
158
+	}
159
+
160
+	/**
161
+	 * Adds a long option value.
162
+	 *
163
+	 * @throws InvalidOptionException When option given doesn't exist
164
+	 * @throws InvalidOptionException When a required value is missing
165
+	 */
166
+	private function addLongOption(string $name, $value)
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));
171
+			}
172
+
173
+			$optionName = $this->definition->negationToName($name);
174
+			$this->options[$optionName] = false;
175
+
176
+			return;
177
+		}
178
+
179
+		$option = $this->definition->getOption($name);
180
+
181
+		if (null === $value) {
182
+			if ($option->isValueRequired()) {
183
+				throw new InvalidOptionException(sprintf('The "--%s" option requires a value.', $name));
184
+			}
185
+
186
+			if (!$option->isValueOptional()) {
187
+				$value = true;
188
+			}
189
+		}
190
+
191
+		$this->options[$name] = $value;
192
+	}
193
+
194
+	/**
195
+	 * Adds an argument value.
196
+	 *
197
+	 * @param string|int $name  The argument name
198
+	 * @param mixed      $value The value for the argument
199
+	 *
200
+	 * @throws InvalidArgumentException When argument given doesn't exist
201
+	 */
202
+	private function addArgument($name, $value)
203
+	{
204
+		if (!$this->definition->hasArgument($name)) {
205
+			throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
206
+		}
207
+
208
+		$this->arguments[$name] = $value;
209
+	}
210 210
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -23,12 +23,10 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @author Fabien Potencier <[email protected]>
25 25
  */
26
-class ArrayInput extends Input
27
-{
26
+class ArrayInput extends Input {
28 27
     private $parameters;
29 28
 
30
-    public function __construct(array $parameters, InputDefinition $definition = null)
31
-    {
29
+    public function __construct(array $parameters, InputDefinition $definition = null) {
32 30
         $this->parameters = $parameters;
33 31
 
34 32
         parent::__construct($definition);
@@ -37,8 +35,7 @@  discard block
 block discarded – undo
37 35
     /**
38 36
      * {@inheritdoc}
39 37
      */
40
-    public function getFirstArgument()
41
-    {
38
+    public function getFirstArgument() {
42 39
         foreach ($this->parameters as $param => $value) {
43 40
             if ($param && \is_string($param) && '-' === $param[0]) {
44 41
                 continue;
@@ -53,8 +50,7 @@  discard block
 block discarded – undo
53 50
     /**
54 51
      * {@inheritdoc}
55 52
      */
56
-    public function hasParameterOption($values, bool $onlyParams = false)
57
-    {
53
+    public function hasParameterOption($values, bool $onlyParams = false) {
58 54
         $values = (array) $values;
59 55
 
60 56
         foreach ($this->parameters as $k => $v) {
@@ -77,8 +73,7 @@  discard block
 block discarded – undo
77 73
     /**
78 74
      * {@inheritdoc}
79 75
      */
80
-    public function getParameterOption($values, $default = false, bool $onlyParams = false)
81
-    {
76
+    public function getParameterOption($values, $default = false, bool $onlyParams = false) {
82 77
         $values = (array) $values;
83 78
 
84 79
         foreach ($this->parameters as $k => $v) {
@@ -103,8 +98,7 @@  discard block
 block discarded – undo
103 98
      *
104 99
      * @return string
105 100
      */
106
-    public function __toString()
107
-    {
101
+    public function __toString() {
108 102
         $params = [];
109 103
         foreach ($this->parameters as $param => $val) {
110 104
             if ($param && \is_string($param) && '-' === $param[0]) {
@@ -127,8 +121,7 @@  discard block
 block discarded – undo
127 121
     /**
128 122
      * {@inheritdoc}
129 123
      */
130
-    protected function parse()
131
-    {
124
+    protected function parse() {
132 125
         foreach ($this->parameters as $key => $value) {
133 126
             if ('--' === $key) {
134 127
                 return;
@@ -148,8 +141,7 @@  discard block
 block discarded – undo
148 141
      *
149 142
      * @throws InvalidOptionException When option given doesn't exist
150 143
      */
151
-    private function addShortOption(string $shortcut, $value)
152
-    {
144
+    private function addShortOption(string $shortcut, $value) {
153 145
         if (!$this->definition->hasShortcut($shortcut)) {
154 146
             throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut));
155 147
         }
@@ -163,8 +155,7 @@  discard block
 block discarded – undo
163 155
      * @throws InvalidOptionException When option given doesn't exist
164 156
      * @throws InvalidOptionException When a required value is missing
165 157
      */
166
-    private function addLongOption(string $name, $value)
167
-    {
158
+    private function addLongOption(string $name, $value) {
168 159
         if (!$this->definition->hasOption($name)) {
169 160
             if (!$this->definition->hasNegation($name)) {
170 161
                 throw new InvalidOptionException(sprintf('The "--%s" option does not exist.', $name));
@@ -199,8 +190,7 @@  discard block
 block discarded – undo
199 190
      *
200 191
      * @throws InvalidArgumentException When argument given doesn't exist
201 192
      */
202
-    private function addArgument($name, $value)
203
-    {
193
+    private function addArgument($name, $value) {
204 194
         if (!$this->definition->hasArgument($name)) {
205 195
             throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
206 196
         }
Please login to merge, or discard this patch.
vendor/symfony/console/SignalRegistry/SignalRegistry.php 3 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -13,53 +13,53 @@
 block discarded – undo
13 13
 
14 14
 final class SignalRegistry
15 15
 {
16
-    private $signalHandlers = [];
16
+	private $signalHandlers = [];
17 17
 
18
-    public function __construct()
19
-    {
20
-        if (\function_exists('pcntl_async_signals')) {
21
-            pcntl_async_signals(true);
22
-        }
23
-    }
18
+	public function __construct()
19
+	{
20
+		if (\function_exists('pcntl_async_signals')) {
21
+			pcntl_async_signals(true);
22
+		}
23
+	}
24 24
 
25
-    public function register(int $signal, callable $signalHandler): void
26
-    {
27
-        if (!isset($this->signalHandlers[$signal])) {
28
-            $previousCallback = pcntl_signal_get_handler($signal);
25
+	public function register(int $signal, callable $signalHandler): void
26
+	{
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;
32
-            }
33
-        }
30
+			if (\is_callable($previousCallback)) {
31
+				$this->signalHandlers[$signal][] = $previousCallback;
32
+			}
33
+		}
34 34
 
35
-        $this->signalHandlers[$signal][] = $signalHandler;
35
+		$this->signalHandlers[$signal][] = $signalHandler;
36 36
 
37
-        pcntl_signal($signal, [$this, 'handle']);
38
-    }
37
+		pcntl_signal($signal, [$this, 'handle']);
38
+	}
39 39
 
40
-    public static function isSupported(): bool
41
-    {
42
-        if (!\function_exists('pcntl_signal')) {
43
-            return false;
44
-        }
40
+	public static function isSupported(): bool
41
+	{
42
+		if (!\function_exists('pcntl_signal')) {
43
+			return false;
44
+		}
45 45
 
46
-        if (\in_array('pcntl_signal', explode(',', ini_get('disable_functions')))) {
47
-            return false;
48
-        }
46
+		if (\in_array('pcntl_signal', explode(',', ini_get('disable_functions')))) {
47
+			return false;
48
+		}
49 49
 
50
-        return true;
51
-    }
50
+		return true;
51
+	}
52 52
 
53
-    /**
54
-     * @internal
55
-     */
56
-    public function handle(int $signal): void
57
-    {
58
-        $count = \count($this->signalHandlers[$signal]);
53
+	/**
54
+	 * @internal
55
+	 */
56
+	public function handle(int $signal): void
57
+	{
58
+		$count = \count($this->signalHandlers[$signal]);
59 59
 
60
-        foreach ($this->signalHandlers[$signal] as $i => $signalHandler) {
61
-            $hasNext = $i !== $count - 1;
62
-            $signalHandler($signal, $hasNext);
63
-        }
64
-    }
60
+		foreach ($this->signalHandlers[$signal] as $i => $signalHandler) {
61
+			$hasNext = $i !== $count - 1;
62
+			$signalHandler($signal, $hasNext);
63
+		}
64
+	}
65 65
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -13,37 +13,37 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,12 +11,10 @@
 block discarded – undo
11 11
 
12 12
 namespace Symfony\Component\Console\SignalRegistry;
13 13
 
14
-final class SignalRegistry
15
-{
14
+final class SignalRegistry {
16 15
     private $signalHandlers = [];
17 16
 
18
-    public function __construct()
19
-    {
17
+    public function __construct() {
20 18
         if (\function_exists('pcntl_async_signals')) {
21 19
             pcntl_async_signals(true);
22 20
         }
Please login to merge, or discard this patch.
vendor/symfony/console/CommandLoader/FactoryCommandLoader.php 3 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -20,43 +20,43 @@
 block discarded – undo
20 20
  */
21 21
 class FactoryCommandLoader implements CommandLoaderInterface
22 22
 {
23
-    private $factories;
24
-
25
-    /**
26
-     * @param callable[] $factories Indexed by command names
27
-     */
28
-    public function __construct(array $factories)
29
-    {
30
-        $this->factories = $factories;
31
-    }
32
-
33
-    /**
34
-     * {@inheritdoc}
35
-     */
36
-    public function has(string $name)
37
-    {
38
-        return isset($this->factories[$name]);
39
-    }
40
-
41
-    /**
42
-     * {@inheritdoc}
43
-     */
44
-    public function get(string $name)
45
-    {
46
-        if (!isset($this->factories[$name])) {
47
-            throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
48
-        }
49
-
50
-        $factory = $this->factories[$name];
51
-
52
-        return $factory();
53
-    }
54
-
55
-    /**
56
-     * {@inheritdoc}
57
-     */
58
-    public function getNames()
59
-    {
60
-        return array_keys($this->factories);
61
-    }
23
+	private $factories;
24
+
25
+	/**
26
+	 * @param callable[] $factories Indexed by command names
27
+	 */
28
+	public function __construct(array $factories)
29
+	{
30
+		$this->factories = $factories;
31
+	}
32
+
33
+	/**
34
+	 * {@inheritdoc}
35
+	 */
36
+	public function has(string $name)
37
+	{
38
+		return isset($this->factories[$name]);
39
+	}
40
+
41
+	/**
42
+	 * {@inheritdoc}
43
+	 */
44
+	public function get(string $name)
45
+	{
46
+		if (!isset($this->factories[$name])) {
47
+			throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
48
+		}
49
+
50
+		$factory = $this->factories[$name];
51
+
52
+		return $factory();
53
+	}
54
+
55
+	/**
56
+	 * {@inheritdoc}
57
+	 */
58
+	public function getNames()
59
+	{
60
+		return array_keys($this->factories);
61
+	}
62 62
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -18,31 +18,27 @@  discard block
 block discarded – undo
18 18
  *
19 19
  * @author Maxime Steinhausser <[email protected]>
20 20
  */
21
-class FactoryCommandLoader implements CommandLoaderInterface
22
-{
21
+class FactoryCommandLoader implements CommandLoaderInterface {
23 22
     private $factories;
24 23
 
25 24
     /**
26 25
      * @param callable[] $factories Indexed by command names
27 26
      */
28
-    public function __construct(array $factories)
29
-    {
27
+    public function __construct(array $factories) {
30 28
         $this->factories = $factories;
31 29
     }
32 30
 
33 31
     /**
34 32
      * {@inheritdoc}
35 33
      */
36
-    public function has(string $name)
37
-    {
34
+    public function has(string $name) {
38 35
         return isset($this->factories[$name]);
39 36
     }
40 37
 
41 38
     /**
42 39
      * {@inheritdoc}
43 40
      */
44
-    public function get(string $name)
45
-    {
41
+    public function get(string $name) {
46 42
         if (!isset($this->factories[$name])) {
47 43
             throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
48 44
         }
@@ -55,8 +51,7 @@  discard block
 block discarded – undo
55 51
     /**
56 52
      * {@inheritdoc}
57 53
      */
58
-    public function getNames()
59
-    {
54
+    public function getNames() {
60 55
         return array_keys($this->factories);
61 56
     }
62 57
 }
Please login to merge, or discard this patch.
vendor/symfony/console/CommandLoader/CommandLoaderInterface.php 3 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -19,24 +19,24 @@
 block discarded – undo
19 19
  */
20 20
 interface CommandLoaderInterface
21 21
 {
22
-    /**
23
-     * Loads a command.
24
-     *
25
-     * @return Command
26
-     *
27
-     * @throws CommandNotFoundException
28
-     */
29
-    public function get(string $name);
22
+	/**
23
+	 * Loads a command.
24
+	 *
25
+	 * @return Command
26
+	 *
27
+	 * @throws CommandNotFoundException
28
+	 */
29
+	public function get(string $name);
30 30
 
31
-    /**
32
-     * Checks if a command exists.
33
-     *
34
-     * @return bool
35
-     */
36
-    public function has(string $name);
31
+	/**
32
+	 * Checks if a command exists.
33
+	 *
34
+	 * @return bool
35
+	 */
36
+	public function has(string $name);
37 37
 
38
-    /**
39
-     * @return string[] All registered command names
40
-     */
41
-    public function getNames();
38
+	/**
39
+	 * @return string[] All registered command names
40
+	 */
41
+	public function getNames();
42 42
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,14 +26,14 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@
 block discarded – undo
17 17
 /**
18 18
  * @author Robin Chalas <[email protected]>
19 19
  */
20
-interface CommandLoaderInterface
21
-{
20
+interface CommandLoaderInterface {
22 21
     /**
23 22
      * Loads a command.
24 23
      *
Please login to merge, or discard this patch.
vendor/symfony/console/CommandLoader/ContainerCommandLoader.php 3 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -21,43 +21,43 @@
 block discarded – undo
21 21
  */
22 22
 class ContainerCommandLoader implements CommandLoaderInterface
23 23
 {
24
-    private $container;
25
-    private $commandMap;
26
-
27
-    /**
28
-     * @param array $commandMap An array with command names as keys and service ids as values
29
-     */
30
-    public function __construct(ContainerInterface $container, array $commandMap)
31
-    {
32
-        $this->container = $container;
33
-        $this->commandMap = $commandMap;
34
-    }
35
-
36
-    /**
37
-     * {@inheritdoc}
38
-     */
39
-    public function get(string $name)
40
-    {
41
-        if (!$this->has($name)) {
42
-            throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
43
-        }
44
-
45
-        return $this->container->get($this->commandMap[$name]);
46
-    }
47
-
48
-    /**
49
-     * {@inheritdoc}
50
-     */
51
-    public function has(string $name)
52
-    {
53
-        return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]);
54
-    }
55
-
56
-    /**
57
-     * {@inheritdoc}
58
-     */
59
-    public function getNames()
60
-    {
61
-        return array_keys($this->commandMap);
62
-    }
24
+	private $container;
25
+	private $commandMap;
26
+
27
+	/**
28
+	 * @param array $commandMap An array with command names as keys and service ids as values
29
+	 */
30
+	public function __construct(ContainerInterface $container, array $commandMap)
31
+	{
32
+		$this->container = $container;
33
+		$this->commandMap = $commandMap;
34
+	}
35
+
36
+	/**
37
+	 * {@inheritdoc}
38
+	 */
39
+	public function get(string $name)
40
+	{
41
+		if (!$this->has($name)) {
42
+			throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
43
+		}
44
+
45
+		return $this->container->get($this->commandMap[$name]);
46
+	}
47
+
48
+	/**
49
+	 * {@inheritdoc}
50
+	 */
51
+	public function has(string $name)
52
+	{
53
+		return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]);
54
+	}
55
+
56
+	/**
57
+	 * {@inheritdoc}
58
+	 */
59
+	public function getNames()
60
+	{
61
+		return array_keys($this->commandMap);
62
+	}
63 63
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -19,16 +19,14 @@  discard block
 block discarded – undo
19 19
  *
20 20
  * @author Robin Chalas <[email protected]>
21 21
  */
22
-class ContainerCommandLoader implements CommandLoaderInterface
23
-{
22
+class ContainerCommandLoader implements CommandLoaderInterface {
24 23
     private $container;
25 24
     private $commandMap;
26 25
 
27 26
     /**
28 27
      * @param array $commandMap An array with command names as keys and service ids as values
29 28
      */
30
-    public function __construct(ContainerInterface $container, array $commandMap)
31
-    {
29
+    public function __construct(ContainerInterface $container, array $commandMap) {
32 30
         $this->container = $container;
33 31
         $this->commandMap = $commandMap;
34 32
     }
@@ -36,8 +34,7 @@  discard block
 block discarded – undo
36 34
     /**
37 35
      * {@inheritdoc}
38 36
      */
39
-    public function get(string $name)
40
-    {
37
+    public function get(string $name) {
41 38
         if (!$this->has($name)) {
42 39
             throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
43 40
         }
@@ -48,16 +45,14 @@  discard block
 block discarded – undo
48 45
     /**
49 46
      * {@inheritdoc}
50 47
      */
51
-    public function has(string $name)
52
-    {
48
+    public function has(string $name) {
53 49
         return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]);
54 50
     }
55 51
 
56 52
     /**
57 53
      * {@inheritdoc}
58 54
      */
59
-    public function getNames()
60
-    {
55
+    public function getNames() {
61 56
         return array_keys($this->commandMap);
62 57
     }
63 58
 }
Please login to merge, or discard this patch.
vendor/symfony/console/Color.php 3 patches
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -18,163 +18,163 @@
 block discarded – undo
18 18
  */
19 19
 final class Color
20 20
 {
21
-    private const COLORS = [
22
-        'black' => 0,
23
-        'red' => 1,
24
-        'green' => 2,
25
-        'yellow' => 3,
26
-        'blue' => 4,
27
-        'magenta' => 5,
28
-        'cyan' => 6,
29
-        'white' => 7,
30
-        'default' => 9,
31
-    ];
32
-
33
-    private const BRIGHT_COLORS = [
34
-        'gray' => 0,
35
-        'bright-red' => 1,
36
-        'bright-green' => 2,
37
-        'bright-yellow' => 3,
38
-        'bright-blue' => 4,
39
-        'bright-magenta' => 5,
40
-        'bright-cyan' => 6,
41
-        'bright-white' => 7,
42
-    ];
43
-
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],
50
-    ];
51
-
52
-    private $foreground;
53
-    private $background;
54
-    private $options = [];
55
-
56
-    public function __construct(string $foreground = '', string $background = '', array $options = [])
57
-    {
58
-        $this->foreground = $this->parseColor($foreground);
59
-        $this->background = $this->parseColor($background, true);
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))));
64
-            }
65
-
66
-            $this->options[$option] = self::AVAILABLE_OPTIONS[$option];
67
-        }
68
-    }
69
-
70
-    public function apply(string $text): string
71
-    {
72
-        return $this->set().$text.$this->unset();
73
-    }
74
-
75
-    public function set(): string
76
-    {
77
-        $setCodes = [];
78
-        if ('' !== $this->foreground) {
79
-            $setCodes[] = $this->foreground;
80
-        }
81
-        if ('' !== $this->background) {
82
-            $setCodes[] = $this->background;
83
-        }
84
-        foreach ($this->options as $option) {
85
-            $setCodes[] = $option['set'];
86
-        }
87
-        if (0 === \count($setCodes)) {
88
-            return '';
89
-        }
90
-
91
-        return sprintf("\033[%sm", implode(';', $setCodes));
92
-    }
93
-
94
-    public function unset(): string
95
-    {
96
-        $unsetCodes = [];
97
-        if ('' !== $this->foreground) {
98
-            $unsetCodes[] = 39;
99
-        }
100
-        if ('' !== $this->background) {
101
-            $unsetCodes[] = 49;
102
-        }
103
-        foreach ($this->options as $option) {
104
-            $unsetCodes[] = $option['unset'];
105
-        }
106
-        if (0 === \count($unsetCodes)) {
107
-            return '';
108
-        }
109
-
110
-        return sprintf("\033[%sm", implode(';', $unsetCodes));
111
-    }
112
-
113
-    private function parseColor(string $color, bool $background = false): string
114
-    {
115
-        if ('' === $color) {
116
-            return '';
117
-        }
118
-
119
-        if ('#' === $color[0]) {
120
-            $color = substr($color, 1);
121
-
122
-            if (3 === \strlen($color)) {
123
-                $color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
124
-            }
125
-
126
-            if (6 !== \strlen($color)) {
127
-                throw new InvalidArgumentException(sprintf('Invalid "%s" color.', $color));
128
-            }
129
-
130
-            return ($background ? '4' : '3').$this->convertHexColorToAnsi(hexdec($color));
131
-        }
132
-
133
-        if (isset(self::COLORS[$color])) {
134
-            return ($background ? '4' : '3').self::COLORS[$color];
135
-        }
136
-
137
-        if (isset(self::BRIGHT_COLORS[$color])) {
138
-            return ($background ? '10' : '9').self::BRIGHT_COLORS[$color];
139
-        }
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)))));
142
-    }
143
-
144
-    private function convertHexColorToAnsi(int $color): string
145
-    {
146
-        $r = ($color >> 16) & 255;
147
-        $g = ($color >> 8) & 255;
148
-        $b = $color & 255;
149
-
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);
153
-        }
154
-
155
-        return sprintf('8;2;%d;%d;%d', $r, $g, $b);
156
-    }
157
-
158
-    private function degradeHexColorToAnsi(int $r, int $g, int $b): int
159
-    {
160
-        if (0 === round($this->getSaturation($r, $g, $b) / 50)) {
161
-            return 0;
162
-        }
163
-
164
-        return (round($b / 255) << 2) | (round($g / 255) << 1) | round($r / 255);
165
-    }
166
-
167
-    private function getSaturation(int $r, int $g, int $b): int
168
-    {
169
-        $r = $r / 255;
170
-        $g = $g / 255;
171
-        $b = $b / 255;
172
-        $v = max($r, $g, $b);
173
-
174
-        if (0 === $diff = $v - min($r, $g, $b)) {
175
-            return 0;
176
-        }
177
-
178
-        return (int) $diff * 100 / $v;
179
-    }
21
+	private const COLORS = [
22
+		'black' => 0,
23
+		'red' => 1,
24
+		'green' => 2,
25
+		'yellow' => 3,
26
+		'blue' => 4,
27
+		'magenta' => 5,
28
+		'cyan' => 6,
29
+		'white' => 7,
30
+		'default' => 9,
31
+	];
32
+
33
+	private const BRIGHT_COLORS = [
34
+		'gray' => 0,
35
+		'bright-red' => 1,
36
+		'bright-green' => 2,
37
+		'bright-yellow' => 3,
38
+		'bright-blue' => 4,
39
+		'bright-magenta' => 5,
40
+		'bright-cyan' => 6,
41
+		'bright-white' => 7,
42
+	];
43
+
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],
50
+	];
51
+
52
+	private $foreground;
53
+	private $background;
54
+	private $options = [];
55
+
56
+	public function __construct(string $foreground = '', string $background = '', array $options = [])
57
+	{
58
+		$this->foreground = $this->parseColor($foreground);
59
+		$this->background = $this->parseColor($background, true);
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))));
64
+			}
65
+
66
+			$this->options[$option] = self::AVAILABLE_OPTIONS[$option];
67
+		}
68
+	}
69
+
70
+	public function apply(string $text): string
71
+	{
72
+		return $this->set().$text.$this->unset();
73
+	}
74
+
75
+	public function set(): string
76
+	{
77
+		$setCodes = [];
78
+		if ('' !== $this->foreground) {
79
+			$setCodes[] = $this->foreground;
80
+		}
81
+		if ('' !== $this->background) {
82
+			$setCodes[] = $this->background;
83
+		}
84
+		foreach ($this->options as $option) {
85
+			$setCodes[] = $option['set'];
86
+		}
87
+		if (0 === \count($setCodes)) {
88
+			return '';
89
+		}
90
+
91
+		return sprintf("\033[%sm", implode(';', $setCodes));
92
+	}
93
+
94
+	public function unset(): string
95
+	{
96
+		$unsetCodes = [];
97
+		if ('' !== $this->foreground) {
98
+			$unsetCodes[] = 39;
99
+		}
100
+		if ('' !== $this->background) {
101
+			$unsetCodes[] = 49;
102
+		}
103
+		foreach ($this->options as $option) {
104
+			$unsetCodes[] = $option['unset'];
105
+		}
106
+		if (0 === \count($unsetCodes)) {
107
+			return '';
108
+		}
109
+
110
+		return sprintf("\033[%sm", implode(';', $unsetCodes));
111
+	}
112
+
113
+	private function parseColor(string $color, bool $background = false): string
114
+	{
115
+		if ('' === $color) {
116
+			return '';
117
+		}
118
+
119
+		if ('#' === $color[0]) {
120
+			$color = substr($color, 1);
121
+
122
+			if (3 === \strlen($color)) {
123
+				$color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
124
+			}
125
+
126
+			if (6 !== \strlen($color)) {
127
+				throw new InvalidArgumentException(sprintf('Invalid "%s" color.', $color));
128
+			}
129
+
130
+			return ($background ? '4' : '3').$this->convertHexColorToAnsi(hexdec($color));
131
+		}
132
+
133
+		if (isset(self::COLORS[$color])) {
134
+			return ($background ? '4' : '3').self::COLORS[$color];
135
+		}
136
+
137
+		if (isset(self::BRIGHT_COLORS[$color])) {
138
+			return ($background ? '10' : '9').self::BRIGHT_COLORS[$color];
139
+		}
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)))));
142
+	}
143
+
144
+	private function convertHexColorToAnsi(int $color): string
145
+	{
146
+		$r = ($color >> 16) & 255;
147
+		$g = ($color >> 8) & 255;
148
+		$b = $color & 255;
149
+
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);
153
+		}
154
+
155
+		return sprintf('8;2;%d;%d;%d', $r, $g, $b);
156
+	}
157
+
158
+	private function degradeHexColorToAnsi(int $r, int $g, int $b): int
159
+	{
160
+		if (0 === round($this->getSaturation($r, $g, $b) / 50)) {
161
+			return 0;
162
+		}
163
+
164
+		return (round($b / 255) << 2) | (round($g / 255) << 1) | round($r / 255);
165
+	}
166
+
167
+	private function getSaturation(int $r, int $g, int $b): int
168
+	{
169
+		$r = $r / 255;
170
+		$g = $g / 255;
171
+		$b = $b / 255;
172
+		$v = max($r, $g, $b);
173
+
174
+		if (0 === $diff = $v - min($r, $g, $b)) {
175
+			return 0;
176
+		}
177
+
178
+		return (int) $diff * 100 / $v;
179
+	}
180 180
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -42,139 +42,139 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,8 +16,7 @@  discard block
 block discarded – undo
16 16
 /**
17 17
  * @author Fabien Potencier <[email protected]>
18 18
  */
19
-final class Color
20
-{
19
+final class Color {
21 20
     private const COLORS = [
22 21
         'black' => 0,
23 22
         'red' => 1,
@@ -53,8 +52,7 @@  discard block
 block discarded – undo
53 52
     private $background;
54 53
     private $options = [];
55 54
 
56
-    public function __construct(string $foreground = '', string $background = '', array $options = [])
57
-    {
55
+    public function __construct(string $foreground = '', string $background = '', array $options = []) {
58 56
         $this->foreground = $this->parseColor($foreground);
59 57
         $this->background = $this->parseColor($background, true);
60 58
 
Please login to merge, or discard this patch.
vendor/symfony/console/Application.php 3 patches
Indentation   +1170 added lines, -1170 removed lines patch added patch discarded remove patch
@@ -66,1174 +66,1174 @@
 block discarded – undo
66 66
  */
67 67
 class Application implements ResetInterface
68 68
 {
69
-    private $commands = [];
70
-    private $wantHelps = false;
71
-    private $runningCommand;
72
-    private $name;
73
-    private $version;
74
-    private $commandLoader;
75
-    private $catchExceptions = true;
76
-    private $autoExit = true;
77
-    private $definition;
78
-    private $helperSet;
79
-    private $dispatcher;
80
-    private $terminal;
81
-    private $defaultCommand;
82
-    private $singleCommand = false;
83
-    private $initialized;
84
-    private $signalRegistry;
85
-    private $signalsToDispatchEvent = [];
86
-
87
-    public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
88
-    {
89
-        $this->name = $name;
90
-        $this->version = $version;
91
-        $this->terminal = new Terminal();
92
-        $this->defaultCommand = 'list';
93
-        if (\defined('SIGINT') && SignalRegistry::isSupported()) {
94
-            $this->signalRegistry = new SignalRegistry();
95
-            $this->signalsToDispatchEvent = [\SIGINT, \SIGTERM, \SIGUSR1, \SIGUSR2];
96
-        }
97
-    }
98
-
99
-    /**
100
-     * @final
101
-     */
102
-    public function setDispatcher(EventDispatcherInterface $dispatcher)
103
-    {
104
-        $this->dispatcher = $dispatcher;
105
-    }
106
-
107
-    public function setCommandLoader(CommandLoaderInterface $commandLoader)
108
-    {
109
-        $this->commandLoader = $commandLoader;
110
-    }
111
-
112
-    public function getSignalRegistry(): SignalRegistry
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.');
116
-        }
117
-
118
-        return $this->signalRegistry;
119
-    }
120
-
121
-    public function setSignalsToDispatchEvent(int ...$signalsToDispatchEvent)
122
-    {
123
-        $this->signalsToDispatchEvent = $signalsToDispatchEvent;
124
-    }
125
-
126
-    /**
127
-     * Runs the current application.
128
-     *
129
-     * @return int 0 if everything went fine, or an error code
130
-     *
131
-     * @throws \Exception When running fails. Bypass this when {@link setCatchExceptions()}.
132
-     */
133
-    public function run(InputInterface $input = null, OutputInterface $output = null)
134
-    {
135
-        if (\function_exists('putenv')) {
136
-            @putenv('LINES='.$this->terminal->getHeight());
137
-            @putenv('COLUMNS='.$this->terminal->getWidth());
138
-        }
139
-
140
-        if (null === $input) {
141
-            $input = new ArgvInput();
142
-        }
143
-
144
-        if (null === $output) {
145
-            $output = new ConsoleOutput();
146
-        }
147
-
148
-        $renderException = function (\Throwable $e) use ($output) {
149
-            if ($output instanceof ConsoleOutputInterface) {
150
-                $this->renderThrowable($e, $output->getErrorOutput());
151
-            } else {
152
-                $this->renderThrowable($e, $output);
153
-            }
154
-        };
155
-        if ($phpHandler = set_exception_handler($renderException)) {
156
-            restore_exception_handler();
157
-            if (!\is_array($phpHandler) || !$phpHandler[0] instanceof ErrorHandler) {
158
-                $errorHandler = true;
159
-            } elseif ($errorHandler = $phpHandler[0]->setExceptionHandler($renderException)) {
160
-                $phpHandler[0]->setExceptionHandler($errorHandler);
161
-            }
162
-        }
163
-
164
-        $this->configureIO($input, $output);
165
-
166
-        try {
167
-            $exitCode = $this->doRun($input, $output);
168
-        } catch (\Exception $e) {
169
-            if (!$this->catchExceptions) {
170
-                throw $e;
171
-            }
172
-
173
-            $renderException($e);
174
-
175
-            $exitCode = $e->getCode();
176
-            if (is_numeric($exitCode)) {
177
-                $exitCode = (int) $exitCode;
178
-                if (0 === $exitCode) {
179
-                    $exitCode = 1;
180
-                }
181
-            } else {
182
-                $exitCode = 1;
183
-            }
184
-        } finally {
185
-            // if the exception handler changed, keep it
186
-            // otherwise, unregister $renderException
187
-            if (!$phpHandler) {
188
-                if (set_exception_handler($renderException) === $renderException) {
189
-                    restore_exception_handler();
190
-                }
191
-                restore_exception_handler();
192
-            } elseif (!$errorHandler) {
193
-                $finalHandler = $phpHandler[0]->setExceptionHandler(null);
194
-                if ($finalHandler !== $renderException) {
195
-                    $phpHandler[0]->setExceptionHandler($finalHandler);
196
-                }
197
-            }
198
-        }
199
-
200
-        if ($this->autoExit) {
201
-            if ($exitCode > 255) {
202
-                $exitCode = 255;
203
-            }
204
-
205
-            exit($exitCode);
206
-        }
207
-
208
-        return $exitCode;
209
-    }
210
-
211
-    /**
212
-     * Runs the current application.
213
-     *
214
-     * @return int 0 if everything went fine, or an error code
215
-     */
216
-    public function doRun(InputInterface $input, OutputInterface $output)
217
-    {
218
-        if (true === $input->hasParameterOption(['--version', '-V'], true)) {
219
-            $output->writeln($this->getLongVersion());
220
-
221
-            return 0;
222
-        }
223
-
224
-        try {
225
-            // Makes ArgvInput::getFirstArgument() able to distinguish an option from an argument.
226
-            $input->bind($this->getDefinition());
227
-        } catch (ExceptionInterface $e) {
228
-            // Errors must be ignored, full binding/validation happens later when the command is known.
229
-        }
230
-
231
-        $name = $this->getCommandName($input);
232
-        if (true === $input->hasParameterOption(['--help', '-h'], true)) {
233
-            if (!$name) {
234
-                $name = 'help';
235
-                $input = new ArrayInput(['command_name' => $this->defaultCommand]);
236
-            } else {
237
-                $this->wantHelps = true;
238
-            }
239
-        }
240
-
241
-        if (!$name) {
242
-            $name = $this->defaultCommand;
243
-            $definition = $this->getDefinition();
244
-            $definition->setArguments(array_merge(
245
-                $definition->getArguments(),
246
-                [
247
-                    'command' => new InputArgument('command', InputArgument::OPTIONAL, $definition->getArgument('command')->getDescription(), $name),
248
-                ]
249
-            ));
250
-        }
251
-
252
-        try {
253
-            $this->runningCommand = null;
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()) {
263
-                        return 0;
264
-                    }
265
-
266
-                    $e = $event->getError();
267
-                }
268
-
269
-                throw $e;
270
-            }
271
-
272
-            $alternative = $alternatives[0];
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);
280
-
281
-                    return $event->getExitCode();
282
-                }
283
-
284
-                return 1;
285
-            }
286
-
287
-            $command = $this->find($alternative);
288
-        }
289
-
290
-        if ($command instanceof LazyCommand) {
291
-            $command = $command->getCommand();
292
-        }
293
-
294
-        $this->runningCommand = $command;
295
-        $exitCode = $this->doRunCommand($command, $input, $output);
296
-        $this->runningCommand = null;
297
-
298
-        return $exitCode;
299
-    }
300
-
301
-    /**
302
-     * {@inheritdoc}
303
-     */
304
-    public function reset()
305
-    {
306
-    }
307
-
308
-    public function setHelperSet(HelperSet $helperSet)
309
-    {
310
-        $this->helperSet = $helperSet;
311
-    }
312
-
313
-    /**
314
-     * Get the helper set associated with the command.
315
-     *
316
-     * @return HelperSet The HelperSet instance associated with this command
317
-     */
318
-    public function getHelperSet()
319
-    {
320
-        if (!$this->helperSet) {
321
-            $this->helperSet = $this->getDefaultHelperSet();
322
-        }
323
-
324
-        return $this->helperSet;
325
-    }
326
-
327
-    public function setDefinition(InputDefinition $definition)
328
-    {
329
-        $this->definition = $definition;
330
-    }
331
-
332
-    /**
333
-     * Gets the InputDefinition related to this Application.
334
-     *
335
-     * @return InputDefinition The InputDefinition instance
336
-     */
337
-    public function getDefinition()
338
-    {
339
-        if (!$this->definition) {
340
-            $this->definition = $this->getDefaultInputDefinition();
341
-        }
342
-
343
-        if ($this->singleCommand) {
344
-            $inputDefinition = $this->definition;
345
-            $inputDefinition->setArguments();
346
-
347
-            return $inputDefinition;
348
-        }
349
-
350
-        return $this->definition;
351
-    }
352
-
353
-    /**
354
-     * Gets the help message.
355
-     *
356
-     * @return string A help message
357
-     */
358
-    public function getHelp()
359
-    {
360
-        return $this->getLongVersion();
361
-    }
362
-
363
-    /**
364
-     * Gets whether to catch exceptions or not during commands execution.
365
-     *
366
-     * @return bool Whether to catch exceptions or not during commands execution
367
-     */
368
-    public function areExceptionsCaught()
369
-    {
370
-        return $this->catchExceptions;
371
-    }
372
-
373
-    /**
374
-     * Sets whether to catch exceptions or not during commands execution.
375
-     */
376
-    public function setCatchExceptions(bool $boolean)
377
-    {
378
-        $this->catchExceptions = $boolean;
379
-    }
380
-
381
-    /**
382
-     * Gets whether to automatically exit after a command execution or not.
383
-     *
384
-     * @return bool Whether to automatically exit after a command execution or not
385
-     */
386
-    public function isAutoExitEnabled()
387
-    {
388
-        return $this->autoExit;
389
-    }
390
-
391
-    /**
392
-     * Sets whether to automatically exit after a command execution or not.
393
-     */
394
-    public function setAutoExit(bool $boolean)
395
-    {
396
-        $this->autoExit = $boolean;
397
-    }
398
-
399
-    /**
400
-     * Gets the name of the application.
401
-     *
402
-     * @return string The application name
403
-     */
404
-    public function getName()
405
-    {
406
-        return $this->name;
407
-    }
408
-
409
-    /**
410
-     * Sets the application name.
411
-     **/
412
-    public function setName(string $name)
413
-    {
414
-        $this->name = $name;
415
-    }
416
-
417
-    /**
418
-     * Gets the application version.
419
-     *
420
-     * @return string The application version
421
-     */
422
-    public function getVersion()
423
-    {
424
-        return $this->version;
425
-    }
426
-
427
-    /**
428
-     * Sets the application version.
429
-     */
430
-    public function setVersion(string $version)
431
-    {
432
-        $this->version = $version;
433
-    }
434
-
435
-    /**
436
-     * Returns the long version of the application.
437
-     *
438
-     * @return string The long application version
439
-     */
440
-    public function getLongVersion()
441
-    {
442
-        if ('UNKNOWN' !== $this->getName()) {
443
-            if ('UNKNOWN' !== $this->getVersion()) {
444
-                return sprintf('%s <info>%s</info>', $this->getName(), $this->getVersion());
445
-            }
446
-
447
-            return $this->getName();
448
-        }
449
-
450
-        return 'Console Tool';
451
-    }
452
-
453
-    /**
454
-     * Registers a new command.
455
-     *
456
-     * @return Command The newly created command
457
-     */
458
-    public function register(string $name)
459
-    {
460
-        return $this->add(new Command($name));
461
-    }
462
-
463
-    /**
464
-     * Adds an array of command objects.
465
-     *
466
-     * If a Command is not enabled it will not be added.
467
-     *
468
-     * @param Command[] $commands An array of commands
469
-     */
470
-    public function addCommands(array $commands)
471
-    {
472
-        foreach ($commands as $command) {
473
-            $this->add($command);
474
-        }
475
-    }
476
-
477
-    /**
478
-     * Adds a command object.
479
-     *
480
-     * If a command with the same name already exists, it will be overridden.
481
-     * If the command is not enabled it will not be added.
482
-     *
483
-     * @return Command|null The registered command if enabled or null
484
-     */
485
-    public function add(Command $command)
486
-    {
487
-        $this->init();
488
-
489
-        $command->setApplication($this);
490
-
491
-        if (!$command->isEnabled()) {
492
-            $command->setApplication(null);
493
-
494
-            return null;
495
-        }
496
-
497
-        if (!$command instanceof LazyCommand) {
498
-            // Will throw if the command is not correctly initialized.
499
-            $command->getDefinition();
500
-        }
501
-
502
-        if (!$command->getName()) {
503
-            throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_debug_type($command)));
504
-        }
505
-
506
-        $this->commands[$command->getName()] = $command;
507
-
508
-        foreach ($command->getAliases() as $alias) {
509
-            $this->commands[$alias] = $command;
510
-        }
511
-
512
-        return $command;
513
-    }
514
-
515
-    /**
516
-     * Returns a registered command by name or alias.
517
-     *
518
-     * @return Command A Command object
519
-     *
520
-     * @throws CommandNotFoundException When given command name does not exist
521
-     */
522
-    public function get(string $name)
523
-    {
524
-        $this->init();
525
-
526
-        if (!$this->has($name)) {
527
-            throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
528
-        }
529
-
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));
533
-        }
534
-
535
-        $command = $this->commands[$name];
536
-
537
-        if ($this->wantHelps) {
538
-            $this->wantHelps = false;
539
-
540
-            $helpCommand = $this->get('help');
541
-            $helpCommand->setCommand($command);
542
-
543
-            return $helpCommand;
544
-        }
545
-
546
-        return $command;
547
-    }
548
-
549
-    /**
550
-     * Returns true if the command exists, false otherwise.
551
-     *
552
-     * @return bool true if the command exists, false otherwise
553
-     */
554
-    public function has(string $name)
555
-    {
556
-        $this->init();
557
-
558
-        return isset($this->commands[$name]) || ($this->commandLoader && $this->commandLoader->has($name) && $this->add($this->commandLoader->get($name)));
559
-    }
560
-
561
-    /**
562
-     * Returns an array of all unique namespaces used by currently registered commands.
563
-     *
564
-     * It does not return the global namespace which always exists.
565
-     *
566
-     * @return string[] An array of namespaces
567
-     */
568
-    public function getNamespaces()
569
-    {
570
-        $namespaces = [];
571
-        foreach ($this->all() as $command) {
572
-            if ($command->isHidden()) {
573
-                continue;
574
-            }
575
-
576
-            $namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
577
-
578
-            foreach ($command->getAliases() as $alias) {
579
-                $namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
580
-            }
581
-        }
582
-
583
-        return array_values(array_unique(array_filter($namespaces)));
584
-    }
585
-
586
-    /**
587
-     * Finds a registered namespace by a name or an abbreviation.
588
-     *
589
-     * @return string A registered namespace
590
-     *
591
-     * @throws NamespaceNotFoundException When namespace is incorrect or ambiguous
592
-     */
593
-    public function findNamespace(string $namespace)
594
-    {
595
-        $allNamespaces = $this->getNamespaces();
596
-        $expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))).'[^:]*';
597
-        $namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);
598
-
599
-        if (empty($namespaces)) {
600
-            $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
601
-
602
-            if ($alternatives = $this->findAlternatives($namespace, $allNamespaces)) {
603
-                if (1 == \count($alternatives)) {
604
-                    $message .= "\n\nDid you mean this?\n    ";
605
-                } else {
606
-                    $message .= "\n\nDid you mean one of these?\n    ";
607
-                }
608
-
609
-                $message .= implode("\n    ", $alternatives);
610
-            }
611
-
612
-            throw new NamespaceNotFoundException($message, $alternatives);
613
-        }
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));
618
-        }
619
-
620
-        return $exact ? $namespace : reset($namespaces);
621
-    }
622
-
623
-    /**
624
-     * Finds a command by name or alias.
625
-     *
626
-     * Contrary to get, this command tries to find the best
627
-     * match if you give it an abbreviation of a name or alias.
628
-     *
629
-     * @return Command A Command instance
630
-     *
631
-     * @throws CommandNotFoundException When command name is incorrect or ambiguous
632
-     */
633
-    public function find(string $name)
634
-    {
635
-        $this->init();
636
-
637
-        $aliases = [];
638
-
639
-        foreach ($this->commands as $command) {
640
-            foreach ($command->getAliases() as $alias) {
641
-                if (!$this->has($alias)) {
642
-                    $this->commands[$alias] = $command;
643
-                }
644
-            }
645
-        }
646
-
647
-        if ($this->has($name)) {
648
-            return $this->get($name);
649
-        }
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);
654
-
655
-        if (empty($commands)) {
656
-            $commands = preg_grep('{^'.$expr.'}i', $allCommands);
657
-        }
658
-
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, ':')) {
662
-                // check if a namespace exists and contains commands
663
-                $this->findNamespace(substr($name, 0, $pos));
664
-            }
665
-
666
-            $message = sprintf('Command "%s" is not defined.', $name);
667
-
668
-            if ($alternatives = $this->findAlternatives($name, $allCommands)) {
669
-                // remove hidden commands
670
-                $alternatives = array_filter($alternatives, function ($name) {
671
-                    return !$this->get($name)->isHidden();
672
-                });
673
-
674
-                if (1 == \count($alternatives)) {
675
-                    $message .= "\n\nDid you mean this?\n    ";
676
-                } else {
677
-                    $message .= "\n\nDid you mean one of these?\n    ";
678
-                }
679
-                $message .= implode("\n    ", $alternatives);
680
-            }
681
-
682
-            throw new CommandNotFoundException($message, array_values($alternatives));
683
-        }
684
-
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);
691
-                }
692
-
693
-                $commandName = $commandList[$nameOrAlias]->getName();
694
-
695
-                $aliases[$nameOrAlias] = $commandName;
696
-
697
-                return $commandName === $nameOrAlias || !\in_array($commandName, $commands);
698
-            }));
699
-        }
700
-
701
-        if (\count($commands) > 1) {
702
-            $usableWidth = $this->terminal->getWidth() - 10;
703
-            $abbrevs = array_values($commands);
704
-            $maxLen = 0;
705
-            foreach ($abbrevs as $abbrev) {
706
-                $maxLen = max(Helper::width($abbrev), $maxLen);
707
-            }
708
-            $abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen, &$commands) {
709
-                if ($commandList[$cmd]->isHidden()) {
710
-                    unset($commands[array_search($cmd, $commands)]);
711
-
712
-                    return false;
713
-                }
714
-
715
-                $abbrev = str_pad($cmd, $maxLen, ' ').' '.$commandList[$cmd]->getDescription();
716
-
717
-                return Helper::width($abbrev) > $usableWidth ? Helper::substr($abbrev, 0, $usableWidth - 3).'...' : $abbrev;
718
-            }, array_values($commands));
719
-
720
-            if (\count($commands) > 1) {
721
-                $suggestions = $this->getAbbreviationSuggestions(array_filter($abbrevs));
722
-
723
-                throw new CommandNotFoundException(sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", $name, $suggestions), array_values($commands));
724
-            }
725
-        }
726
-
727
-        $command = $this->get(reset($commands));
728
-
729
-        if ($command->isHidden()) {
730
-            throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
731
-        }
732
-
733
-        return $command;
734
-    }
735
-
736
-    /**
737
-     * Gets the commands (registered in the given namespace if provided).
738
-     *
739
-     * The array keys are the full names and the values the command instances.
740
-     *
741
-     * @return Command[] An array of Command instances
742
-     */
743
-    public function all(string $namespace = null)
744
-    {
745
-        $this->init();
746
-
747
-        if (null === $namespace) {
748
-            if (!$this->commandLoader) {
749
-                return $this->commands;
750
-            }
751
-
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);
756
-                }
757
-            }
758
-
759
-            return $commands;
760
-        }
761
-
762
-        $commands = [];
763
-        foreach ($this->commands as $name => $command) {
764
-            if ($namespace === $this->extractNamespace($name, substr_count($namespace, ':') + 1)) {
765
-                $commands[$name] = $command;
766
-            }
767
-        }
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);
773
-                }
774
-            }
775
-        }
776
-
777
-        return $commands;
778
-    }
779
-
780
-    /**
781
-     * Returns an array of possible abbreviations given a set of names.
782
-     *
783
-     * @return string[][] An array of abbreviations
784
-     */
785
-    public static function getAbbreviations(array $names)
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;
792
-            }
793
-        }
794
-
795
-        return $abbrevs;
796
-    }
797
-
798
-    public function renderThrowable(\Throwable $e, OutputInterface $output): void
799
-    {
800
-        $output->writeln('', OutputInterface::VERBOSITY_QUIET);
801
-
802
-        $this->doRenderThrowable($e, $output);
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);
807
-        }
808
-    }
809
-
810
-    protected function doRenderThrowable(\Throwable $e, OutputInterface $output): void
811
-    {
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);
818
-            } else {
819
-                $len = 0;
820
-            }
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);
826
-            }
827
-
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) {
832
-                    // pre-format lines to get the right string length
833
-                    $lineLength = Helper::width($line) + 4;
834
-                    $lines[] = [$line, $lineLength];
835
-
836
-                    $len = max($lineLength, $len);
837
-                }
838
-            }
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')));
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))));
847
-            }
848
-            foreach ($lines as $line) {
849
-                $messages[] = sprintf('<error>  %s  %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
850
-            }
851
-            $messages[] = $emptyLine;
852
-            $messages[] = '';
853
-
854
-            $output->writeln($messages, OutputInterface::VERBOSITY_QUIET);
855
-
856
-            if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
857
-                $output->writeln('<comment>Exception trace:</comment>', OutputInterface::VERBOSITY_QUIET);
858
-
859
-                // exception related properties
860
-                $trace = $e->getTrace();
861
-
862
-                array_unshift($trace, [
863
-                    'function' => '',
864
-                    'file' => $e->getFile() ?: 'n/a',
865
-                    'line' => $e->getLine() ?: 'n/a',
866
-                    'args' => [],
867
-                ]);
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';
875
-
876
-                    $output->writeln(sprintf(' %s%s at <info>%s:%s</info>', $class, $function ? $type.$function.'()' : '', $file, $line), OutputInterface::VERBOSITY_QUIET);
877
-                }
878
-
879
-                $output->writeln('', OutputInterface::VERBOSITY_QUIET);
880
-            }
881
-        } while ($e = $e->getPrevious());
882
-    }
883
-
884
-    /**
885
-     * Configures the input and output instances based on the user arguments and options.
886
-     */
887
-    protected function configureIO(InputInterface $input, OutputInterface $output)
888
-    {
889
-        if (true === $input->hasParameterOption(['--ansi'], true)) {
890
-            $output->setDecorated(true);
891
-        } elseif (true === $input->hasParameterOption(['--no-ansi'], true)) {
892
-            $output->setDecorated(false);
893
-        }
894
-
895
-        if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) {
896
-            $input->setInteractive(false);
897
-        }
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;
904
-            default: $shellVerbosity = 0; break;
905
-        }
906
-
907
-        if (true === $input->hasParameterOption(['--quiet', '-q'], true)) {
908
-            $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
909
-            $shellVerbosity = -1;
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);
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);
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);
919
-                $shellVerbosity = 1;
920
-            }
921
-        }
922
-
923
-        if (-1 === $shellVerbosity) {
924
-            $input->setInteractive(false);
925
-        }
926
-
927
-        if (\function_exists('putenv')) {
928
-            @putenv('SHELL_VERBOSITY='.$shellVerbosity);
929
-        }
930
-        $_ENV['SHELL_VERBOSITY'] = $shellVerbosity;
931
-        $_SERVER['SHELL_VERBOSITY'] = $shellVerbosity;
932
-    }
933
-
934
-    /**
935
-     * Runs the current command.
936
-     *
937
-     * If an event dispatcher has been attached to the application,
938
-     * events are also dispatched during the life-cycle of the command.
939
-     *
940
-     * @return int 0 if everything went fine, or an error code
941
-     */
942
-    protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
943
-    {
944
-        foreach ($command->getHelperSet() as $helper) {
945
-            if ($helper instanceof InputAwareInterface) {
946
-                $helper->setInput($input);
947
-            }
948
-        }
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.');
953
-            }
954
-
955
-            if ($this->dispatcher) {
956
-                foreach ($this->signalsToDispatchEvent as $signal) {
957
-                    $event = new ConsoleSignalEvent($command, $input, $output, $signal);
958
-
959
-                    $this->signalRegistry->register($signal, function ($signal, $hasNext) use ($event) {
960
-                        $this->dispatcher->dispatch($event, ConsoleEvents::SIGNAL);
961
-
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);
966
-                            }
967
-                        }
968
-                    });
969
-                }
970
-            }
971
-
972
-            foreach ($command->getSubscribedSignals() as $signal) {
973
-                $this->signalRegistry->register($signal, [$command, 'handleSignal']);
974
-            }
975
-        }
976
-
977
-        if (null === $this->dispatcher) {
978
-            return $command->run($input, $output);
979
-        }
980
-
981
-        // bind before the console.command event, so the listeners have access to input options/arguments
982
-        try {
983
-            $command->mergeApplicationDefinition();
984
-            $input->bind($command->getDefinition());
985
-        } catch (ExceptionInterface $e) {
986
-            // ignore invalid options/arguments for now, to allow the event listeners to customize the InputDefinition
987
-        }
988
-
989
-        $event = new ConsoleCommandEvent($command, $input, $output);
990
-        $e = null;
991
-
992
-        try {
993
-            $this->dispatcher->dispatch($event, ConsoleEvents::COMMAND);
994
-
995
-            if ($event->commandShouldRun()) {
996
-                $exitCode = $command->run($input, $output);
997
-            } else {
998
-                $exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED;
999
-            }
1000
-        } catch (\Throwable $e) {
1001
-            $event = new ConsoleErrorEvent($input, $output, $e, $command);
1002
-            $this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
1003
-            $e = $event->getError();
1004
-
1005
-            if (0 === $exitCode = $event->getExitCode()) {
1006
-                $e = null;
1007
-            }
1008
-        }
1009
-
1010
-        $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
1011
-        $this->dispatcher->dispatch($event, ConsoleEvents::TERMINATE);
1012
-
1013
-        if (null !== $e) {
1014
-            throw $e;
1015
-        }
1016
-
1017
-        return $event->getExitCode();
1018
-    }
1019
-
1020
-    /**
1021
-     * Gets the name of the command based on input.
1022
-     *
1023
-     * @return string|null
1024
-     */
1025
-    protected function getCommandName(InputInterface $input)
1026
-    {
1027
-        return $this->singleCommand ? $this->defaultCommand : $input->getFirstArgument();
1028
-    }
1029
-
1030
-    /**
1031
-     * Gets the default input definition.
1032
-     *
1033
-     * @return InputDefinition An InputDefinition instance
1034
-     */
1035
-    protected function getDefaultInputDefinition()
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
-        ]);
1046
-    }
1047
-
1048
-    /**
1049
-     * Gets the default commands that should always be available.
1050
-     *
1051
-     * @return Command[] An array of default Command instances
1052
-     */
1053
-    protected function getDefaultCommands()
1054
-    {
1055
-        return [new HelpCommand(), new ListCommand()];
1056
-    }
1057
-
1058
-    /**
1059
-     * Gets the default helper set with the helpers that should always be available.
1060
-     *
1061
-     * @return HelperSet A HelperSet instance
1062
-     */
1063
-    protected function getDefaultHelperSet()
1064
-    {
1065
-        return new HelperSet([
1066
-            new FormatterHelper(),
1067
-            new DebugFormatterHelper(),
1068
-            new ProcessHelper(),
1069
-            new QuestionHelper(),
1070
-        ]);
1071
-    }
1072
-
1073
-    /**
1074
-     * Returns abbreviated suggestions in string format.
1075
-     */
1076
-    private function getAbbreviationSuggestions(array $abbrevs): string
1077
-    {
1078
-        return '    '.implode("\n    ", $abbrevs);
1079
-    }
1080
-
1081
-    /**
1082
-     * Returns the namespace part of the command name.
1083
-     *
1084
-     * This method is not part of public API and should not be used directly.
1085
-     *
1086
-     * @return string The namespace of the command
1087
-     */
1088
-    public function extractNamespace(string $name, int $limit = null)
1089
-    {
1090
-        $parts = explode(':', $name, -1);
1091
-
1092
-        return implode(':', null === $limit ? $parts : \array_slice($parts, 0, $limit));
1093
-    }
1094
-
1095
-    /**
1096
-     * Finds alternative of $name among $collection,
1097
-     * if nothing is found in $collection, try in $abbrevs.
1098
-     *
1099
-     * @return string[] A sorted array of similar string
1100
-     */
1101
-    private function findAlternatives(string $name, iterable $collection): array
1102
-    {
1103
-        $threshold = 1e3;
1104
-        $alternatives = [];
1105
-
1106
-        $collectionParts = [];
1107
-        foreach ($collection as $item) {
1108
-            $collectionParts[$item] = explode(':', $item);
1109
-        }
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;
1116
-                    continue;
1117
-                } elseif (!isset($parts[$i])) {
1118
-                    continue;
1119
-                }
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;
1126
-                }
1127
-            }
1128
-        }
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;
1134
-            }
1135
-        }
1136
-
1137
-        $alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2 * $threshold; });
1138
-        ksort($alternatives, \SORT_NATURAL | \SORT_FLAG_CASE);
1139
-
1140
-        return array_keys($alternatives);
1141
-    }
1142
-
1143
-    /**
1144
-     * Sets the default Command name.
1145
-     *
1146
-     * @return self
1147
-     */
1148
-    public function setDefaultCommand(string $commandName, bool $isSingleCommand = false)
1149
-    {
1150
-        $this->defaultCommand = explode('|', ltrim($commandName, '|'))[0];
1151
-
1152
-        if ($isSingleCommand) {
1153
-            // Ensure the command exist
1154
-            $this->find($commandName);
1155
-
1156
-            $this->singleCommand = true;
1157
-        }
1158
-
1159
-        return $this;
1160
-    }
1161
-
1162
-    /**
1163
-     * @internal
1164
-     */
1165
-    public function isSingleCommand(): bool
1166
-    {
1167
-        return $this->singleCommand;
1168
-    }
1169
-
1170
-    private function splitStringByWidth(string $string, int $width): array
1171
-    {
1172
-        // str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.
1173
-        // additionally, array_slice() is not enough as some character has doubled width.
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);
1177
-        }
1178
-
1179
-        $utf8String = mb_convert_encoding($string, 'utf8', $encoding);
1180
-        $lines = [];
1181
-        $line = '';
1182
-
1183
-        $offset = 0;
1184
-        while (preg_match('/.{1,10000}/u', $utf8String, $m, 0, $offset)) {
1185
-            $offset += \strlen($m[0]);
1186
-
1187
-            foreach (preg_split('//u', $m[0]) as $char) {
1188
-                // test if $char could be appended to current line
1189
-                if (mb_strwidth($line.$char, 'utf8') <= $width) {
1190
-                    $line .= $char;
1191
-                    continue;
1192
-                }
1193
-                // if not, push current line to array and make new line
1194
-                $lines[] = str_pad($line, $width);
1195
-                $line = $char;
1196
-            }
1197
-        }
1198
-
1199
-        $lines[] = \count($lines) ? str_pad($line, $width) : $line;
1200
-
1201
-        mb_convert_variables($encoding, 'utf8', $lines);
1202
-
1203
-        return $lines;
1204
-    }
1205
-
1206
-    /**
1207
-     * Returns all namespaces of the command name.
1208
-     *
1209
-     * @return string[] The namespaces of the command
1210
-     */
1211
-    private function extractAllNamespaces(string $name): array
1212
-    {
1213
-        // -1 as third argument is needed to skip the command short name when exploding
1214
-        $parts = explode(':', $name, -1);
1215
-        $namespaces = [];
1216
-
1217
-        foreach ($parts as $part) {
1218
-            if (\count($namespaces)) {
1219
-                $namespaces[] = end($namespaces).':'.$part;
1220
-            } else {
1221
-                $namespaces[] = $part;
1222
-            }
1223
-        }
1224
-
1225
-        return $namespaces;
1226
-    }
1227
-
1228
-    private function init()
1229
-    {
1230
-        if ($this->initialized) {
1231
-            return;
1232
-        }
1233
-        $this->initialized = true;
1234
-
1235
-        foreach ($this->getDefaultCommands() as $command) {
1236
-            $this->add($command);
1237
-        }
1238
-    }
69
+	private $commands = [];
70
+	private $wantHelps = false;
71
+	private $runningCommand;
72
+	private $name;
73
+	private $version;
74
+	private $commandLoader;
75
+	private $catchExceptions = true;
76
+	private $autoExit = true;
77
+	private $definition;
78
+	private $helperSet;
79
+	private $dispatcher;
80
+	private $terminal;
81
+	private $defaultCommand;
82
+	private $singleCommand = false;
83
+	private $initialized;
84
+	private $signalRegistry;
85
+	private $signalsToDispatchEvent = [];
86
+
87
+	public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
88
+	{
89
+		$this->name = $name;
90
+		$this->version = $version;
91
+		$this->terminal = new Terminal();
92
+		$this->defaultCommand = 'list';
93
+		if (\defined('SIGINT') && SignalRegistry::isSupported()) {
94
+			$this->signalRegistry = new SignalRegistry();
95
+			$this->signalsToDispatchEvent = [\SIGINT, \SIGTERM, \SIGUSR1, \SIGUSR2];
96
+		}
97
+	}
98
+
99
+	/**
100
+	 * @final
101
+	 */
102
+	public function setDispatcher(EventDispatcherInterface $dispatcher)
103
+	{
104
+		$this->dispatcher = $dispatcher;
105
+	}
106
+
107
+	public function setCommandLoader(CommandLoaderInterface $commandLoader)
108
+	{
109
+		$this->commandLoader = $commandLoader;
110
+	}
111
+
112
+	public function getSignalRegistry(): SignalRegistry
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.');
116
+		}
117
+
118
+		return $this->signalRegistry;
119
+	}
120
+
121
+	public function setSignalsToDispatchEvent(int ...$signalsToDispatchEvent)
122
+	{
123
+		$this->signalsToDispatchEvent = $signalsToDispatchEvent;
124
+	}
125
+
126
+	/**
127
+	 * Runs the current application.
128
+	 *
129
+	 * @return int 0 if everything went fine, or an error code
130
+	 *
131
+	 * @throws \Exception When running fails. Bypass this when {@link setCatchExceptions()}.
132
+	 */
133
+	public function run(InputInterface $input = null, OutputInterface $output = null)
134
+	{
135
+		if (\function_exists('putenv')) {
136
+			@putenv('LINES='.$this->terminal->getHeight());
137
+			@putenv('COLUMNS='.$this->terminal->getWidth());
138
+		}
139
+
140
+		if (null === $input) {
141
+			$input = new ArgvInput();
142
+		}
143
+
144
+		if (null === $output) {
145
+			$output = new ConsoleOutput();
146
+		}
147
+
148
+		$renderException = function (\Throwable $e) use ($output) {
149
+			if ($output instanceof ConsoleOutputInterface) {
150
+				$this->renderThrowable($e, $output->getErrorOutput());
151
+			} else {
152
+				$this->renderThrowable($e, $output);
153
+			}
154
+		};
155
+		if ($phpHandler = set_exception_handler($renderException)) {
156
+			restore_exception_handler();
157
+			if (!\is_array($phpHandler) || !$phpHandler[0] instanceof ErrorHandler) {
158
+				$errorHandler = true;
159
+			} elseif ($errorHandler = $phpHandler[0]->setExceptionHandler($renderException)) {
160
+				$phpHandler[0]->setExceptionHandler($errorHandler);
161
+			}
162
+		}
163
+
164
+		$this->configureIO($input, $output);
165
+
166
+		try {
167
+			$exitCode = $this->doRun($input, $output);
168
+		} catch (\Exception $e) {
169
+			if (!$this->catchExceptions) {
170
+				throw $e;
171
+			}
172
+
173
+			$renderException($e);
174
+
175
+			$exitCode = $e->getCode();
176
+			if (is_numeric($exitCode)) {
177
+				$exitCode = (int) $exitCode;
178
+				if (0 === $exitCode) {
179
+					$exitCode = 1;
180
+				}
181
+			} else {
182
+				$exitCode = 1;
183
+			}
184
+		} finally {
185
+			// if the exception handler changed, keep it
186
+			// otherwise, unregister $renderException
187
+			if (!$phpHandler) {
188
+				if (set_exception_handler($renderException) === $renderException) {
189
+					restore_exception_handler();
190
+				}
191
+				restore_exception_handler();
192
+			} elseif (!$errorHandler) {
193
+				$finalHandler = $phpHandler[0]->setExceptionHandler(null);
194
+				if ($finalHandler !== $renderException) {
195
+					$phpHandler[0]->setExceptionHandler($finalHandler);
196
+				}
197
+			}
198
+		}
199
+
200
+		if ($this->autoExit) {
201
+			if ($exitCode > 255) {
202
+				$exitCode = 255;
203
+			}
204
+
205
+			exit($exitCode);
206
+		}
207
+
208
+		return $exitCode;
209
+	}
210
+
211
+	/**
212
+	 * Runs the current application.
213
+	 *
214
+	 * @return int 0 if everything went fine, or an error code
215
+	 */
216
+	public function doRun(InputInterface $input, OutputInterface $output)
217
+	{
218
+		if (true === $input->hasParameterOption(['--version', '-V'], true)) {
219
+			$output->writeln($this->getLongVersion());
220
+
221
+			return 0;
222
+		}
223
+
224
+		try {
225
+			// Makes ArgvInput::getFirstArgument() able to distinguish an option from an argument.
226
+			$input->bind($this->getDefinition());
227
+		} catch (ExceptionInterface $e) {
228
+			// Errors must be ignored, full binding/validation happens later when the command is known.
229
+		}
230
+
231
+		$name = $this->getCommandName($input);
232
+		if (true === $input->hasParameterOption(['--help', '-h'], true)) {
233
+			if (!$name) {
234
+				$name = 'help';
235
+				$input = new ArrayInput(['command_name' => $this->defaultCommand]);
236
+			} else {
237
+				$this->wantHelps = true;
238
+			}
239
+		}
240
+
241
+		if (!$name) {
242
+			$name = $this->defaultCommand;
243
+			$definition = $this->getDefinition();
244
+			$definition->setArguments(array_merge(
245
+				$definition->getArguments(),
246
+				[
247
+					'command' => new InputArgument('command', InputArgument::OPTIONAL, $definition->getArgument('command')->getDescription(), $name),
248
+				]
249
+			));
250
+		}
251
+
252
+		try {
253
+			$this->runningCommand = null;
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()) {
263
+						return 0;
264
+					}
265
+
266
+					$e = $event->getError();
267
+				}
268
+
269
+				throw $e;
270
+			}
271
+
272
+			$alternative = $alternatives[0];
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);
280
+
281
+					return $event->getExitCode();
282
+				}
283
+
284
+				return 1;
285
+			}
286
+
287
+			$command = $this->find($alternative);
288
+		}
289
+
290
+		if ($command instanceof LazyCommand) {
291
+			$command = $command->getCommand();
292
+		}
293
+
294
+		$this->runningCommand = $command;
295
+		$exitCode = $this->doRunCommand($command, $input, $output);
296
+		$this->runningCommand = null;
297
+
298
+		return $exitCode;
299
+	}
300
+
301
+	/**
302
+	 * {@inheritdoc}
303
+	 */
304
+	public function reset()
305
+	{
306
+	}
307
+
308
+	public function setHelperSet(HelperSet $helperSet)
309
+	{
310
+		$this->helperSet = $helperSet;
311
+	}
312
+
313
+	/**
314
+	 * Get the helper set associated with the command.
315
+	 *
316
+	 * @return HelperSet The HelperSet instance associated with this command
317
+	 */
318
+	public function getHelperSet()
319
+	{
320
+		if (!$this->helperSet) {
321
+			$this->helperSet = $this->getDefaultHelperSet();
322
+		}
323
+
324
+		return $this->helperSet;
325
+	}
326
+
327
+	public function setDefinition(InputDefinition $definition)
328
+	{
329
+		$this->definition = $definition;
330
+	}
331
+
332
+	/**
333
+	 * Gets the InputDefinition related to this Application.
334
+	 *
335
+	 * @return InputDefinition The InputDefinition instance
336
+	 */
337
+	public function getDefinition()
338
+	{
339
+		if (!$this->definition) {
340
+			$this->definition = $this->getDefaultInputDefinition();
341
+		}
342
+
343
+		if ($this->singleCommand) {
344
+			$inputDefinition = $this->definition;
345
+			$inputDefinition->setArguments();
346
+
347
+			return $inputDefinition;
348
+		}
349
+
350
+		return $this->definition;
351
+	}
352
+
353
+	/**
354
+	 * Gets the help message.
355
+	 *
356
+	 * @return string A help message
357
+	 */
358
+	public function getHelp()
359
+	{
360
+		return $this->getLongVersion();
361
+	}
362
+
363
+	/**
364
+	 * Gets whether to catch exceptions or not during commands execution.
365
+	 *
366
+	 * @return bool Whether to catch exceptions or not during commands execution
367
+	 */
368
+	public function areExceptionsCaught()
369
+	{
370
+		return $this->catchExceptions;
371
+	}
372
+
373
+	/**
374
+	 * Sets whether to catch exceptions or not during commands execution.
375
+	 */
376
+	public function setCatchExceptions(bool $boolean)
377
+	{
378
+		$this->catchExceptions = $boolean;
379
+	}
380
+
381
+	/**
382
+	 * Gets whether to automatically exit after a command execution or not.
383
+	 *
384
+	 * @return bool Whether to automatically exit after a command execution or not
385
+	 */
386
+	public function isAutoExitEnabled()
387
+	{
388
+		return $this->autoExit;
389
+	}
390
+
391
+	/**
392
+	 * Sets whether to automatically exit after a command execution or not.
393
+	 */
394
+	public function setAutoExit(bool $boolean)
395
+	{
396
+		$this->autoExit = $boolean;
397
+	}
398
+
399
+	/**
400
+	 * Gets the name of the application.
401
+	 *
402
+	 * @return string The application name
403
+	 */
404
+	public function getName()
405
+	{
406
+		return $this->name;
407
+	}
408
+
409
+	/**
410
+	 * Sets the application name.
411
+	 **/
412
+	public function setName(string $name)
413
+	{
414
+		$this->name = $name;
415
+	}
416
+
417
+	/**
418
+	 * Gets the application version.
419
+	 *
420
+	 * @return string The application version
421
+	 */
422
+	public function getVersion()
423
+	{
424
+		return $this->version;
425
+	}
426
+
427
+	/**
428
+	 * Sets the application version.
429
+	 */
430
+	public function setVersion(string $version)
431
+	{
432
+		$this->version = $version;
433
+	}
434
+
435
+	/**
436
+	 * Returns the long version of the application.
437
+	 *
438
+	 * @return string The long application version
439
+	 */
440
+	public function getLongVersion()
441
+	{
442
+		if ('UNKNOWN' !== $this->getName()) {
443
+			if ('UNKNOWN' !== $this->getVersion()) {
444
+				return sprintf('%s <info>%s</info>', $this->getName(), $this->getVersion());
445
+			}
446
+
447
+			return $this->getName();
448
+		}
449
+
450
+		return 'Console Tool';
451
+	}
452
+
453
+	/**
454
+	 * Registers a new command.
455
+	 *
456
+	 * @return Command The newly created command
457
+	 */
458
+	public function register(string $name)
459
+	{
460
+		return $this->add(new Command($name));
461
+	}
462
+
463
+	/**
464
+	 * Adds an array of command objects.
465
+	 *
466
+	 * If a Command is not enabled it will not be added.
467
+	 *
468
+	 * @param Command[] $commands An array of commands
469
+	 */
470
+	public function addCommands(array $commands)
471
+	{
472
+		foreach ($commands as $command) {
473
+			$this->add($command);
474
+		}
475
+	}
476
+
477
+	/**
478
+	 * Adds a command object.
479
+	 *
480
+	 * If a command with the same name already exists, it will be overridden.
481
+	 * If the command is not enabled it will not be added.
482
+	 *
483
+	 * @return Command|null The registered command if enabled or null
484
+	 */
485
+	public function add(Command $command)
486
+	{
487
+		$this->init();
488
+
489
+		$command->setApplication($this);
490
+
491
+		if (!$command->isEnabled()) {
492
+			$command->setApplication(null);
493
+
494
+			return null;
495
+		}
496
+
497
+		if (!$command instanceof LazyCommand) {
498
+			// Will throw if the command is not correctly initialized.
499
+			$command->getDefinition();
500
+		}
501
+
502
+		if (!$command->getName()) {
503
+			throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_debug_type($command)));
504
+		}
505
+
506
+		$this->commands[$command->getName()] = $command;
507
+
508
+		foreach ($command->getAliases() as $alias) {
509
+			$this->commands[$alias] = $command;
510
+		}
511
+
512
+		return $command;
513
+	}
514
+
515
+	/**
516
+	 * Returns a registered command by name or alias.
517
+	 *
518
+	 * @return Command A Command object
519
+	 *
520
+	 * @throws CommandNotFoundException When given command name does not exist
521
+	 */
522
+	public function get(string $name)
523
+	{
524
+		$this->init();
525
+
526
+		if (!$this->has($name)) {
527
+			throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
528
+		}
529
+
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));
533
+		}
534
+
535
+		$command = $this->commands[$name];
536
+
537
+		if ($this->wantHelps) {
538
+			$this->wantHelps = false;
539
+
540
+			$helpCommand = $this->get('help');
541
+			$helpCommand->setCommand($command);
542
+
543
+			return $helpCommand;
544
+		}
545
+
546
+		return $command;
547
+	}
548
+
549
+	/**
550
+	 * Returns true if the command exists, false otherwise.
551
+	 *
552
+	 * @return bool true if the command exists, false otherwise
553
+	 */
554
+	public function has(string $name)
555
+	{
556
+		$this->init();
557
+
558
+		return isset($this->commands[$name]) || ($this->commandLoader && $this->commandLoader->has($name) && $this->add($this->commandLoader->get($name)));
559
+	}
560
+
561
+	/**
562
+	 * Returns an array of all unique namespaces used by currently registered commands.
563
+	 *
564
+	 * It does not return the global namespace which always exists.
565
+	 *
566
+	 * @return string[] An array of namespaces
567
+	 */
568
+	public function getNamespaces()
569
+	{
570
+		$namespaces = [];
571
+		foreach ($this->all() as $command) {
572
+			if ($command->isHidden()) {
573
+				continue;
574
+			}
575
+
576
+			$namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
577
+
578
+			foreach ($command->getAliases() as $alias) {
579
+				$namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
580
+			}
581
+		}
582
+
583
+		return array_values(array_unique(array_filter($namespaces)));
584
+	}
585
+
586
+	/**
587
+	 * Finds a registered namespace by a name or an abbreviation.
588
+	 *
589
+	 * @return string A registered namespace
590
+	 *
591
+	 * @throws NamespaceNotFoundException When namespace is incorrect or ambiguous
592
+	 */
593
+	public function findNamespace(string $namespace)
594
+	{
595
+		$allNamespaces = $this->getNamespaces();
596
+		$expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))).'[^:]*';
597
+		$namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);
598
+
599
+		if (empty($namespaces)) {
600
+			$message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
601
+
602
+			if ($alternatives = $this->findAlternatives($namespace, $allNamespaces)) {
603
+				if (1 == \count($alternatives)) {
604
+					$message .= "\n\nDid you mean this?\n    ";
605
+				} else {
606
+					$message .= "\n\nDid you mean one of these?\n    ";
607
+				}
608
+
609
+				$message .= implode("\n    ", $alternatives);
610
+			}
611
+
612
+			throw new NamespaceNotFoundException($message, $alternatives);
613
+		}
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));
618
+		}
619
+
620
+		return $exact ? $namespace : reset($namespaces);
621
+	}
622
+
623
+	/**
624
+	 * Finds a command by name or alias.
625
+	 *
626
+	 * Contrary to get, this command tries to find the best
627
+	 * match if you give it an abbreviation of a name or alias.
628
+	 *
629
+	 * @return Command A Command instance
630
+	 *
631
+	 * @throws CommandNotFoundException When command name is incorrect or ambiguous
632
+	 */
633
+	public function find(string $name)
634
+	{
635
+		$this->init();
636
+
637
+		$aliases = [];
638
+
639
+		foreach ($this->commands as $command) {
640
+			foreach ($command->getAliases() as $alias) {
641
+				if (!$this->has($alias)) {
642
+					$this->commands[$alias] = $command;
643
+				}
644
+			}
645
+		}
646
+
647
+		if ($this->has($name)) {
648
+			return $this->get($name);
649
+		}
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);
654
+
655
+		if (empty($commands)) {
656
+			$commands = preg_grep('{^'.$expr.'}i', $allCommands);
657
+		}
658
+
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, ':')) {
662
+				// check if a namespace exists and contains commands
663
+				$this->findNamespace(substr($name, 0, $pos));
664
+			}
665
+
666
+			$message = sprintf('Command "%s" is not defined.', $name);
667
+
668
+			if ($alternatives = $this->findAlternatives($name, $allCommands)) {
669
+				// remove hidden commands
670
+				$alternatives = array_filter($alternatives, function ($name) {
671
+					return !$this->get($name)->isHidden();
672
+				});
673
+
674
+				if (1 == \count($alternatives)) {
675
+					$message .= "\n\nDid you mean this?\n    ";
676
+				} else {
677
+					$message .= "\n\nDid you mean one of these?\n    ";
678
+				}
679
+				$message .= implode("\n    ", $alternatives);
680
+			}
681
+
682
+			throw new CommandNotFoundException($message, array_values($alternatives));
683
+		}
684
+
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);
691
+				}
692
+
693
+				$commandName = $commandList[$nameOrAlias]->getName();
694
+
695
+				$aliases[$nameOrAlias] = $commandName;
696
+
697
+				return $commandName === $nameOrAlias || !\in_array($commandName, $commands);
698
+			}));
699
+		}
700
+
701
+		if (\count($commands) > 1) {
702
+			$usableWidth = $this->terminal->getWidth() - 10;
703
+			$abbrevs = array_values($commands);
704
+			$maxLen = 0;
705
+			foreach ($abbrevs as $abbrev) {
706
+				$maxLen = max(Helper::width($abbrev), $maxLen);
707
+			}
708
+			$abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen, &$commands) {
709
+				if ($commandList[$cmd]->isHidden()) {
710
+					unset($commands[array_search($cmd, $commands)]);
711
+
712
+					return false;
713
+				}
714
+
715
+				$abbrev = str_pad($cmd, $maxLen, ' ').' '.$commandList[$cmd]->getDescription();
716
+
717
+				return Helper::width($abbrev) > $usableWidth ? Helper::substr($abbrev, 0, $usableWidth - 3).'...' : $abbrev;
718
+			}, array_values($commands));
719
+
720
+			if (\count($commands) > 1) {
721
+				$suggestions = $this->getAbbreviationSuggestions(array_filter($abbrevs));
722
+
723
+				throw new CommandNotFoundException(sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", $name, $suggestions), array_values($commands));
724
+			}
725
+		}
726
+
727
+		$command = $this->get(reset($commands));
728
+
729
+		if ($command->isHidden()) {
730
+			throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
731
+		}
732
+
733
+		return $command;
734
+	}
735
+
736
+	/**
737
+	 * Gets the commands (registered in the given namespace if provided).
738
+	 *
739
+	 * The array keys are the full names and the values the command instances.
740
+	 *
741
+	 * @return Command[] An array of Command instances
742
+	 */
743
+	public function all(string $namespace = null)
744
+	{
745
+		$this->init();
746
+
747
+		if (null === $namespace) {
748
+			if (!$this->commandLoader) {
749
+				return $this->commands;
750
+			}
751
+
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);
756
+				}
757
+			}
758
+
759
+			return $commands;
760
+		}
761
+
762
+		$commands = [];
763
+		foreach ($this->commands as $name => $command) {
764
+			if ($namespace === $this->extractNamespace($name, substr_count($namespace, ':') + 1)) {
765
+				$commands[$name] = $command;
766
+			}
767
+		}
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);
773
+				}
774
+			}
775
+		}
776
+
777
+		return $commands;
778
+	}
779
+
780
+	/**
781
+	 * Returns an array of possible abbreviations given a set of names.
782
+	 *
783
+	 * @return string[][] An array of abbreviations
784
+	 */
785
+	public static function getAbbreviations(array $names)
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;
792
+			}
793
+		}
794
+
795
+		return $abbrevs;
796
+	}
797
+
798
+	public function renderThrowable(\Throwable $e, OutputInterface $output): void
799
+	{
800
+		$output->writeln('', OutputInterface::VERBOSITY_QUIET);
801
+
802
+		$this->doRenderThrowable($e, $output);
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);
807
+		}
808
+	}
809
+
810
+	protected function doRenderThrowable(\Throwable $e, OutputInterface $output): void
811
+	{
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);
818
+			} else {
819
+				$len = 0;
820
+			}
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);
826
+			}
827
+
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) {
832
+					// pre-format lines to get the right string length
833
+					$lineLength = Helper::width($line) + 4;
834
+					$lines[] = [$line, $lineLength];
835
+
836
+					$len = max($lineLength, $len);
837
+				}
838
+			}
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')));
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))));
847
+			}
848
+			foreach ($lines as $line) {
849
+				$messages[] = sprintf('<error>  %s  %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
850
+			}
851
+			$messages[] = $emptyLine;
852
+			$messages[] = '';
853
+
854
+			$output->writeln($messages, OutputInterface::VERBOSITY_QUIET);
855
+
856
+			if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
857
+				$output->writeln('<comment>Exception trace:</comment>', OutputInterface::VERBOSITY_QUIET);
858
+
859
+				// exception related properties
860
+				$trace = $e->getTrace();
861
+
862
+				array_unshift($trace, [
863
+					'function' => '',
864
+					'file' => $e->getFile() ?: 'n/a',
865
+					'line' => $e->getLine() ?: 'n/a',
866
+					'args' => [],
867
+				]);
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';
875
+
876
+					$output->writeln(sprintf(' %s%s at <info>%s:%s</info>', $class, $function ? $type.$function.'()' : '', $file, $line), OutputInterface::VERBOSITY_QUIET);
877
+				}
878
+
879
+				$output->writeln('', OutputInterface::VERBOSITY_QUIET);
880
+			}
881
+		} while ($e = $e->getPrevious());
882
+	}
883
+
884
+	/**
885
+	 * Configures the input and output instances based on the user arguments and options.
886
+	 */
887
+	protected function configureIO(InputInterface $input, OutputInterface $output)
888
+	{
889
+		if (true === $input->hasParameterOption(['--ansi'], true)) {
890
+			$output->setDecorated(true);
891
+		} elseif (true === $input->hasParameterOption(['--no-ansi'], true)) {
892
+			$output->setDecorated(false);
893
+		}
894
+
895
+		if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) {
896
+			$input->setInteractive(false);
897
+		}
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;
904
+			default: $shellVerbosity = 0; break;
905
+		}
906
+
907
+		if (true === $input->hasParameterOption(['--quiet', '-q'], true)) {
908
+			$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
909
+			$shellVerbosity = -1;
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);
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);
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);
919
+				$shellVerbosity = 1;
920
+			}
921
+		}
922
+
923
+		if (-1 === $shellVerbosity) {
924
+			$input->setInteractive(false);
925
+		}
926
+
927
+		if (\function_exists('putenv')) {
928
+			@putenv('SHELL_VERBOSITY='.$shellVerbosity);
929
+		}
930
+		$_ENV['SHELL_VERBOSITY'] = $shellVerbosity;
931
+		$_SERVER['SHELL_VERBOSITY'] = $shellVerbosity;
932
+	}
933
+
934
+	/**
935
+	 * Runs the current command.
936
+	 *
937
+	 * If an event dispatcher has been attached to the application,
938
+	 * events are also dispatched during the life-cycle of the command.
939
+	 *
940
+	 * @return int 0 if everything went fine, or an error code
941
+	 */
942
+	protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
943
+	{
944
+		foreach ($command->getHelperSet() as $helper) {
945
+			if ($helper instanceof InputAwareInterface) {
946
+				$helper->setInput($input);
947
+			}
948
+		}
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.');
953
+			}
954
+
955
+			if ($this->dispatcher) {
956
+				foreach ($this->signalsToDispatchEvent as $signal) {
957
+					$event = new ConsoleSignalEvent($command, $input, $output, $signal);
958
+
959
+					$this->signalRegistry->register($signal, function ($signal, $hasNext) use ($event) {
960
+						$this->dispatcher->dispatch($event, ConsoleEvents::SIGNAL);
961
+
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);
966
+							}
967
+						}
968
+					});
969
+				}
970
+			}
971
+
972
+			foreach ($command->getSubscribedSignals() as $signal) {
973
+				$this->signalRegistry->register($signal, [$command, 'handleSignal']);
974
+			}
975
+		}
976
+
977
+		if (null === $this->dispatcher) {
978
+			return $command->run($input, $output);
979
+		}
980
+
981
+		// bind before the console.command event, so the listeners have access to input options/arguments
982
+		try {
983
+			$command->mergeApplicationDefinition();
984
+			$input->bind($command->getDefinition());
985
+		} catch (ExceptionInterface $e) {
986
+			// ignore invalid options/arguments for now, to allow the event listeners to customize the InputDefinition
987
+		}
988
+
989
+		$event = new ConsoleCommandEvent($command, $input, $output);
990
+		$e = null;
991
+
992
+		try {
993
+			$this->dispatcher->dispatch($event, ConsoleEvents::COMMAND);
994
+
995
+			if ($event->commandShouldRun()) {
996
+				$exitCode = $command->run($input, $output);
997
+			} else {
998
+				$exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED;
999
+			}
1000
+		} catch (\Throwable $e) {
1001
+			$event = new ConsoleErrorEvent($input, $output, $e, $command);
1002
+			$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
1003
+			$e = $event->getError();
1004
+
1005
+			if (0 === $exitCode = $event->getExitCode()) {
1006
+				$e = null;
1007
+			}
1008
+		}
1009
+
1010
+		$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
1011
+		$this->dispatcher->dispatch($event, ConsoleEvents::TERMINATE);
1012
+
1013
+		if (null !== $e) {
1014
+			throw $e;
1015
+		}
1016
+
1017
+		return $event->getExitCode();
1018
+	}
1019
+
1020
+	/**
1021
+	 * Gets the name of the command based on input.
1022
+	 *
1023
+	 * @return string|null
1024
+	 */
1025
+	protected function getCommandName(InputInterface $input)
1026
+	{
1027
+		return $this->singleCommand ? $this->defaultCommand : $input->getFirstArgument();
1028
+	}
1029
+
1030
+	/**
1031
+	 * Gets the default input definition.
1032
+	 *
1033
+	 * @return InputDefinition An InputDefinition instance
1034
+	 */
1035
+	protected function getDefaultInputDefinition()
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
+		]);
1046
+	}
1047
+
1048
+	/**
1049
+	 * Gets the default commands that should always be available.
1050
+	 *
1051
+	 * @return Command[] An array of default Command instances
1052
+	 */
1053
+	protected function getDefaultCommands()
1054
+	{
1055
+		return [new HelpCommand(), new ListCommand()];
1056
+	}
1057
+
1058
+	/**
1059
+	 * Gets the default helper set with the helpers that should always be available.
1060
+	 *
1061
+	 * @return HelperSet A HelperSet instance
1062
+	 */
1063
+	protected function getDefaultHelperSet()
1064
+	{
1065
+		return new HelperSet([
1066
+			new FormatterHelper(),
1067
+			new DebugFormatterHelper(),
1068
+			new ProcessHelper(),
1069
+			new QuestionHelper(),
1070
+		]);
1071
+	}
1072
+
1073
+	/**
1074
+	 * Returns abbreviated suggestions in string format.
1075
+	 */
1076
+	private function getAbbreviationSuggestions(array $abbrevs): string
1077
+	{
1078
+		return '    '.implode("\n    ", $abbrevs);
1079
+	}
1080
+
1081
+	/**
1082
+	 * Returns the namespace part of the command name.
1083
+	 *
1084
+	 * This method is not part of public API and should not be used directly.
1085
+	 *
1086
+	 * @return string The namespace of the command
1087
+	 */
1088
+	public function extractNamespace(string $name, int $limit = null)
1089
+	{
1090
+		$parts = explode(':', $name, -1);
1091
+
1092
+		return implode(':', null === $limit ? $parts : \array_slice($parts, 0, $limit));
1093
+	}
1094
+
1095
+	/**
1096
+	 * Finds alternative of $name among $collection,
1097
+	 * if nothing is found in $collection, try in $abbrevs.
1098
+	 *
1099
+	 * @return string[] A sorted array of similar string
1100
+	 */
1101
+	private function findAlternatives(string $name, iterable $collection): array
1102
+	{
1103
+		$threshold = 1e3;
1104
+		$alternatives = [];
1105
+
1106
+		$collectionParts = [];
1107
+		foreach ($collection as $item) {
1108
+			$collectionParts[$item] = explode(':', $item);
1109
+		}
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;
1116
+					continue;
1117
+				} elseif (!isset($parts[$i])) {
1118
+					continue;
1119
+				}
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;
1126
+				}
1127
+			}
1128
+		}
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;
1134
+			}
1135
+		}
1136
+
1137
+		$alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2 * $threshold; });
1138
+		ksort($alternatives, \SORT_NATURAL | \SORT_FLAG_CASE);
1139
+
1140
+		return array_keys($alternatives);
1141
+	}
1142
+
1143
+	/**
1144
+	 * Sets the default Command name.
1145
+	 *
1146
+	 * @return self
1147
+	 */
1148
+	public function setDefaultCommand(string $commandName, bool $isSingleCommand = false)
1149
+	{
1150
+		$this->defaultCommand = explode('|', ltrim($commandName, '|'))[0];
1151
+
1152
+		if ($isSingleCommand) {
1153
+			// Ensure the command exist
1154
+			$this->find($commandName);
1155
+
1156
+			$this->singleCommand = true;
1157
+		}
1158
+
1159
+		return $this;
1160
+	}
1161
+
1162
+	/**
1163
+	 * @internal
1164
+	 */
1165
+	public function isSingleCommand(): bool
1166
+	{
1167
+		return $this->singleCommand;
1168
+	}
1169
+
1170
+	private function splitStringByWidth(string $string, int $width): array
1171
+	{
1172
+		// str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.
1173
+		// additionally, array_slice() is not enough as some character has doubled width.
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);
1177
+		}
1178
+
1179
+		$utf8String = mb_convert_encoding($string, 'utf8', $encoding);
1180
+		$lines = [];
1181
+		$line = '';
1182
+
1183
+		$offset = 0;
1184
+		while (preg_match('/.{1,10000}/u', $utf8String, $m, 0, $offset)) {
1185
+			$offset += \strlen($m[0]);
1186
+
1187
+			foreach (preg_split('//u', $m[0]) as $char) {
1188
+				// test if $char could be appended to current line
1189
+				if (mb_strwidth($line.$char, 'utf8') <= $width) {
1190
+					$line .= $char;
1191
+					continue;
1192
+				}
1193
+				// if not, push current line to array and make new line
1194
+				$lines[] = str_pad($line, $width);
1195
+				$line = $char;
1196
+			}
1197
+		}
1198
+
1199
+		$lines[] = \count($lines) ? str_pad($line, $width) : $line;
1200
+
1201
+		mb_convert_variables($encoding, 'utf8', $lines);
1202
+
1203
+		return $lines;
1204
+	}
1205
+
1206
+	/**
1207
+	 * Returns all namespaces of the command name.
1208
+	 *
1209
+	 * @return string[] The namespaces of the command
1210
+	 */
1211
+	private function extractAllNamespaces(string $name): array
1212
+	{
1213
+		// -1 as third argument is needed to skip the command short name when exploding
1214
+		$parts = explode(':', $name, -1);
1215
+		$namespaces = [];
1216
+
1217
+		foreach ($parts as $part) {
1218
+			if (\count($namespaces)) {
1219
+				$namespaces[] = end($namespaces).':'.$part;
1220
+			} else {
1221
+				$namespaces[] = $part;
1222
+			}
1223
+		}
1224
+
1225
+		return $namespaces;
1226
+	}
1227
+
1228
+	private function init()
1229
+	{
1230
+		if ($this->initialized) {
1231
+			return;
1232
+		}
1233
+		$this->initialized = true;
1234
+
1235
+		foreach ($this->getDefaultCommands() as $command) {
1236
+			$this->add($command);
1237
+		}
1238
+	}
1239 1239
 }
Please login to merge, or discard this patch.
Spacing   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +41 added lines, -82 removed lines patch added patch discarded remove patch
@@ -64,8 +64,7 @@  discard block
 block discarded – undo
64 64
  *
65 65
  * @author Fabien Potencier <[email protected]>
66 66
  */
67
-class Application implements ResetInterface
68
-{
67
+class Application implements ResetInterface {
69 68
     private $commands = [];
70 69
     private $wantHelps = false;
71 70
     private $runningCommand;
@@ -84,8 +83,7 @@  discard block
 block discarded – undo
84 83
     private $signalRegistry;
85 84
     private $signalsToDispatchEvent = [];
86 85
 
87
-    public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
88
-    {
86
+    public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN') {
89 87
         $this->name = $name;
90 88
         $this->version = $version;
91 89
         $this->terminal = new Terminal();
@@ -99,13 +97,11 @@  discard block
 block discarded – undo
99 97
     /**
100 98
      * @final
101 99
      */
102
-    public function setDispatcher(EventDispatcherInterface $dispatcher)
103
-    {
100
+    public function setDispatcher(EventDispatcherInterface $dispatcher) {
104 101
         $this->dispatcher = $dispatcher;
105 102
     }
106 103
 
107
-    public function setCommandLoader(CommandLoaderInterface $commandLoader)
108
-    {
104
+    public function setCommandLoader(CommandLoaderInterface $commandLoader) {
109 105
         $this->commandLoader = $commandLoader;
110 106
     }
111 107
 
@@ -118,8 +114,7 @@  discard block
 block discarded – undo
118 114
         return $this->signalRegistry;
119 115
     }
120 116
 
121
-    public function setSignalsToDispatchEvent(int ...$signalsToDispatchEvent)
122
-    {
117
+    public function setSignalsToDispatchEvent(int ...$signalsToDispatchEvent) {
123 118
         $this->signalsToDispatchEvent = $signalsToDispatchEvent;
124 119
     }
125 120
 
@@ -130,8 +125,7 @@  discard block
 block discarded – undo
130 125
      *
131 126
      * @throws \Exception When running fails. Bypass this when {@link setCatchExceptions()}.
132 127
      */
133
-    public function run(InputInterface $input = null, OutputInterface $output = null)
134
-    {
128
+    public function run(InputInterface $input = null, OutputInterface $output = null) {
135 129
         if (\function_exists('putenv')) {
136 130
             @putenv('LINES='.$this->terminal->getHeight());
137 131
             @putenv('COLUMNS='.$this->terminal->getWidth());
@@ -213,8 +207,7 @@  discard block
 block discarded – undo
213 207
      *
214 208
      * @return int 0 if everything went fine, or an error code
215 209
      */
216
-    public function doRun(InputInterface $input, OutputInterface $output)
217
-    {
210
+    public function doRun(InputInterface $input, OutputInterface $output) {
218 211
         if (true === $input->hasParameterOption(['--version', '-V'], true)) {
219 212
             $output->writeln($this->getLongVersion());
220 213
 
@@ -301,12 +294,10 @@  discard block
 block discarded – undo
301 294
     /**
302 295
      * {@inheritdoc}
303 296
      */
304
-    public function reset()
305
-    {
297
+    public function reset() {
306 298
     }
307 299
 
308
-    public function setHelperSet(HelperSet $helperSet)
309
-    {
300
+    public function setHelperSet(HelperSet $helperSet) {
310 301
         $this->helperSet = $helperSet;
311 302
     }
312 303
 
@@ -315,8 +306,7 @@  discard block
 block discarded – undo
315 306
      *
316 307
      * @return HelperSet The HelperSet instance associated with this command
317 308
      */
318
-    public function getHelperSet()
319
-    {
309
+    public function getHelperSet() {
320 310
         if (!$this->helperSet) {
321 311
             $this->helperSet = $this->getDefaultHelperSet();
322 312
         }
@@ -324,8 +314,7 @@  discard block
 block discarded – undo
324 314
         return $this->helperSet;
325 315
     }
326 316
 
327
-    public function setDefinition(InputDefinition $definition)
328
-    {
317
+    public function setDefinition(InputDefinition $definition) {
329 318
         $this->definition = $definition;
330 319
     }
331 320
 
@@ -334,8 +323,7 @@  discard block
 block discarded – undo
334 323
      *
335 324
      * @return InputDefinition The InputDefinition instance
336 325
      */
337
-    public function getDefinition()
338
-    {
326
+    public function getDefinition() {
339 327
         if (!$this->definition) {
340 328
             $this->definition = $this->getDefaultInputDefinition();
341 329
         }
@@ -355,8 +343,7 @@  discard block
 block discarded – undo
355 343
      *
356 344
      * @return string A help message
357 345
      */
358
-    public function getHelp()
359
-    {
346
+    public function getHelp() {
360 347
         return $this->getLongVersion();
361 348
     }
362 349
 
@@ -365,16 +352,14 @@  discard block
 block discarded – undo
365 352
      *
366 353
      * @return bool Whether to catch exceptions or not during commands execution
367 354
      */
368
-    public function areExceptionsCaught()
369
-    {
355
+    public function areExceptionsCaught() {
370 356
         return $this->catchExceptions;
371 357
     }
372 358
 
373 359
     /**
374 360
      * Sets whether to catch exceptions or not during commands execution.
375 361
      */
376
-    public function setCatchExceptions(bool $boolean)
377
-    {
362
+    public function setCatchExceptions(bool $boolean) {
378 363
         $this->catchExceptions = $boolean;
379 364
     }
380 365
 
@@ -383,16 +368,14 @@  discard block
 block discarded – undo
383 368
      *
384 369
      * @return bool Whether to automatically exit after a command execution or not
385 370
      */
386
-    public function isAutoExitEnabled()
387
-    {
371
+    public function isAutoExitEnabled() {
388 372
         return $this->autoExit;
389 373
     }
390 374
 
391 375
     /**
392 376
      * Sets whether to automatically exit after a command execution or not.
393 377
      */
394
-    public function setAutoExit(bool $boolean)
395
-    {
378
+    public function setAutoExit(bool $boolean) {
396 379
         $this->autoExit = $boolean;
397 380
     }
398 381
 
@@ -401,16 +384,14 @@  discard block
 block discarded – undo
401 384
      *
402 385
      * @return string The application name
403 386
      */
404
-    public function getName()
405
-    {
387
+    public function getName() {
406 388
         return $this->name;
407 389
     }
408 390
 
409 391
     /**
410 392
      * Sets the application name.
411 393
      **/
412
-    public function setName(string $name)
413
-    {
394
+    public function setName(string $name) {
414 395
         $this->name = $name;
415 396
     }
416 397
 
@@ -419,16 +400,14 @@  discard block
 block discarded – undo
419 400
      *
420 401
      * @return string The application version
421 402
      */
422
-    public function getVersion()
423
-    {
403
+    public function getVersion() {
424 404
         return $this->version;
425 405
     }
426 406
 
427 407
     /**
428 408
      * Sets the application version.
429 409
      */
430
-    public function setVersion(string $version)
431
-    {
410
+    public function setVersion(string $version) {
432 411
         $this->version = $version;
433 412
     }
434 413
 
@@ -437,8 +416,7 @@  discard block
 block discarded – undo
437 416
      *
438 417
      * @return string The long application version
439 418
      */
440
-    public function getLongVersion()
441
-    {
419
+    public function getLongVersion() {
442 420
         if ('UNKNOWN' !== $this->getName()) {
443 421
             if ('UNKNOWN' !== $this->getVersion()) {
444 422
                 return sprintf('%s <info>%s</info>', $this->getName(), $this->getVersion());
@@ -455,8 +433,7 @@  discard block
 block discarded – undo
455 433
      *
456 434
      * @return Command The newly created command
457 435
      */
458
-    public function register(string $name)
459
-    {
436
+    public function register(string $name) {
460 437
         return $this->add(new Command($name));
461 438
     }
462 439
 
@@ -467,8 +444,7 @@  discard block
 block discarded – undo
467 444
      *
468 445
      * @param Command[] $commands An array of commands
469 446
      */
470
-    public function addCommands(array $commands)
471
-    {
447
+    public function addCommands(array $commands) {
472 448
         foreach ($commands as $command) {
473 449
             $this->add($command);
474 450
         }
@@ -482,8 +458,7 @@  discard block
 block discarded – undo
482 458
      *
483 459
      * @return Command|null The registered command if enabled or null
484 460
      */
485
-    public function add(Command $command)
486
-    {
461
+    public function add(Command $command) {
487 462
         $this->init();
488 463
 
489 464
         $command->setApplication($this);
@@ -519,8 +494,7 @@  discard block
 block discarded – undo
519 494
      *
520 495
      * @throws CommandNotFoundException When given command name does not exist
521 496
      */
522
-    public function get(string $name)
523
-    {
497
+    public function get(string $name) {
524 498
         $this->init();
525 499
 
526 500
         if (!$this->has($name)) {
@@ -551,8 +525,7 @@  discard block
 block discarded – undo
551 525
      *
552 526
      * @return bool true if the command exists, false otherwise
553 527
      */
554
-    public function has(string $name)
555
-    {
528
+    public function has(string $name) {
556 529
         $this->init();
557 530
 
558 531
         return isset($this->commands[$name]) || ($this->commandLoader && $this->commandLoader->has($name) && $this->add($this->commandLoader->get($name)));
@@ -565,8 +538,7 @@  discard block
 block discarded – undo
565 538
      *
566 539
      * @return string[] An array of namespaces
567 540
      */
568
-    public function getNamespaces()
569
-    {
541
+    public function getNamespaces() {
570 542
         $namespaces = [];
571 543
         foreach ($this->all() as $command) {
572 544
             if ($command->isHidden()) {
@@ -590,8 +562,7 @@  discard block
 block discarded – undo
590 562
      *
591 563
      * @throws NamespaceNotFoundException When namespace is incorrect or ambiguous
592 564
      */
593
-    public function findNamespace(string $namespace)
594
-    {
565
+    public function findNamespace(string $namespace) {
595 566
         $allNamespaces = $this->getNamespaces();
596 567
         $expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))).'[^:]*';
597 568
         $namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);
@@ -630,8 +601,7 @@  discard block
 block discarded – undo
630 601
      *
631 602
      * @throws CommandNotFoundException When command name is incorrect or ambiguous
632 603
      */
633
-    public function find(string $name)
634
-    {
604
+    public function find(string $name) {
635 605
         $this->init();
636 606
 
637 607
         $aliases = [];
@@ -740,8 +710,7 @@  discard block
 block discarded – undo
740 710
      *
741 711
      * @return Command[] An array of Command instances
742 712
      */
743
-    public function all(string $namespace = null)
744
-    {
713
+    public function all(string $namespace = null) {
745 714
         $this->init();
746 715
 
747 716
         if (null === $namespace) {
@@ -782,8 +751,7 @@  discard block
 block discarded – undo
782 751
      *
783 752
      * @return string[][] An array of abbreviations
784 753
      */
785
-    public static function getAbbreviations(array $names)
786
-    {
754
+    public static function getAbbreviations(array $names) {
787 755
         $abbrevs = [];
788 756
         foreach ($names as $name) {
789 757
             for ($len = \strlen($name); $len > 0; --$len) {
@@ -884,8 +852,7 @@  discard block
 block discarded – undo
884 852
     /**
885 853
      * Configures the input and output instances based on the user arguments and options.
886 854
      */
887
-    protected function configureIO(InputInterface $input, OutputInterface $output)
888
-    {
855
+    protected function configureIO(InputInterface $input, OutputInterface $output) {
889 856
         if (true === $input->hasParameterOption(['--ansi'], true)) {
890 857
             $output->setDecorated(true);
891 858
         } elseif (true === $input->hasParameterOption(['--no-ansi'], true)) {
@@ -939,8 +906,7 @@  discard block
 block discarded – undo
939 906
      *
940 907
      * @return int 0 if everything went fine, or an error code
941 908
      */
942
-    protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
943
-    {
909
+    protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output) {
944 910
         foreach ($command->getHelperSet() as $helper) {
945 911
             if ($helper instanceof InputAwareInterface) {
946 912
                 $helper->setInput($input);
@@ -1022,8 +988,7 @@  discard block
 block discarded – undo
1022 988
      *
1023 989
      * @return string|null
1024 990
      */
1025
-    protected function getCommandName(InputInterface $input)
1026
-    {
991
+    protected function getCommandName(InputInterface $input) {
1027 992
         return $this->singleCommand ? $this->defaultCommand : $input->getFirstArgument();
1028 993
     }
1029 994
 
@@ -1032,8 +997,7 @@  discard block
 block discarded – undo
1032 997
      *
1033 998
      * @return InputDefinition An InputDefinition instance
1034 999
      */
1035
-    protected function getDefaultInputDefinition()
1036
-    {
1000
+    protected function getDefaultInputDefinition() {
1037 1001
         return new InputDefinition([
1038 1002
             new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
1039 1003
             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'),
@@ -1050,8 +1014,7 @@  discard block
 block discarded – undo
1050 1014
      *
1051 1015
      * @return Command[] An array of default Command instances
1052 1016
      */
1053
-    protected function getDefaultCommands()
1054
-    {
1017
+    protected function getDefaultCommands() {
1055 1018
         return [new HelpCommand(), new ListCommand()];
1056 1019
     }
1057 1020
 
@@ -1060,8 +1023,7 @@  discard block
 block discarded – undo
1060 1023
      *
1061 1024
      * @return HelperSet A HelperSet instance
1062 1025
      */
1063
-    protected function getDefaultHelperSet()
1064
-    {
1026
+    protected function getDefaultHelperSet() {
1065 1027
         return new HelperSet([
1066 1028
             new FormatterHelper(),
1067 1029
             new DebugFormatterHelper(),
@@ -1085,8 +1047,7 @@  discard block
 block discarded – undo
1085 1047
      *
1086 1048
      * @return string The namespace of the command
1087 1049
      */
1088
-    public function extractNamespace(string $name, int $limit = null)
1089
-    {
1050
+    public function extractNamespace(string $name, int $limit = null) {
1090 1051
         $parts = explode(':', $name, -1);
1091 1052
 
1092 1053
         return implode(':', null === $limit ? $parts : \array_slice($parts, 0, $limit));
@@ -1145,8 +1106,7 @@  discard block
 block discarded – undo
1145 1106
      *
1146 1107
      * @return self
1147 1108
      */
1148
-    public function setDefaultCommand(string $commandName, bool $isSingleCommand = false)
1149
-    {
1109
+    public function setDefaultCommand(string $commandName, bool $isSingleCommand = false) {
1150 1110
         $this->defaultCommand = explode('|', ltrim($commandName, '|'))[0];
1151 1111
 
1152 1112
         if ($isSingleCommand) {
@@ -1225,8 +1185,7 @@  discard block
 block discarded – undo
1225 1185
         return $namespaces;
1226 1186
     }
1227 1187
 
1228
-    private function init()
1229
-    {
1188
+    private function init() {
1230 1189
         if ($this->initialized) {
1231 1190
             return;
1232 1191
         }
Please login to merge, or discard this patch.