@@ -20,5 +20,5 @@ |
||
20 | 20 | */ |
21 | 21 | interface DescriptorInterface |
22 | 22 | { |
23 | - public function describe(OutputInterface $output, object $object, array $options = []); |
|
23 | + public function describe(OutputInterface $output, object $object, array $options = []); |
|
24 | 24 | } |
@@ -20,5 +20,5 @@ |
||
20 | 20 | */ |
21 | 21 | interface DescriptorInterface |
22 | 22 | { |
23 | - public function describe(OutputInterface $output, object $object, array $options = []); |
|
23 | + public function describe( OutputInterface $output, object $object, array $options = [ ] ); |
|
24 | 24 | } |
@@ -18,7 +18,6 @@ |
||
18 | 18 | * |
19 | 19 | * @author Jean-François Simon <[email protected]> |
20 | 20 | */ |
21 | -interface DescriptorInterface |
|
22 | -{ |
|
21 | +interface DescriptorInterface { |
|
23 | 22 | public function describe(OutputInterface $output, object $object, array $options = []); |
24 | 23 | } |
@@ -26,156 +26,156 @@ |
||
26 | 26 | */ |
27 | 27 | class JsonDescriptor extends Descriptor |
28 | 28 | { |
29 | - /** |
|
30 | - * {@inheritdoc} |
|
31 | - */ |
|
32 | - protected function describeInputArgument(InputArgument $argument, array $options = []) |
|
33 | - { |
|
34 | - $this->writeData($this->getInputArgumentData($argument), $options); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * {@inheritdoc} |
|
39 | - */ |
|
40 | - protected function describeInputOption(InputOption $option, array $options = []) |
|
41 | - { |
|
42 | - $this->writeData($this->getInputOptionData($option), $options); |
|
43 | - if ($option->isNegatable()) { |
|
44 | - $this->writeData($this->getInputOptionData($option, true), $options); |
|
45 | - } |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * {@inheritdoc} |
|
50 | - */ |
|
51 | - protected function describeInputDefinition(InputDefinition $definition, array $options = []) |
|
52 | - { |
|
53 | - $this->writeData($this->getInputDefinitionData($definition), $options); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - protected function describeCommand(Command $command, array $options = []) |
|
60 | - { |
|
61 | - $this->writeData($this->getCommandData($command, $options['short'] ?? false), $options); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - protected function describeApplication(Application $application, array $options = []) |
|
68 | - { |
|
69 | - $describedNamespace = $options['namespace'] ?? null; |
|
70 | - $description = new ApplicationDescription($application, $describedNamespace, true); |
|
71 | - $commands = []; |
|
72 | - |
|
73 | - foreach ($description->getCommands() as $command) { |
|
74 | - $commands[] = $this->getCommandData($command, $options['short'] ?? false); |
|
75 | - } |
|
76 | - |
|
77 | - $data = []; |
|
78 | - if ('UNKNOWN' !== $application->getName()) { |
|
79 | - $data['application']['name'] = $application->getName(); |
|
80 | - if ('UNKNOWN' !== $application->getVersion()) { |
|
81 | - $data['application']['version'] = $application->getVersion(); |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - $data['commands'] = $commands; |
|
86 | - |
|
87 | - if ($describedNamespace) { |
|
88 | - $data['namespace'] = $describedNamespace; |
|
89 | - } else { |
|
90 | - $data['namespaces'] = array_values($description->getNamespaces()); |
|
91 | - } |
|
92 | - |
|
93 | - $this->writeData($data, $options); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Writes data as json. |
|
98 | - */ |
|
99 | - private function writeData(array $data, array $options) |
|
100 | - { |
|
101 | - $flags = $options['json_encoding'] ?? 0; |
|
102 | - |
|
103 | - $this->write(json_encode($data, $flags)); |
|
104 | - } |
|
105 | - |
|
106 | - private function getInputArgumentData(InputArgument $argument): array |
|
107 | - { |
|
108 | - return [ |
|
109 | - 'name' => $argument->getName(), |
|
110 | - 'is_required' => $argument->isRequired(), |
|
111 | - 'is_array' => $argument->isArray(), |
|
112 | - 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()), |
|
113 | - 'default' => \INF === $argument->getDefault() ? 'INF' : $argument->getDefault(), |
|
114 | - ]; |
|
115 | - } |
|
116 | - |
|
117 | - private function getInputOptionData(InputOption $option, bool $negated = false): array |
|
118 | - { |
|
119 | - return $negated ? [ |
|
120 | - 'name' => '--no-'.$option->getName(), |
|
121 | - 'shortcut' => '', |
|
122 | - 'accept_value' => false, |
|
123 | - 'is_value_required' => false, |
|
124 | - 'is_multiple' => false, |
|
125 | - 'description' => 'Negate the "--'.$option->getName().'" option', |
|
126 | - 'default' => false, |
|
127 | - ] : [ |
|
128 | - 'name' => '--'.$option->getName(), |
|
129 | - 'shortcut' => $option->getShortcut() ? '-'.str_replace('|', '|-', $option->getShortcut()) : '', |
|
130 | - 'accept_value' => $option->acceptValue(), |
|
131 | - 'is_value_required' => $option->isValueRequired(), |
|
132 | - 'is_multiple' => $option->isArray(), |
|
133 | - 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()), |
|
134 | - 'default' => \INF === $option->getDefault() ? 'INF' : $option->getDefault(), |
|
135 | - ]; |
|
136 | - } |
|
137 | - |
|
138 | - private function getInputDefinitionData(InputDefinition $definition): array |
|
139 | - { |
|
140 | - $inputArguments = []; |
|
141 | - foreach ($definition->getArguments() as $name => $argument) { |
|
142 | - $inputArguments[$name] = $this->getInputArgumentData($argument); |
|
143 | - } |
|
144 | - |
|
145 | - $inputOptions = []; |
|
146 | - foreach ($definition->getOptions() as $name => $option) { |
|
147 | - $inputOptions[$name] = $this->getInputOptionData($option); |
|
148 | - if ($option->isNegatable()) { |
|
149 | - $inputOptions['no-'.$name] = $this->getInputOptionData($option, true); |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - return ['arguments' => $inputArguments, 'options' => $inputOptions]; |
|
154 | - } |
|
155 | - |
|
156 | - private function getCommandData(Command $command, bool $short = false): array |
|
157 | - { |
|
158 | - $data = [ |
|
159 | - 'name' => $command->getName(), |
|
160 | - 'description' => $command->getDescription(), |
|
161 | - ]; |
|
162 | - |
|
163 | - if ($short) { |
|
164 | - $data += [ |
|
165 | - 'usage' => $command->getAliases(), |
|
166 | - ]; |
|
167 | - } else { |
|
168 | - $command->mergeApplicationDefinition(false); |
|
169 | - |
|
170 | - $data += [ |
|
171 | - 'usage' => array_merge([$command->getSynopsis()], $command->getUsages(), $command->getAliases()), |
|
172 | - 'help' => $command->getProcessedHelp(), |
|
173 | - 'definition' => $this->getInputDefinitionData($command->getDefinition()), |
|
174 | - ]; |
|
175 | - } |
|
176 | - |
|
177 | - $data['hidden'] = $command->isHidden(); |
|
178 | - |
|
179 | - return $data; |
|
180 | - } |
|
29 | + /** |
|
30 | + * {@inheritdoc} |
|
31 | + */ |
|
32 | + protected function describeInputArgument(InputArgument $argument, array $options = []) |
|
33 | + { |
|
34 | + $this->writeData($this->getInputArgumentData($argument), $options); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * {@inheritdoc} |
|
39 | + */ |
|
40 | + protected function describeInputOption(InputOption $option, array $options = []) |
|
41 | + { |
|
42 | + $this->writeData($this->getInputOptionData($option), $options); |
|
43 | + if ($option->isNegatable()) { |
|
44 | + $this->writeData($this->getInputOptionData($option, true), $options); |
|
45 | + } |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * {@inheritdoc} |
|
50 | + */ |
|
51 | + protected function describeInputDefinition(InputDefinition $definition, array $options = []) |
|
52 | + { |
|
53 | + $this->writeData($this->getInputDefinitionData($definition), $options); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + protected function describeCommand(Command $command, array $options = []) |
|
60 | + { |
|
61 | + $this->writeData($this->getCommandData($command, $options['short'] ?? false), $options); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + protected function describeApplication(Application $application, array $options = []) |
|
68 | + { |
|
69 | + $describedNamespace = $options['namespace'] ?? null; |
|
70 | + $description = new ApplicationDescription($application, $describedNamespace, true); |
|
71 | + $commands = []; |
|
72 | + |
|
73 | + foreach ($description->getCommands() as $command) { |
|
74 | + $commands[] = $this->getCommandData($command, $options['short'] ?? false); |
|
75 | + } |
|
76 | + |
|
77 | + $data = []; |
|
78 | + if ('UNKNOWN' !== $application->getName()) { |
|
79 | + $data['application']['name'] = $application->getName(); |
|
80 | + if ('UNKNOWN' !== $application->getVersion()) { |
|
81 | + $data['application']['version'] = $application->getVersion(); |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + $data['commands'] = $commands; |
|
86 | + |
|
87 | + if ($describedNamespace) { |
|
88 | + $data['namespace'] = $describedNamespace; |
|
89 | + } else { |
|
90 | + $data['namespaces'] = array_values($description->getNamespaces()); |
|
91 | + } |
|
92 | + |
|
93 | + $this->writeData($data, $options); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Writes data as json. |
|
98 | + */ |
|
99 | + private function writeData(array $data, array $options) |
|
100 | + { |
|
101 | + $flags = $options['json_encoding'] ?? 0; |
|
102 | + |
|
103 | + $this->write(json_encode($data, $flags)); |
|
104 | + } |
|
105 | + |
|
106 | + private function getInputArgumentData(InputArgument $argument): array |
|
107 | + { |
|
108 | + return [ |
|
109 | + 'name' => $argument->getName(), |
|
110 | + 'is_required' => $argument->isRequired(), |
|
111 | + 'is_array' => $argument->isArray(), |
|
112 | + 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()), |
|
113 | + 'default' => \INF === $argument->getDefault() ? 'INF' : $argument->getDefault(), |
|
114 | + ]; |
|
115 | + } |
|
116 | + |
|
117 | + private function getInputOptionData(InputOption $option, bool $negated = false): array |
|
118 | + { |
|
119 | + return $negated ? [ |
|
120 | + 'name' => '--no-'.$option->getName(), |
|
121 | + 'shortcut' => '', |
|
122 | + 'accept_value' => false, |
|
123 | + 'is_value_required' => false, |
|
124 | + 'is_multiple' => false, |
|
125 | + 'description' => 'Negate the "--'.$option->getName().'" option', |
|
126 | + 'default' => false, |
|
127 | + ] : [ |
|
128 | + 'name' => '--'.$option->getName(), |
|
129 | + 'shortcut' => $option->getShortcut() ? '-'.str_replace('|', '|-', $option->getShortcut()) : '', |
|
130 | + 'accept_value' => $option->acceptValue(), |
|
131 | + 'is_value_required' => $option->isValueRequired(), |
|
132 | + 'is_multiple' => $option->isArray(), |
|
133 | + 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()), |
|
134 | + 'default' => \INF === $option->getDefault() ? 'INF' : $option->getDefault(), |
|
135 | + ]; |
|
136 | + } |
|
137 | + |
|
138 | + private function getInputDefinitionData(InputDefinition $definition): array |
|
139 | + { |
|
140 | + $inputArguments = []; |
|
141 | + foreach ($definition->getArguments() as $name => $argument) { |
|
142 | + $inputArguments[$name] = $this->getInputArgumentData($argument); |
|
143 | + } |
|
144 | + |
|
145 | + $inputOptions = []; |
|
146 | + foreach ($definition->getOptions() as $name => $option) { |
|
147 | + $inputOptions[$name] = $this->getInputOptionData($option); |
|
148 | + if ($option->isNegatable()) { |
|
149 | + $inputOptions['no-'.$name] = $this->getInputOptionData($option, true); |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + return ['arguments' => $inputArguments, 'options' => $inputOptions]; |
|
154 | + } |
|
155 | + |
|
156 | + private function getCommandData(Command $command, bool $short = false): array |
|
157 | + { |
|
158 | + $data = [ |
|
159 | + 'name' => $command->getName(), |
|
160 | + 'description' => $command->getDescription(), |
|
161 | + ]; |
|
162 | + |
|
163 | + if ($short) { |
|
164 | + $data += [ |
|
165 | + 'usage' => $command->getAliases(), |
|
166 | + ]; |
|
167 | + } else { |
|
168 | + $command->mergeApplicationDefinition(false); |
|
169 | + |
|
170 | + $data += [ |
|
171 | + 'usage' => array_merge([$command->getSynopsis()], $command->getUsages(), $command->getAliases()), |
|
172 | + 'help' => $command->getProcessedHelp(), |
|
173 | + 'definition' => $this->getInputDefinitionData($command->getDefinition()), |
|
174 | + ]; |
|
175 | + } |
|
176 | + |
|
177 | + $data['hidden'] = $command->isHidden(); |
|
178 | + |
|
179 | + return $data; |
|
180 | + } |
|
181 | 181 | } |
@@ -29,152 +29,152 @@ |
||
29 | 29 | /** |
30 | 30 | * {@inheritdoc} |
31 | 31 | */ |
32 | - protected function describeInputArgument(InputArgument $argument, array $options = []) |
|
32 | + protected function describeInputArgument( InputArgument $argument, array $options = [ ] ) |
|
33 | 33 | { |
34 | - $this->writeData($this->getInputArgumentData($argument), $options); |
|
34 | + $this->writeData( $this->getInputArgumentData( $argument ), $options ); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * {@inheritdoc} |
39 | 39 | */ |
40 | - protected function describeInputOption(InputOption $option, array $options = []) |
|
40 | + protected function describeInputOption( InputOption $option, array $options = [ ] ) |
|
41 | 41 | { |
42 | - $this->writeData($this->getInputOptionData($option), $options); |
|
43 | - if ($option->isNegatable()) { |
|
44 | - $this->writeData($this->getInputOptionData($option, true), $options); |
|
42 | + $this->writeData( $this->getInputOptionData( $option ), $options ); |
|
43 | + if ( $option->isNegatable() ) { |
|
44 | + $this->writeData( $this->getInputOptionData( $option, true ), $options ); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | 49 | * {@inheritdoc} |
50 | 50 | */ |
51 | - protected function describeInputDefinition(InputDefinition $definition, array $options = []) |
|
51 | + protected function describeInputDefinition( InputDefinition $definition, array $options = [ ] ) |
|
52 | 52 | { |
53 | - $this->writeData($this->getInputDefinitionData($definition), $options); |
|
53 | + $this->writeData( $this->getInputDefinitionData( $definition ), $options ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * {@inheritdoc} |
58 | 58 | */ |
59 | - protected function describeCommand(Command $command, array $options = []) |
|
59 | + protected function describeCommand( Command $command, array $options = [ ] ) |
|
60 | 60 | { |
61 | - $this->writeData($this->getCommandData($command, $options['short'] ?? false), $options); |
|
61 | + $this->writeData( $this->getCommandData( $command, $options[ 'short' ] ?? false ), $options ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * {@inheritdoc} |
66 | 66 | */ |
67 | - protected function describeApplication(Application $application, array $options = []) |
|
67 | + protected function describeApplication( Application $application, array $options = [ ] ) |
|
68 | 68 | { |
69 | - $describedNamespace = $options['namespace'] ?? null; |
|
70 | - $description = new ApplicationDescription($application, $describedNamespace, true); |
|
71 | - $commands = []; |
|
69 | + $describedNamespace = $options[ 'namespace' ] ?? null; |
|
70 | + $description = new ApplicationDescription( $application, $describedNamespace, true ); |
|
71 | + $commands = [ ]; |
|
72 | 72 | |
73 | - foreach ($description->getCommands() as $command) { |
|
74 | - $commands[] = $this->getCommandData($command, $options['short'] ?? false); |
|
73 | + foreach ( $description->getCommands() as $command ) { |
|
74 | + $commands[ ] = $this->getCommandData( $command, $options[ 'short' ] ?? false ); |
|
75 | 75 | } |
76 | 76 | |
77 | - $data = []; |
|
78 | - if ('UNKNOWN' !== $application->getName()) { |
|
79 | - $data['application']['name'] = $application->getName(); |
|
80 | - if ('UNKNOWN' !== $application->getVersion()) { |
|
81 | - $data['application']['version'] = $application->getVersion(); |
|
77 | + $data = [ ]; |
|
78 | + if ( 'UNKNOWN' !== $application->getName() ) { |
|
79 | + $data[ 'application' ][ 'name' ] = $application->getName(); |
|
80 | + if ( 'UNKNOWN' !== $application->getVersion() ) { |
|
81 | + $data[ 'application' ][ 'version' ] = $application->getVersion(); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - $data['commands'] = $commands; |
|
85 | + $data[ 'commands' ] = $commands; |
|
86 | 86 | |
87 | - if ($describedNamespace) { |
|
88 | - $data['namespace'] = $describedNamespace; |
|
87 | + if ( $describedNamespace ) { |
|
88 | + $data[ 'namespace' ] = $describedNamespace; |
|
89 | 89 | } else { |
90 | - $data['namespaces'] = array_values($description->getNamespaces()); |
|
90 | + $data[ 'namespaces' ] = array_values( $description->getNamespaces() ); |
|
91 | 91 | } |
92 | 92 | |
93 | - $this->writeData($data, $options); |
|
93 | + $this->writeData( $data, $options ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | 97 | * Writes data as json. |
98 | 98 | */ |
99 | - private function writeData(array $data, array $options) |
|
99 | + private function writeData( array $data, array $options ) |
|
100 | 100 | { |
101 | - $flags = $options['json_encoding'] ?? 0; |
|
101 | + $flags = $options[ 'json_encoding' ] ?? 0; |
|
102 | 102 | |
103 | - $this->write(json_encode($data, $flags)); |
|
103 | + $this->write( json_encode( $data, $flags ) ); |
|
104 | 104 | } |
105 | 105 | |
106 | - private function getInputArgumentData(InputArgument $argument): array |
|
106 | + private function getInputArgumentData( InputArgument $argument ): array |
|
107 | 107 | { |
108 | 108 | return [ |
109 | 109 | 'name' => $argument->getName(), |
110 | 110 | 'is_required' => $argument->isRequired(), |
111 | 111 | 'is_array' => $argument->isArray(), |
112 | - 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()), |
|
112 | + 'description' => preg_replace( '/\s*[\r\n]\s*/', ' ', $argument->getDescription() ), |
|
113 | 113 | 'default' => \INF === $argument->getDefault() ? 'INF' : $argument->getDefault(), |
114 | 114 | ]; |
115 | 115 | } |
116 | 116 | |
117 | - private function getInputOptionData(InputOption $option, bool $negated = false): array |
|
117 | + private function getInputOptionData( InputOption $option, bool $negated = false ): array |
|
118 | 118 | { |
119 | 119 | return $negated ? [ |
120 | - 'name' => '--no-'.$option->getName(), |
|
120 | + 'name' => '--no-' . $option->getName(), |
|
121 | 121 | 'shortcut' => '', |
122 | 122 | 'accept_value' => false, |
123 | 123 | 'is_value_required' => false, |
124 | 124 | 'is_multiple' => false, |
125 | - 'description' => 'Negate the "--'.$option->getName().'" option', |
|
125 | + 'description' => 'Negate the "--' . $option->getName() . '" option', |
|
126 | 126 | 'default' => false, |
127 | 127 | ] : [ |
128 | - 'name' => '--'.$option->getName(), |
|
129 | - 'shortcut' => $option->getShortcut() ? '-'.str_replace('|', '|-', $option->getShortcut()) : '', |
|
128 | + 'name' => '--' . $option->getName(), |
|
129 | + 'shortcut' => $option->getShortcut() ? '-' . str_replace( '|', '|-', $option->getShortcut() ) : '', |
|
130 | 130 | 'accept_value' => $option->acceptValue(), |
131 | 131 | 'is_value_required' => $option->isValueRequired(), |
132 | 132 | 'is_multiple' => $option->isArray(), |
133 | - 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()), |
|
133 | + 'description' => preg_replace( '/\s*[\r\n]\s*/', ' ', $option->getDescription() ), |
|
134 | 134 | 'default' => \INF === $option->getDefault() ? 'INF' : $option->getDefault(), |
135 | 135 | ]; |
136 | 136 | } |
137 | 137 | |
138 | - private function getInputDefinitionData(InputDefinition $definition): array |
|
138 | + private function getInputDefinitionData( InputDefinition $definition ): array |
|
139 | 139 | { |
140 | - $inputArguments = []; |
|
141 | - foreach ($definition->getArguments() as $name => $argument) { |
|
142 | - $inputArguments[$name] = $this->getInputArgumentData($argument); |
|
140 | + $inputArguments = [ ]; |
|
141 | + foreach ( $definition->getArguments() as $name => $argument ) { |
|
142 | + $inputArguments[ $name ] = $this->getInputArgumentData( $argument ); |
|
143 | 143 | } |
144 | 144 | |
145 | - $inputOptions = []; |
|
146 | - foreach ($definition->getOptions() as $name => $option) { |
|
147 | - $inputOptions[$name] = $this->getInputOptionData($option); |
|
148 | - if ($option->isNegatable()) { |
|
149 | - $inputOptions['no-'.$name] = $this->getInputOptionData($option, true); |
|
145 | + $inputOptions = [ ]; |
|
146 | + foreach ( $definition->getOptions() as $name => $option ) { |
|
147 | + $inputOptions[ $name ] = $this->getInputOptionData( $option ); |
|
148 | + if ( $option->isNegatable() ) { |
|
149 | + $inputOptions[ 'no-' . $name ] = $this->getInputOptionData( $option, true ); |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
153 | - return ['arguments' => $inputArguments, 'options' => $inputOptions]; |
|
153 | + return [ 'arguments' => $inputArguments, 'options' => $inputOptions ]; |
|
154 | 154 | } |
155 | 155 | |
156 | - private function getCommandData(Command $command, bool $short = false): array |
|
156 | + private function getCommandData( Command $command, bool $short = false ): array |
|
157 | 157 | { |
158 | 158 | $data = [ |
159 | 159 | 'name' => $command->getName(), |
160 | 160 | 'description' => $command->getDescription(), |
161 | 161 | ]; |
162 | 162 | |
163 | - if ($short) { |
|
163 | + if ( $short ) { |
|
164 | 164 | $data += [ |
165 | 165 | 'usage' => $command->getAliases(), |
166 | 166 | ]; |
167 | 167 | } else { |
168 | - $command->mergeApplicationDefinition(false); |
|
168 | + $command->mergeApplicationDefinition( false ); |
|
169 | 169 | |
170 | 170 | $data += [ |
171 | - 'usage' => array_merge([$command->getSynopsis()], $command->getUsages(), $command->getAliases()), |
|
171 | + 'usage' => array_merge( [ $command->getSynopsis() ], $command->getUsages(), $command->getAliases() ), |
|
172 | 172 | 'help' => $command->getProcessedHelp(), |
173 | - 'definition' => $this->getInputDefinitionData($command->getDefinition()), |
|
173 | + 'definition' => $this->getInputDefinitionData( $command->getDefinition() ), |
|
174 | 174 | ]; |
175 | 175 | } |
176 | 176 | |
177 | - $data['hidden'] = $command->isHidden(); |
|
177 | + $data[ 'hidden' ] = $command->isHidden(); |
|
178 | 178 | |
179 | 179 | return $data; |
180 | 180 | } |
@@ -24,21 +24,18 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @internal |
26 | 26 | */ |
27 | -class JsonDescriptor extends Descriptor |
|
28 | -{ |
|
27 | +class JsonDescriptor extends Descriptor { |
|
29 | 28 | /** |
30 | 29 | * {@inheritdoc} |
31 | 30 | */ |
32 | - protected function describeInputArgument(InputArgument $argument, array $options = []) |
|
33 | - { |
|
31 | + protected function describeInputArgument(InputArgument $argument, array $options = []) { |
|
34 | 32 | $this->writeData($this->getInputArgumentData($argument), $options); |
35 | 33 | } |
36 | 34 | |
37 | 35 | /** |
38 | 36 | * {@inheritdoc} |
39 | 37 | */ |
40 | - protected function describeInputOption(InputOption $option, array $options = []) |
|
41 | - { |
|
38 | + protected function describeInputOption(InputOption $option, array $options = []) { |
|
42 | 39 | $this->writeData($this->getInputOptionData($option), $options); |
43 | 40 | if ($option->isNegatable()) { |
44 | 41 | $this->writeData($this->getInputOptionData($option, true), $options); |
@@ -48,24 +45,21 @@ discard block |
||
48 | 45 | /** |
49 | 46 | * {@inheritdoc} |
50 | 47 | */ |
51 | - protected function describeInputDefinition(InputDefinition $definition, array $options = []) |
|
52 | - { |
|
48 | + protected function describeInputDefinition(InputDefinition $definition, array $options = []) { |
|
53 | 49 | $this->writeData($this->getInputDefinitionData($definition), $options); |
54 | 50 | } |
55 | 51 | |
56 | 52 | /** |
57 | 53 | * {@inheritdoc} |
58 | 54 | */ |
59 | - protected function describeCommand(Command $command, array $options = []) |
|
60 | - { |
|
55 | + protected function describeCommand(Command $command, array $options = []) { |
|
61 | 56 | $this->writeData($this->getCommandData($command, $options['short'] ?? false), $options); |
62 | 57 | } |
63 | 58 | |
64 | 59 | /** |
65 | 60 | * {@inheritdoc} |
66 | 61 | */ |
67 | - protected function describeApplication(Application $application, array $options = []) |
|
68 | - { |
|
62 | + protected function describeApplication(Application $application, array $options = []) { |
|
69 | 63 | $describedNamespace = $options['namespace'] ?? null; |
70 | 64 | $description = new ApplicationDescription($application, $describedNamespace, true); |
71 | 65 | $commands = []; |
@@ -96,8 +90,7 @@ discard block |
||
96 | 90 | /** |
97 | 91 | * Writes data as json. |
98 | 92 | */ |
99 | - private function writeData(array $data, array $options) |
|
100 | - { |
|
93 | + private function writeData(array $data, array $options) { |
|
101 | 94 | $flags = $options['json_encoding'] ?? 0; |
102 | 95 | |
103 | 96 | $this->write(json_encode($data, $flags)); |
@@ -22,122 +22,122 @@ |
||
22 | 22 | */ |
23 | 23 | class ApplicationDescription |
24 | 24 | { |
25 | - public const GLOBAL_NAMESPACE = '_global'; |
|
26 | - |
|
27 | - private $application; |
|
28 | - private $namespace; |
|
29 | - private $showHidden; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - private $namespaces; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Command[] |
|
38 | - */ |
|
39 | - private $commands; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var Command[] |
|
43 | - */ |
|
44 | - private $aliases; |
|
45 | - |
|
46 | - public function __construct(Application $application, string $namespace = null, bool $showHidden = false) |
|
47 | - { |
|
48 | - $this->application = $application; |
|
49 | - $this->namespace = $namespace; |
|
50 | - $this->showHidden = $showHidden; |
|
51 | - } |
|
52 | - |
|
53 | - public function getNamespaces(): array |
|
54 | - { |
|
55 | - if (null === $this->namespaces) { |
|
56 | - $this->inspectApplication(); |
|
57 | - } |
|
58 | - |
|
59 | - return $this->namespaces; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @return Command[] |
|
64 | - */ |
|
65 | - public function getCommands(): array |
|
66 | - { |
|
67 | - if (null === $this->commands) { |
|
68 | - $this->inspectApplication(); |
|
69 | - } |
|
70 | - |
|
71 | - return $this->commands; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @throws CommandNotFoundException |
|
76 | - */ |
|
77 | - public function getCommand(string $name): Command |
|
78 | - { |
|
79 | - if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) { |
|
80 | - throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); |
|
81 | - } |
|
82 | - |
|
83 | - return $this->commands[$name] ?? $this->aliases[$name]; |
|
84 | - } |
|
85 | - |
|
86 | - private function inspectApplication() |
|
87 | - { |
|
88 | - $this->commands = []; |
|
89 | - $this->namespaces = []; |
|
90 | - |
|
91 | - $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null); |
|
92 | - foreach ($this->sortCommands($all) as $namespace => $commands) { |
|
93 | - $names = []; |
|
94 | - |
|
95 | - /** @var Command $command */ |
|
96 | - foreach ($commands as $name => $command) { |
|
97 | - if (!$command->getName() || (!$this->showHidden && $command->isHidden())) { |
|
98 | - continue; |
|
99 | - } |
|
100 | - |
|
101 | - if ($command->getName() === $name) { |
|
102 | - $this->commands[$name] = $command; |
|
103 | - } else { |
|
104 | - $this->aliases[$name] = $command; |
|
105 | - } |
|
106 | - |
|
107 | - $names[] = $name; |
|
108 | - } |
|
109 | - |
|
110 | - $this->namespaces[$namespace] = ['id' => $namespace, 'commands' => $names]; |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - private function sortCommands(array $commands): array |
|
115 | - { |
|
116 | - $namespacedCommands = []; |
|
117 | - $globalCommands = []; |
|
118 | - $sortedCommands = []; |
|
119 | - foreach ($commands as $name => $command) { |
|
120 | - $key = $this->application->extractNamespace($name, 1); |
|
121 | - if (\in_array($key, ['', self::GLOBAL_NAMESPACE], true)) { |
|
122 | - $globalCommands[$name] = $command; |
|
123 | - } else { |
|
124 | - $namespacedCommands[$key][$name] = $command; |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - if ($globalCommands) { |
|
129 | - ksort($globalCommands); |
|
130 | - $sortedCommands[self::GLOBAL_NAMESPACE] = $globalCommands; |
|
131 | - } |
|
132 | - |
|
133 | - if ($namespacedCommands) { |
|
134 | - ksort($namespacedCommands); |
|
135 | - foreach ($namespacedCommands as $key => $commandsSet) { |
|
136 | - ksort($commandsSet); |
|
137 | - $sortedCommands[$key] = $commandsSet; |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - return $sortedCommands; |
|
142 | - } |
|
25 | + public const GLOBAL_NAMESPACE = '_global'; |
|
26 | + |
|
27 | + private $application; |
|
28 | + private $namespace; |
|
29 | + private $showHidden; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + private $namespaces; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Command[] |
|
38 | + */ |
|
39 | + private $commands; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var Command[] |
|
43 | + */ |
|
44 | + private $aliases; |
|
45 | + |
|
46 | + public function __construct(Application $application, string $namespace = null, bool $showHidden = false) |
|
47 | + { |
|
48 | + $this->application = $application; |
|
49 | + $this->namespace = $namespace; |
|
50 | + $this->showHidden = $showHidden; |
|
51 | + } |
|
52 | + |
|
53 | + public function getNamespaces(): array |
|
54 | + { |
|
55 | + if (null === $this->namespaces) { |
|
56 | + $this->inspectApplication(); |
|
57 | + } |
|
58 | + |
|
59 | + return $this->namespaces; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @return Command[] |
|
64 | + */ |
|
65 | + public function getCommands(): array |
|
66 | + { |
|
67 | + if (null === $this->commands) { |
|
68 | + $this->inspectApplication(); |
|
69 | + } |
|
70 | + |
|
71 | + return $this->commands; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @throws CommandNotFoundException |
|
76 | + */ |
|
77 | + public function getCommand(string $name): Command |
|
78 | + { |
|
79 | + if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) { |
|
80 | + throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); |
|
81 | + } |
|
82 | + |
|
83 | + return $this->commands[$name] ?? $this->aliases[$name]; |
|
84 | + } |
|
85 | + |
|
86 | + private function inspectApplication() |
|
87 | + { |
|
88 | + $this->commands = []; |
|
89 | + $this->namespaces = []; |
|
90 | + |
|
91 | + $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null); |
|
92 | + foreach ($this->sortCommands($all) as $namespace => $commands) { |
|
93 | + $names = []; |
|
94 | + |
|
95 | + /** @var Command $command */ |
|
96 | + foreach ($commands as $name => $command) { |
|
97 | + if (!$command->getName() || (!$this->showHidden && $command->isHidden())) { |
|
98 | + continue; |
|
99 | + } |
|
100 | + |
|
101 | + if ($command->getName() === $name) { |
|
102 | + $this->commands[$name] = $command; |
|
103 | + } else { |
|
104 | + $this->aliases[$name] = $command; |
|
105 | + } |
|
106 | + |
|
107 | + $names[] = $name; |
|
108 | + } |
|
109 | + |
|
110 | + $this->namespaces[$namespace] = ['id' => $namespace, 'commands' => $names]; |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + private function sortCommands(array $commands): array |
|
115 | + { |
|
116 | + $namespacedCommands = []; |
|
117 | + $globalCommands = []; |
|
118 | + $sortedCommands = []; |
|
119 | + foreach ($commands as $name => $command) { |
|
120 | + $key = $this->application->extractNamespace($name, 1); |
|
121 | + if (\in_array($key, ['', self::GLOBAL_NAMESPACE], true)) { |
|
122 | + $globalCommands[$name] = $command; |
|
123 | + } else { |
|
124 | + $namespacedCommands[$key][$name] = $command; |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + if ($globalCommands) { |
|
129 | + ksort($globalCommands); |
|
130 | + $sortedCommands[self::GLOBAL_NAMESPACE] = $globalCommands; |
|
131 | + } |
|
132 | + |
|
133 | + if ($namespacedCommands) { |
|
134 | + ksort($namespacedCommands); |
|
135 | + foreach ($namespacedCommands as $key => $commandsSet) { |
|
136 | + ksort($commandsSet); |
|
137 | + $sortedCommands[$key] = $commandsSet; |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + return $sortedCommands; |
|
142 | + } |
|
143 | 143 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | private $aliases; |
45 | 45 | |
46 | - public function __construct(Application $application, string $namespace = null, bool $showHidden = false) |
|
46 | + public function __construct( Application $application, string $namespace = null, bool $showHidden = false ) |
|
47 | 47 | { |
48 | 48 | $this->application = $application; |
49 | 49 | $this->namespace = $namespace; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | public function getNamespaces(): array |
54 | 54 | { |
55 | - if (null === $this->namespaces) { |
|
55 | + if ( null === $this->namespaces ) { |
|
56 | 56 | $this->inspectApplication(); |
57 | 57 | } |
58 | 58 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function getCommands(): array |
66 | 66 | { |
67 | - if (null === $this->commands) { |
|
67 | + if ( null === $this->commands ) { |
|
68 | 68 | $this->inspectApplication(); |
69 | 69 | } |
70 | 70 | |
@@ -74,67 +74,67 @@ discard block |
||
74 | 74 | /** |
75 | 75 | * @throws CommandNotFoundException |
76 | 76 | */ |
77 | - public function getCommand(string $name): Command |
|
77 | + public function getCommand( string $name ): Command |
|
78 | 78 | { |
79 | - if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) { |
|
80 | - throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); |
|
79 | + if ( ! isset( $this->commands[ $name ] ) && ! isset( $this->aliases[ $name ] ) ) { |
|
80 | + throw new CommandNotFoundException( sprintf( 'Command "%s" does not exist.', $name ) ); |
|
81 | 81 | } |
82 | 82 | |
83 | - return $this->commands[$name] ?? $this->aliases[$name]; |
|
83 | + return $this->commands[ $name ] ?? $this->aliases[ $name ]; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | private function inspectApplication() |
87 | 87 | { |
88 | - $this->commands = []; |
|
89 | - $this->namespaces = []; |
|
88 | + $this->commands = [ ]; |
|
89 | + $this->namespaces = [ ]; |
|
90 | 90 | |
91 | - $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null); |
|
92 | - foreach ($this->sortCommands($all) as $namespace => $commands) { |
|
93 | - $names = []; |
|
91 | + $all = $this->application->all( $this->namespace ? $this->application->findNamespace( $this->namespace ) : null ); |
|
92 | + foreach ( $this->sortCommands( $all ) as $namespace => $commands ) { |
|
93 | + $names = [ ]; |
|
94 | 94 | |
95 | 95 | /** @var Command $command */ |
96 | - foreach ($commands as $name => $command) { |
|
97 | - if (!$command->getName() || (!$this->showHidden && $command->isHidden())) { |
|
96 | + foreach ( $commands as $name => $command ) { |
|
97 | + if ( ! $command->getName() || ( ! $this->showHidden && $command->isHidden() ) ) { |
|
98 | 98 | continue; |
99 | 99 | } |
100 | 100 | |
101 | - if ($command->getName() === $name) { |
|
102 | - $this->commands[$name] = $command; |
|
101 | + if ( $command->getName() === $name ) { |
|
102 | + $this->commands[ $name ] = $command; |
|
103 | 103 | } else { |
104 | - $this->aliases[$name] = $command; |
|
104 | + $this->aliases[ $name ] = $command; |
|
105 | 105 | } |
106 | 106 | |
107 | - $names[] = $name; |
|
107 | + $names[ ] = $name; |
|
108 | 108 | } |
109 | 109 | |
110 | - $this->namespaces[$namespace] = ['id' => $namespace, 'commands' => $names]; |
|
110 | + $this->namespaces[ $namespace ] = [ 'id' => $namespace, 'commands' => $names ]; |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
114 | - private function sortCommands(array $commands): array |
|
114 | + private function sortCommands( array $commands ): array |
|
115 | 115 | { |
116 | - $namespacedCommands = []; |
|
117 | - $globalCommands = []; |
|
118 | - $sortedCommands = []; |
|
119 | - foreach ($commands as $name => $command) { |
|
120 | - $key = $this->application->extractNamespace($name, 1); |
|
121 | - if (\in_array($key, ['', self::GLOBAL_NAMESPACE], true)) { |
|
122 | - $globalCommands[$name] = $command; |
|
116 | + $namespacedCommands = [ ]; |
|
117 | + $globalCommands = [ ]; |
|
118 | + $sortedCommands = [ ]; |
|
119 | + foreach ( $commands as $name => $command ) { |
|
120 | + $key = $this->application->extractNamespace( $name, 1 ); |
|
121 | + if ( \in_array( $key, [ '', self::GLOBAL_NAMESPACE ], true ) ) { |
|
122 | + $globalCommands[ $name ] = $command; |
|
123 | 123 | } else { |
124 | - $namespacedCommands[$key][$name] = $command; |
|
124 | + $namespacedCommands[ $key ][ $name ] = $command; |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | - if ($globalCommands) { |
|
129 | - ksort($globalCommands); |
|
130 | - $sortedCommands[self::GLOBAL_NAMESPACE] = $globalCommands; |
|
128 | + if ( $globalCommands ) { |
|
129 | + ksort( $globalCommands ); |
|
130 | + $sortedCommands[ self::GLOBAL_NAMESPACE ] = $globalCommands; |
|
131 | 131 | } |
132 | 132 | |
133 | - if ($namespacedCommands) { |
|
134 | - ksort($namespacedCommands); |
|
135 | - foreach ($namespacedCommands as $key => $commandsSet) { |
|
136 | - ksort($commandsSet); |
|
137 | - $sortedCommands[$key] = $commandsSet; |
|
133 | + if ( $namespacedCommands ) { |
|
134 | + ksort( $namespacedCommands ); |
|
135 | + foreach ( $namespacedCommands as $key => $commandsSet ) { |
|
136 | + ksort( $commandsSet ); |
|
137 | + $sortedCommands[ $key ] = $commandsSet; |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 |
@@ -20,8 +20,7 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @internal |
22 | 22 | */ |
23 | -class ApplicationDescription |
|
24 | -{ |
|
23 | +class ApplicationDescription { |
|
25 | 24 | public const GLOBAL_NAMESPACE = '_global'; |
26 | 25 | |
27 | 26 | private $application; |
@@ -43,8 +42,7 @@ discard block |
||
43 | 42 | */ |
44 | 43 | private $aliases; |
45 | 44 | |
46 | - public function __construct(Application $application, string $namespace = null, bool $showHidden = false) |
|
47 | - { |
|
45 | + public function __construct(Application $application, string $namespace = null, bool $showHidden = false) { |
|
48 | 46 | $this->application = $application; |
49 | 47 | $this->namespace = $namespace; |
50 | 48 | $this->showHidden = $showHidden; |
@@ -83,8 +81,7 @@ discard block |
||
83 | 81 | return $this->commands[$name] ?? $this->aliases[$name]; |
84 | 82 | } |
85 | 83 | |
86 | - private function inspectApplication() |
|
87 | - { |
|
84 | + private function inspectApplication() { |
|
88 | 85 | $this->commands = []; |
89 | 86 | $this->namespaces = []; |
90 | 87 |
@@ -20,80 +20,80 @@ |
||
20 | 20 | */ |
21 | 21 | class GithubActionReporter |
22 | 22 | { |
23 | - private $output; |
|
23 | + private $output; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @see https://github.com/actions/toolkit/blob/5e5e1b7aacba68a53836a34db4a288c3c1c1585b/packages/core/src/command.ts#L80-L85 |
|
27 | - */ |
|
28 | - private const ESCAPED_DATA = [ |
|
29 | - '%' => '%25', |
|
30 | - "\r" => '%0D', |
|
31 | - "\n" => '%0A', |
|
32 | - ]; |
|
25 | + /** |
|
26 | + * @see https://github.com/actions/toolkit/blob/5e5e1b7aacba68a53836a34db4a288c3c1c1585b/packages/core/src/command.ts#L80-L85 |
|
27 | + */ |
|
28 | + private const ESCAPED_DATA = [ |
|
29 | + '%' => '%25', |
|
30 | + "\r" => '%0D', |
|
31 | + "\n" => '%0A', |
|
32 | + ]; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @see https://github.com/actions/toolkit/blob/5e5e1b7aacba68a53836a34db4a288c3c1c1585b/packages/core/src/command.ts#L87-L94 |
|
36 | - */ |
|
37 | - private const ESCAPED_PROPERTIES = [ |
|
38 | - '%' => '%25', |
|
39 | - "\r" => '%0D', |
|
40 | - "\n" => '%0A', |
|
41 | - ':' => '%3A', |
|
42 | - ',' => '%2C', |
|
43 | - ]; |
|
34 | + /** |
|
35 | + * @see https://github.com/actions/toolkit/blob/5e5e1b7aacba68a53836a34db4a288c3c1c1585b/packages/core/src/command.ts#L87-L94 |
|
36 | + */ |
|
37 | + private const ESCAPED_PROPERTIES = [ |
|
38 | + '%' => '%25', |
|
39 | + "\r" => '%0D', |
|
40 | + "\n" => '%0A', |
|
41 | + ':' => '%3A', |
|
42 | + ',' => '%2C', |
|
43 | + ]; |
|
44 | 44 | |
45 | - public function __construct(OutputInterface $output) |
|
46 | - { |
|
47 | - $this->output = $output; |
|
48 | - } |
|
45 | + public function __construct(OutputInterface $output) |
|
46 | + { |
|
47 | + $this->output = $output; |
|
48 | + } |
|
49 | 49 | |
50 | - public static function isGithubActionEnvironment(): bool |
|
51 | - { |
|
52 | - return false !== getenv('GITHUB_ACTIONS'); |
|
53 | - } |
|
50 | + public static function isGithubActionEnvironment(): bool |
|
51 | + { |
|
52 | + return false !== getenv('GITHUB_ACTIONS'); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Output an error using the Github annotations format. |
|
57 | - * |
|
58 | - * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-error-message |
|
59 | - */ |
|
60 | - public function error(string $message, string $file = null, int $line = null, int $col = null): void |
|
61 | - { |
|
62 | - $this->log('error', $message, $file, $line, $col); |
|
63 | - } |
|
55 | + /** |
|
56 | + * Output an error using the Github annotations format. |
|
57 | + * |
|
58 | + * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-error-message |
|
59 | + */ |
|
60 | + public function error(string $message, string $file = null, int $line = null, int $col = null): void |
|
61 | + { |
|
62 | + $this->log('error', $message, $file, $line, $col); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Output a warning using the Github annotations format. |
|
67 | - * |
|
68 | - * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message |
|
69 | - */ |
|
70 | - public function warning(string $message, string $file = null, int $line = null, int $col = null): void |
|
71 | - { |
|
72 | - $this->log('warning', $message, $file, $line, $col); |
|
73 | - } |
|
65 | + /** |
|
66 | + * Output a warning using the Github annotations format. |
|
67 | + * |
|
68 | + * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message |
|
69 | + */ |
|
70 | + public function warning(string $message, string $file = null, int $line = null, int $col = null): void |
|
71 | + { |
|
72 | + $this->log('warning', $message, $file, $line, $col); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Output a debug log using the Github annotations format. |
|
77 | - * |
|
78 | - * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-debug-message |
|
79 | - */ |
|
80 | - public function debug(string $message, string $file = null, int $line = null, int $col = null): void |
|
81 | - { |
|
82 | - $this->log('debug', $message, $file, $line, $col); |
|
83 | - } |
|
75 | + /** |
|
76 | + * Output a debug log using the Github annotations format. |
|
77 | + * |
|
78 | + * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-debug-message |
|
79 | + */ |
|
80 | + public function debug(string $message, string $file = null, int $line = null, int $col = null): void |
|
81 | + { |
|
82 | + $this->log('debug', $message, $file, $line, $col); |
|
83 | + } |
|
84 | 84 | |
85 | - private function log(string $type, string $message, string $file = null, int $line = null, int $col = null): void |
|
86 | - { |
|
87 | - // Some values must be encoded. |
|
88 | - $message = strtr($message, self::ESCAPED_DATA); |
|
85 | + private function log(string $type, string $message, string $file = null, int $line = null, int $col = null): void |
|
86 | + { |
|
87 | + // Some values must be encoded. |
|
88 | + $message = strtr($message, self::ESCAPED_DATA); |
|
89 | 89 | |
90 | - if (!$file) { |
|
91 | - // No file provided, output the message solely: |
|
92 | - $this->output->writeln(sprintf('::%s::%s', $type, $message)); |
|
90 | + if (!$file) { |
|
91 | + // No file provided, output the message solely: |
|
92 | + $this->output->writeln(sprintf('::%s::%s', $type, $message)); |
|
93 | 93 | |
94 | - return; |
|
95 | - } |
|
94 | + return; |
|
95 | + } |
|
96 | 96 | |
97 | - $this->output->writeln(sprintf('::%s file=%s,line=%s,col=%s::%s', $type, strtr($file, self::ESCAPED_PROPERTIES), strtr($line ?? 1, self::ESCAPED_PROPERTIES), strtr($col ?? 0, self::ESCAPED_PROPERTIES), $message)); |
|
98 | - } |
|
97 | + $this->output->writeln(sprintf('::%s file=%s,line=%s,col=%s::%s', $type, strtr($file, self::ESCAPED_PROPERTIES), strtr($line ?? 1, self::ESCAPED_PROPERTIES), strtr($col ?? 0, self::ESCAPED_PROPERTIES), $message)); |
|
98 | + } |
|
99 | 99 | } |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | ',' => '%2C', |
43 | 43 | ]; |
44 | 44 | |
45 | - public function __construct(OutputInterface $output) |
|
45 | + public function __construct( OutputInterface $output ) |
|
46 | 46 | { |
47 | 47 | $this->output = $output; |
48 | 48 | } |
49 | 49 | |
50 | 50 | public static function isGithubActionEnvironment(): bool |
51 | 51 | { |
52 | - return false !== getenv('GITHUB_ACTIONS'); |
|
52 | + return false !== getenv( 'GITHUB_ACTIONS' ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-error-message |
59 | 59 | */ |
60 | - public function error(string $message, string $file = null, int $line = null, int $col = null): void |
|
60 | + public function error( string $message, string $file = null, int $line = null, int $col = null ): void |
|
61 | 61 | { |
62 | - $this->log('error', $message, $file, $line, $col); |
|
62 | + $this->log( 'error', $message, $file, $line, $col ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message |
69 | 69 | */ |
70 | - public function warning(string $message, string $file = null, int $line = null, int $col = null): void |
|
70 | + public function warning( string $message, string $file = null, int $line = null, int $col = null ): void |
|
71 | 71 | { |
72 | - $this->log('warning', $message, $file, $line, $col); |
|
72 | + $this->log( 'warning', $message, $file, $line, $col ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -77,23 +77,23 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-a-debug-message |
79 | 79 | */ |
80 | - public function debug(string $message, string $file = null, int $line = null, int $col = null): void |
|
80 | + public function debug( string $message, string $file = null, int $line = null, int $col = null ): void |
|
81 | 81 | { |
82 | - $this->log('debug', $message, $file, $line, $col); |
|
82 | + $this->log( 'debug', $message, $file, $line, $col ); |
|
83 | 83 | } |
84 | 84 | |
85 | - private function log(string $type, string $message, string $file = null, int $line = null, int $col = null): void |
|
85 | + private function log( string $type, string $message, string $file = null, int $line = null, int $col = null ): void |
|
86 | 86 | { |
87 | 87 | // Some values must be encoded. |
88 | - $message = strtr($message, self::ESCAPED_DATA); |
|
88 | + $message = strtr( $message, self::ESCAPED_DATA ); |
|
89 | 89 | |
90 | - if (!$file) { |
|
90 | + if ( ! $file ) { |
|
91 | 91 | // No file provided, output the message solely: |
92 | - $this->output->writeln(sprintf('::%s::%s', $type, $message)); |
|
92 | + $this->output->writeln( sprintf( '::%s::%s', $type, $message ) ); |
|
93 | 93 | |
94 | 94 | return; |
95 | 95 | } |
96 | 96 | |
97 | - $this->output->writeln(sprintf('::%s file=%s,line=%s,col=%s::%s', $type, strtr($file, self::ESCAPED_PROPERTIES), strtr($line ?? 1, self::ESCAPED_PROPERTIES), strtr($col ?? 0, self::ESCAPED_PROPERTIES), $message)); |
|
97 | + $this->output->writeln( sprintf( '::%s file=%s,line=%s,col=%s::%s', $type, strtr( $file, self::ESCAPED_PROPERTIES ), strtr( $line ?? 1, self::ESCAPED_PROPERTIES ), strtr( $col ?? 0, self::ESCAPED_PROPERTIES ), $message ) ); |
|
98 | 98 | } |
99 | 99 | } |
@@ -18,8 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @author Maxime Steinhausser <[email protected]> |
20 | 20 | */ |
21 | -class GithubActionReporter |
|
22 | -{ |
|
21 | +class GithubActionReporter { |
|
23 | 22 | private $output; |
24 | 23 | |
25 | 24 | /** |
@@ -42,8 +41,7 @@ discard block |
||
42 | 41 | ',' => '%2C', |
43 | 42 | ]; |
44 | 43 | |
45 | - public function __construct(OutputInterface $output) |
|
46 | - { |
|
44 | + public function __construct(OutputInterface $output) { |
|
47 | 45 | $this->output = $output; |
48 | 46 | } |
49 | 47 |
@@ -26,101 +26,101 @@ |
||
26 | 26 | */ |
27 | 27 | class ConsoleLogger extends AbstractLogger |
28 | 28 | { |
29 | - public const INFO = 'info'; |
|
30 | - public const ERROR = 'error'; |
|
29 | + public const INFO = 'info'; |
|
30 | + public const ERROR = 'error'; |
|
31 | 31 | |
32 | - private $output; |
|
33 | - private $verbosityLevelMap = [ |
|
34 | - LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, |
|
35 | - LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, |
|
36 | - LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL, |
|
37 | - LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL, |
|
38 | - LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL, |
|
39 | - LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE, |
|
40 | - LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE, |
|
41 | - LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG, |
|
42 | - ]; |
|
43 | - private $formatLevelMap = [ |
|
44 | - LogLevel::EMERGENCY => self::ERROR, |
|
45 | - LogLevel::ALERT => self::ERROR, |
|
46 | - LogLevel::CRITICAL => self::ERROR, |
|
47 | - LogLevel::ERROR => self::ERROR, |
|
48 | - LogLevel::WARNING => self::INFO, |
|
49 | - LogLevel::NOTICE => self::INFO, |
|
50 | - LogLevel::INFO => self::INFO, |
|
51 | - LogLevel::DEBUG => self::INFO, |
|
52 | - ]; |
|
53 | - private $errored = false; |
|
32 | + private $output; |
|
33 | + private $verbosityLevelMap = [ |
|
34 | + LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, |
|
35 | + LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, |
|
36 | + LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL, |
|
37 | + LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL, |
|
38 | + LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL, |
|
39 | + LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE, |
|
40 | + LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE, |
|
41 | + LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG, |
|
42 | + ]; |
|
43 | + private $formatLevelMap = [ |
|
44 | + LogLevel::EMERGENCY => self::ERROR, |
|
45 | + LogLevel::ALERT => self::ERROR, |
|
46 | + LogLevel::CRITICAL => self::ERROR, |
|
47 | + LogLevel::ERROR => self::ERROR, |
|
48 | + LogLevel::WARNING => self::INFO, |
|
49 | + LogLevel::NOTICE => self::INFO, |
|
50 | + LogLevel::INFO => self::INFO, |
|
51 | + LogLevel::DEBUG => self::INFO, |
|
52 | + ]; |
|
53 | + private $errored = false; |
|
54 | 54 | |
55 | - public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = []) |
|
56 | - { |
|
57 | - $this->output = $output; |
|
58 | - $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap; |
|
59 | - $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap; |
|
60 | - } |
|
55 | + public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = []) |
|
56 | + { |
|
57 | + $this->output = $output; |
|
58 | + $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap; |
|
59 | + $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * {@inheritdoc} |
|
64 | - * |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - public function log($level, $message, array $context = []) |
|
68 | - { |
|
69 | - if (!isset($this->verbosityLevelMap[$level])) { |
|
70 | - throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); |
|
71 | - } |
|
62 | + /** |
|
63 | + * {@inheritdoc} |
|
64 | + * |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + public function log($level, $message, array $context = []) |
|
68 | + { |
|
69 | + if (!isset($this->verbosityLevelMap[$level])) { |
|
70 | + throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); |
|
71 | + } |
|
72 | 72 | |
73 | - $output = $this->output; |
|
73 | + $output = $this->output; |
|
74 | 74 | |
75 | - // Write to the error output if necessary and available |
|
76 | - if (self::ERROR === $this->formatLevelMap[$level]) { |
|
77 | - if ($this->output instanceof ConsoleOutputInterface) { |
|
78 | - $output = $output->getErrorOutput(); |
|
79 | - } |
|
80 | - $this->errored = true; |
|
81 | - } |
|
75 | + // Write to the error output if necessary and available |
|
76 | + if (self::ERROR === $this->formatLevelMap[$level]) { |
|
77 | + if ($this->output instanceof ConsoleOutputInterface) { |
|
78 | + $output = $output->getErrorOutput(); |
|
79 | + } |
|
80 | + $this->errored = true; |
|
81 | + } |
|
82 | 82 | |
83 | - // the if condition check isn't necessary -- it's the same one that $output will do internally anyway. |
|
84 | - // We only do it for efficiency here as the message formatting is relatively expensive. |
|
85 | - if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) { |
|
86 | - $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)), $this->verbosityLevelMap[$level]); |
|
87 | - } |
|
88 | - } |
|
83 | + // the if condition check isn't necessary -- it's the same one that $output will do internally anyway. |
|
84 | + // We only do it for efficiency here as the message formatting is relatively expensive. |
|
85 | + if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) { |
|
86 | + $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)), $this->verbosityLevelMap[$level]); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Returns true when any messages have been logged at error levels. |
|
92 | - * |
|
93 | - * @return bool |
|
94 | - */ |
|
95 | - public function hasErrored() |
|
96 | - { |
|
97 | - return $this->errored; |
|
98 | - } |
|
90 | + /** |
|
91 | + * Returns true when any messages have been logged at error levels. |
|
92 | + * |
|
93 | + * @return bool |
|
94 | + */ |
|
95 | + public function hasErrored() |
|
96 | + { |
|
97 | + return $this->errored; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Interpolates context values into the message placeholders. |
|
102 | - * |
|
103 | - * @author PHP Framework Interoperability Group |
|
104 | - */ |
|
105 | - private function interpolate(string $message, array $context): string |
|
106 | - { |
|
107 | - if (!str_contains($message, '{')) { |
|
108 | - return $message; |
|
109 | - } |
|
100 | + /** |
|
101 | + * Interpolates context values into the message placeholders. |
|
102 | + * |
|
103 | + * @author PHP Framework Interoperability Group |
|
104 | + */ |
|
105 | + private function interpolate(string $message, array $context): string |
|
106 | + { |
|
107 | + if (!str_contains($message, '{')) { |
|
108 | + return $message; |
|
109 | + } |
|
110 | 110 | |
111 | - $replacements = []; |
|
112 | - foreach ($context as $key => $val) { |
|
113 | - if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) { |
|
114 | - $replacements["{{$key}}"] = $val; |
|
115 | - } elseif ($val instanceof \DateTimeInterface) { |
|
116 | - $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339); |
|
117 | - } elseif (\is_object($val)) { |
|
118 | - $replacements["{{$key}}"] = '[object '.\get_class($val).']'; |
|
119 | - } else { |
|
120 | - $replacements["{{$key}}"] = '['.\gettype($val).']'; |
|
121 | - } |
|
122 | - } |
|
111 | + $replacements = []; |
|
112 | + foreach ($context as $key => $val) { |
|
113 | + if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) { |
|
114 | + $replacements["{{$key}}"] = $val; |
|
115 | + } elseif ($val instanceof \DateTimeInterface) { |
|
116 | + $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339); |
|
117 | + } elseif (\is_object($val)) { |
|
118 | + $replacements["{{$key}}"] = '[object '.\get_class($val).']'; |
|
119 | + } else { |
|
120 | + $replacements["{{$key}}"] = '['.\gettype($val).']'; |
|
121 | + } |
|
122 | + } |
|
123 | 123 | |
124 | - return strtr($message, $replacements); |
|
125 | - } |
|
124 | + return strtr($message, $replacements); |
|
125 | + } |
|
126 | 126 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | ]; |
53 | 53 | private $errored = false; |
54 | 54 | |
55 | - public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = []) |
|
55 | + public function __construct( OutputInterface $output, array $verbosityLevelMap = [ ], array $formatLevelMap = [ ] ) |
|
56 | 56 | { |
57 | 57 | $this->output = $output; |
58 | 58 | $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap; |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return void |
66 | 66 | */ |
67 | - public function log($level, $message, array $context = []) |
|
67 | + public function log( $level, $message, array $context = [ ] ) |
|
68 | 68 | { |
69 | - if (!isset($this->verbosityLevelMap[$level])) { |
|
70 | - throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); |
|
69 | + if ( ! isset( $this->verbosityLevelMap[ $level ] ) ) { |
|
70 | + throw new InvalidArgumentException( sprintf( 'The log level "%s" does not exist.', $level ) ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | $output = $this->output; |
74 | 74 | |
75 | 75 | // Write to the error output if necessary and available |
76 | - if (self::ERROR === $this->formatLevelMap[$level]) { |
|
77 | - if ($this->output instanceof ConsoleOutputInterface) { |
|
76 | + if ( self::ERROR === $this->formatLevelMap[ $level ] ) { |
|
77 | + if ( $this->output instanceof ConsoleOutputInterface ) { |
|
78 | 78 | $output = $output->getErrorOutput(); |
79 | 79 | } |
80 | 80 | $this->errored = true; |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | |
83 | 83 | // the if condition check isn't necessary -- it's the same one that $output will do internally anyway. |
84 | 84 | // We only do it for efficiency here as the message formatting is relatively expensive. |
85 | - if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) { |
|
86 | - $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)), $this->verbosityLevelMap[$level]); |
|
85 | + if ( $output->getVerbosity() >= $this->verbosityLevelMap[ $level ] ) { |
|
86 | + $output->writeln( sprintf( '<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[ $level ], $level, $this->interpolate( $message, $context ) ), $this->verbosityLevelMap[ $level ] ); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
@@ -102,25 +102,25 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @author PHP Framework Interoperability Group |
104 | 104 | */ |
105 | - private function interpolate(string $message, array $context): string |
|
105 | + private function interpolate( string $message, array $context ): string |
|
106 | 106 | { |
107 | - if (!str_contains($message, '{')) { |
|
107 | + if ( ! str_contains( $message, '{' ) ) { |
|
108 | 108 | return $message; |
109 | 109 | } |
110 | 110 | |
111 | - $replacements = []; |
|
112 | - foreach ($context as $key => $val) { |
|
113 | - if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) { |
|
114 | - $replacements["{{$key}}"] = $val; |
|
115 | - } elseif ($val instanceof \DateTimeInterface) { |
|
116 | - $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339); |
|
117 | - } elseif (\is_object($val)) { |
|
118 | - $replacements["{{$key}}"] = '[object '.\get_class($val).']'; |
|
111 | + $replacements = [ ]; |
|
112 | + foreach ( $context as $key => $val ) { |
|
113 | + if ( null === $val || is_scalar( $val ) || ( \is_object( $val ) && method_exists( $val, '__toString' ) ) ) { |
|
114 | + $replacements[ "{{$key}}" ] = $val; |
|
115 | + } elseif ( $val instanceof \DateTimeInterface ) { |
|
116 | + $replacements[ "{{$key}}" ] = $val->format( \DateTime::RFC3339 ); |
|
117 | + } elseif ( \is_object( $val ) ) { |
|
118 | + $replacements[ "{{$key}}" ] = '[object ' . \get_class( $val ) . ']'; |
|
119 | 119 | } else { |
120 | - $replacements["{{$key}}"] = '['.\gettype($val).']'; |
|
120 | + $replacements[ "{{$key}}" ] = '[' . \gettype( $val ) . ']'; |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - return strtr($message, $replacements); |
|
124 | + return strtr( $message, $replacements ); |
|
125 | 125 | } |
126 | 126 | } |
@@ -24,8 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @see https://www.php-fig.org/psr/psr-3/ |
26 | 26 | */ |
27 | -class ConsoleLogger extends AbstractLogger |
|
28 | -{ |
|
27 | +class ConsoleLogger extends AbstractLogger { |
|
29 | 28 | public const INFO = 'info'; |
30 | 29 | public const ERROR = 'error'; |
31 | 30 | |
@@ -52,8 +51,7 @@ discard block |
||
52 | 51 | ]; |
53 | 52 | private $errored = false; |
54 | 53 | |
55 | - public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = []) |
|
56 | - { |
|
54 | + public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = []) { |
|
57 | 55 | $this->output = $output; |
58 | 56 | $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap; |
59 | 57 | $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap; |
@@ -64,8 +62,7 @@ discard block |
||
64 | 62 | * |
65 | 63 | * @return void |
66 | 64 | */ |
67 | - public function log($level, $message, array $context = []) |
|
68 | - { |
|
65 | + public function log($level, $message, array $context = []) { |
|
69 | 66 | if (!isset($this->verbosityLevelMap[$level])) { |
70 | 67 | throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); |
71 | 68 | } |
@@ -92,8 +89,7 @@ discard block |
||
92 | 89 | * |
93 | 90 | * @return bool |
94 | 91 | */ |
95 | - public function hasErrored() |
|
96 | - { |
|
92 | + public function hasErrored() { |
|
97 | 93 | return $this->errored; |
98 | 94 | } |
99 | 95 |
@@ -24,72 +24,72 @@ |
||
24 | 24 | */ |
25 | 25 | class ErrorListener implements EventSubscriberInterface |
26 | 26 | { |
27 | - private $logger; |
|
27 | + private $logger; |
|
28 | 28 | |
29 | - public function __construct(LoggerInterface $logger = null) |
|
30 | - { |
|
31 | - $this->logger = $logger; |
|
32 | - } |
|
29 | + public function __construct(LoggerInterface $logger = null) |
|
30 | + { |
|
31 | + $this->logger = $logger; |
|
32 | + } |
|
33 | 33 | |
34 | - public function onConsoleError(ConsoleErrorEvent $event) |
|
35 | - { |
|
36 | - if (null === $this->logger) { |
|
37 | - return; |
|
38 | - } |
|
34 | + public function onConsoleError(ConsoleErrorEvent $event) |
|
35 | + { |
|
36 | + if (null === $this->logger) { |
|
37 | + return; |
|
38 | + } |
|
39 | 39 | |
40 | - $error = $event->getError(); |
|
40 | + $error = $event->getError(); |
|
41 | 41 | |
42 | - if (!$inputString = $this->getInputString($event)) { |
|
43 | - $this->logger->critical('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]); |
|
42 | + if (!$inputString = $this->getInputString($event)) { |
|
43 | + $this->logger->critical('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]); |
|
44 | 44 | |
45 | - return; |
|
46 | - } |
|
45 | + return; |
|
46 | + } |
|
47 | 47 | |
48 | - $this->logger->critical('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]); |
|
49 | - } |
|
48 | + $this->logger->critical('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]); |
|
49 | + } |
|
50 | 50 | |
51 | - public function onConsoleTerminate(ConsoleTerminateEvent $event) |
|
52 | - { |
|
53 | - if (null === $this->logger) { |
|
54 | - return; |
|
55 | - } |
|
51 | + public function onConsoleTerminate(ConsoleTerminateEvent $event) |
|
52 | + { |
|
53 | + if (null === $this->logger) { |
|
54 | + return; |
|
55 | + } |
|
56 | 56 | |
57 | - $exitCode = $event->getExitCode(); |
|
57 | + $exitCode = $event->getExitCode(); |
|
58 | 58 | |
59 | - if (0 === $exitCode) { |
|
60 | - return; |
|
61 | - } |
|
59 | + if (0 === $exitCode) { |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - if (!$inputString = $this->getInputString($event)) { |
|
64 | - $this->logger->debug('The console exited with code "{code}"', ['code' => $exitCode]); |
|
63 | + if (!$inputString = $this->getInputString($event)) { |
|
64 | + $this->logger->debug('The console exited with code "{code}"', ['code' => $exitCode]); |
|
65 | 65 | |
66 | - return; |
|
67 | - } |
|
66 | + return; |
|
67 | + } |
|
68 | 68 | |
69 | - $this->logger->debug('Command "{command}" exited with code "{code}"', ['command' => $inputString, 'code' => $exitCode]); |
|
70 | - } |
|
69 | + $this->logger->debug('Command "{command}" exited with code "{code}"', ['command' => $inputString, 'code' => $exitCode]); |
|
70 | + } |
|
71 | 71 | |
72 | - public static function getSubscribedEvents() |
|
73 | - { |
|
74 | - return [ |
|
75 | - ConsoleEvents::ERROR => ['onConsoleError', -128], |
|
76 | - ConsoleEvents::TERMINATE => ['onConsoleTerminate', -128], |
|
77 | - ]; |
|
78 | - } |
|
72 | + public static function getSubscribedEvents() |
|
73 | + { |
|
74 | + return [ |
|
75 | + ConsoleEvents::ERROR => ['onConsoleError', -128], |
|
76 | + ConsoleEvents::TERMINATE => ['onConsoleTerminate', -128], |
|
77 | + ]; |
|
78 | + } |
|
79 | 79 | |
80 | - private static function getInputString(ConsoleEvent $event): ?string |
|
81 | - { |
|
82 | - $commandName = $event->getCommand() ? $event->getCommand()->getName() : null; |
|
83 | - $input = $event->getInput(); |
|
80 | + private static function getInputString(ConsoleEvent $event): ?string |
|
81 | + { |
|
82 | + $commandName = $event->getCommand() ? $event->getCommand()->getName() : null; |
|
83 | + $input = $event->getInput(); |
|
84 | 84 | |
85 | - if (method_exists($input, '__toString')) { |
|
86 | - if ($commandName) { |
|
87 | - return str_replace(["'$commandName'", "\"$commandName\""], $commandName, (string) $input); |
|
88 | - } |
|
85 | + if (method_exists($input, '__toString')) { |
|
86 | + if ($commandName) { |
|
87 | + return str_replace(["'$commandName'", "\"$commandName\""], $commandName, (string) $input); |
|
88 | + } |
|
89 | 89 | |
90 | - return (string) $input; |
|
91 | - } |
|
90 | + return (string) $input; |
|
91 | + } |
|
92 | 92 | |
93 | - return $commandName; |
|
94 | - } |
|
93 | + return $commandName; |
|
94 | + } |
|
95 | 95 | } |
@@ -26,68 +26,68 @@ |
||
26 | 26 | { |
27 | 27 | private $logger; |
28 | 28 | |
29 | - public function __construct(LoggerInterface $logger = null) |
|
29 | + public function __construct( LoggerInterface $logger = null ) |
|
30 | 30 | { |
31 | 31 | $this->logger = $logger; |
32 | 32 | } |
33 | 33 | |
34 | - public function onConsoleError(ConsoleErrorEvent $event) |
|
34 | + public function onConsoleError( ConsoleErrorEvent $event ) |
|
35 | 35 | { |
36 | - if (null === $this->logger) { |
|
36 | + if ( null === $this->logger ) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | 39 | |
40 | 40 | $error = $event->getError(); |
41 | 41 | |
42 | - if (!$inputString = $this->getInputString($event)) { |
|
43 | - $this->logger->critical('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]); |
|
42 | + if ( ! $inputString = $this->getInputString( $event ) ) { |
|
43 | + $this->logger->critical( 'An error occurred while using the console. Message: "{message}"', [ 'exception' => $error, 'message' => $error->getMessage() ] ); |
|
44 | 44 | |
45 | 45 | return; |
46 | 46 | } |
47 | 47 | |
48 | - $this->logger->critical('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]); |
|
48 | + $this->logger->critical( 'Error thrown while running command "{command}". Message: "{message}"', [ 'exception' => $error, 'command' => $inputString, 'message' => $error->getMessage() ] ); |
|
49 | 49 | } |
50 | 50 | |
51 | - public function onConsoleTerminate(ConsoleTerminateEvent $event) |
|
51 | + public function onConsoleTerminate( ConsoleTerminateEvent $event ) |
|
52 | 52 | { |
53 | - if (null === $this->logger) { |
|
53 | + if ( null === $this->logger ) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $exitCode = $event->getExitCode(); |
58 | 58 | |
59 | - if (0 === $exitCode) { |
|
59 | + if ( 0 === $exitCode ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | - if (!$inputString = $this->getInputString($event)) { |
|
64 | - $this->logger->debug('The console exited with code "{code}"', ['code' => $exitCode]); |
|
63 | + if ( ! $inputString = $this->getInputString( $event ) ) { |
|
64 | + $this->logger->debug( 'The console exited with code "{code}"', [ 'code' => $exitCode ] ); |
|
65 | 65 | |
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | - $this->logger->debug('Command "{command}" exited with code "{code}"', ['command' => $inputString, 'code' => $exitCode]); |
|
69 | + $this->logger->debug( 'Command "{command}" exited with code "{code}"', [ 'command' => $inputString, 'code' => $exitCode ] ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | public static function getSubscribedEvents() |
73 | 73 | { |
74 | 74 | return [ |
75 | - ConsoleEvents::ERROR => ['onConsoleError', -128], |
|
76 | - ConsoleEvents::TERMINATE => ['onConsoleTerminate', -128], |
|
75 | + ConsoleEvents::ERROR => [ 'onConsoleError', -128 ], |
|
76 | + ConsoleEvents::TERMINATE => [ 'onConsoleTerminate', -128 ], |
|
77 | 77 | ]; |
78 | 78 | } |
79 | 79 | |
80 | - private static function getInputString(ConsoleEvent $event): ?string |
|
80 | + private static function getInputString( ConsoleEvent $event ): ?string |
|
81 | 81 | { |
82 | 82 | $commandName = $event->getCommand() ? $event->getCommand()->getName() : null; |
83 | 83 | $input = $event->getInput(); |
84 | 84 | |
85 | - if (method_exists($input, '__toString')) { |
|
86 | - if ($commandName) { |
|
87 | - return str_replace(["'$commandName'", "\"$commandName\""], $commandName, (string) $input); |
|
85 | + if ( method_exists( $input, '__toString' ) ) { |
|
86 | + if ( $commandName ) { |
|
87 | + return str_replace( [ "'$commandName'", "\"$commandName\"" ], $commandName, (string)$input ); |
|
88 | 88 | } |
89 | 89 | |
90 | - return (string) $input; |
|
90 | + return (string)$input; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return $commandName; |
@@ -22,17 +22,14 @@ discard block |
||
22 | 22 | * @author James Halsall <[email protected]> |
23 | 23 | * @author Robin Chalas <[email protected]> |
24 | 24 | */ |
25 | -class ErrorListener implements EventSubscriberInterface |
|
26 | -{ |
|
25 | +class ErrorListener implements EventSubscriberInterface { |
|
27 | 26 | private $logger; |
28 | 27 | |
29 | - public function __construct(LoggerInterface $logger = null) |
|
30 | - { |
|
28 | + public function __construct(LoggerInterface $logger = null) { |
|
31 | 29 | $this->logger = $logger; |
32 | 30 | } |
33 | 31 | |
34 | - public function onConsoleError(ConsoleErrorEvent $event) |
|
35 | - { |
|
32 | + public function onConsoleError(ConsoleErrorEvent $event) { |
|
36 | 33 | if (null === $this->logger) { |
37 | 34 | return; |
38 | 35 | } |
@@ -48,8 +45,7 @@ discard block |
||
48 | 45 | $this->logger->critical('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]); |
49 | 46 | } |
50 | 47 | |
51 | - public function onConsoleTerminate(ConsoleTerminateEvent $event) |
|
52 | - { |
|
48 | + public function onConsoleTerminate(ConsoleTerminateEvent $event) { |
|
53 | 49 | if (null === $this->logger) { |
54 | 50 | return; |
55 | 51 | } |
@@ -69,8 +65,7 @@ discard block |
||
69 | 65 | $this->logger->debug('Command "{command}" exited with code "{code}"', ['command' => $inputString, 'code' => $exitCode]); |
70 | 66 | } |
71 | 67 | |
72 | - public static function getSubscribedEvents() |
|
73 | - { |
|
68 | + public static function getSubscribedEvents() { |
|
74 | 69 | return [ |
75 | 70 | ConsoleEvents::ERROR => ['onConsoleError', -128], |
76 | 71 | ConsoleEvents::TERMINATE => ['onConsoleTerminate', -128], |
@@ -20,164 +20,164 @@ |
||
20 | 20 | */ |
21 | 21 | class ChoiceQuestion extends Question |
22 | 22 | { |
23 | - private $choices; |
|
24 | - private $multiselect = false; |
|
25 | - private $prompt = ' > '; |
|
26 | - private $errorMessage = 'Value "%s" is invalid'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @param string $question The question to ask to the user |
|
30 | - * @param array $choices The list of available choices |
|
31 | - * @param mixed $default The default answer to return |
|
32 | - */ |
|
33 | - public function __construct(string $question, array $choices, $default = null) |
|
34 | - { |
|
35 | - if (!$choices) { |
|
36 | - throw new \LogicException('Choice question must have at least 1 choice available.'); |
|
37 | - } |
|
38 | - |
|
39 | - parent::__construct($question, $default); |
|
40 | - |
|
41 | - $this->choices = $choices; |
|
42 | - $this->setValidator($this->getDefaultValidator()); |
|
43 | - $this->setAutocompleterValues($choices); |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Returns available choices. |
|
48 | - * |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - public function getChoices() |
|
52 | - { |
|
53 | - return $this->choices; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Sets multiselect option. |
|
58 | - * |
|
59 | - * When multiselect is set to true, multiple choices can be answered. |
|
60 | - * |
|
61 | - * @return $this |
|
62 | - */ |
|
63 | - public function setMultiselect(bool $multiselect) |
|
64 | - { |
|
65 | - $this->multiselect = $multiselect; |
|
66 | - $this->setValidator($this->getDefaultValidator()); |
|
67 | - |
|
68 | - return $this; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Returns whether the choices are multiselect. |
|
73 | - * |
|
74 | - * @return bool |
|
75 | - */ |
|
76 | - public function isMultiselect() |
|
77 | - { |
|
78 | - return $this->multiselect; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Gets the prompt for choices. |
|
83 | - * |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function getPrompt() |
|
87 | - { |
|
88 | - return $this->prompt; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Sets the prompt for choices. |
|
93 | - * |
|
94 | - * @return $this |
|
95 | - */ |
|
96 | - public function setPrompt(string $prompt) |
|
97 | - { |
|
98 | - $this->prompt = $prompt; |
|
99 | - |
|
100 | - return $this; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Sets the error message for invalid values. |
|
105 | - * |
|
106 | - * The error message has a string placeholder (%s) for the invalid value. |
|
107 | - * |
|
108 | - * @return $this |
|
109 | - */ |
|
110 | - public function setErrorMessage(string $errorMessage) |
|
111 | - { |
|
112 | - $this->errorMessage = $errorMessage; |
|
113 | - $this->setValidator($this->getDefaultValidator()); |
|
114 | - |
|
115 | - return $this; |
|
116 | - } |
|
117 | - |
|
118 | - private function getDefaultValidator(): callable |
|
119 | - { |
|
120 | - $choices = $this->choices; |
|
121 | - $errorMessage = $this->errorMessage; |
|
122 | - $multiselect = $this->multiselect; |
|
123 | - $isAssoc = $this->isAssoc($choices); |
|
124 | - |
|
125 | - return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) { |
|
126 | - if ($multiselect) { |
|
127 | - // Check for a separated comma values |
|
128 | - if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selected, $matches)) { |
|
129 | - throw new InvalidArgumentException(sprintf($errorMessage, $selected)); |
|
130 | - } |
|
131 | - |
|
132 | - $selectedChoices = explode(',', $selected); |
|
133 | - } else { |
|
134 | - $selectedChoices = [$selected]; |
|
135 | - } |
|
136 | - |
|
137 | - if ($this->isTrimmable()) { |
|
138 | - foreach ($selectedChoices as $k => $v) { |
|
139 | - $selectedChoices[$k] = trim($v); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - $multiselectChoices = []; |
|
144 | - foreach ($selectedChoices as $value) { |
|
145 | - $results = []; |
|
146 | - foreach ($choices as $key => $choice) { |
|
147 | - if ($choice === $value) { |
|
148 | - $results[] = $key; |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - if (\count($results) > 1) { |
|
153 | - throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of "%s".', implode('" or "', $results))); |
|
154 | - } |
|
155 | - |
|
156 | - $result = array_search($value, $choices); |
|
157 | - |
|
158 | - if (!$isAssoc) { |
|
159 | - if (false !== $result) { |
|
160 | - $result = $choices[$result]; |
|
161 | - } elseif (isset($choices[$value])) { |
|
162 | - $result = $choices[$value]; |
|
163 | - } |
|
164 | - } elseif (false === $result && isset($choices[$value])) { |
|
165 | - $result = $value; |
|
166 | - } |
|
167 | - |
|
168 | - if (false === $result) { |
|
169 | - throw new InvalidArgumentException(sprintf($errorMessage, $value)); |
|
170 | - } |
|
171 | - |
|
172 | - // For associative choices, consistently return the key as string: |
|
173 | - $multiselectChoices[] = $isAssoc ? (string) $result : $result; |
|
174 | - } |
|
175 | - |
|
176 | - if ($multiselect) { |
|
177 | - return $multiselectChoices; |
|
178 | - } |
|
179 | - |
|
180 | - return current($multiselectChoices); |
|
181 | - }; |
|
182 | - } |
|
23 | + private $choices; |
|
24 | + private $multiselect = false; |
|
25 | + private $prompt = ' > '; |
|
26 | + private $errorMessage = 'Value "%s" is invalid'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @param string $question The question to ask to the user |
|
30 | + * @param array $choices The list of available choices |
|
31 | + * @param mixed $default The default answer to return |
|
32 | + */ |
|
33 | + public function __construct(string $question, array $choices, $default = null) |
|
34 | + { |
|
35 | + if (!$choices) { |
|
36 | + throw new \LogicException('Choice question must have at least 1 choice available.'); |
|
37 | + } |
|
38 | + |
|
39 | + parent::__construct($question, $default); |
|
40 | + |
|
41 | + $this->choices = $choices; |
|
42 | + $this->setValidator($this->getDefaultValidator()); |
|
43 | + $this->setAutocompleterValues($choices); |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Returns available choices. |
|
48 | + * |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + public function getChoices() |
|
52 | + { |
|
53 | + return $this->choices; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Sets multiselect option. |
|
58 | + * |
|
59 | + * When multiselect is set to true, multiple choices can be answered. |
|
60 | + * |
|
61 | + * @return $this |
|
62 | + */ |
|
63 | + public function setMultiselect(bool $multiselect) |
|
64 | + { |
|
65 | + $this->multiselect = $multiselect; |
|
66 | + $this->setValidator($this->getDefaultValidator()); |
|
67 | + |
|
68 | + return $this; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Returns whether the choices are multiselect. |
|
73 | + * |
|
74 | + * @return bool |
|
75 | + */ |
|
76 | + public function isMultiselect() |
|
77 | + { |
|
78 | + return $this->multiselect; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Gets the prompt for choices. |
|
83 | + * |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function getPrompt() |
|
87 | + { |
|
88 | + return $this->prompt; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Sets the prompt for choices. |
|
93 | + * |
|
94 | + * @return $this |
|
95 | + */ |
|
96 | + public function setPrompt(string $prompt) |
|
97 | + { |
|
98 | + $this->prompt = $prompt; |
|
99 | + |
|
100 | + return $this; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Sets the error message for invalid values. |
|
105 | + * |
|
106 | + * The error message has a string placeholder (%s) for the invalid value. |
|
107 | + * |
|
108 | + * @return $this |
|
109 | + */ |
|
110 | + public function setErrorMessage(string $errorMessage) |
|
111 | + { |
|
112 | + $this->errorMessage = $errorMessage; |
|
113 | + $this->setValidator($this->getDefaultValidator()); |
|
114 | + |
|
115 | + return $this; |
|
116 | + } |
|
117 | + |
|
118 | + private function getDefaultValidator(): callable |
|
119 | + { |
|
120 | + $choices = $this->choices; |
|
121 | + $errorMessage = $this->errorMessage; |
|
122 | + $multiselect = $this->multiselect; |
|
123 | + $isAssoc = $this->isAssoc($choices); |
|
124 | + |
|
125 | + return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) { |
|
126 | + if ($multiselect) { |
|
127 | + // Check for a separated comma values |
|
128 | + if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selected, $matches)) { |
|
129 | + throw new InvalidArgumentException(sprintf($errorMessage, $selected)); |
|
130 | + } |
|
131 | + |
|
132 | + $selectedChoices = explode(',', $selected); |
|
133 | + } else { |
|
134 | + $selectedChoices = [$selected]; |
|
135 | + } |
|
136 | + |
|
137 | + if ($this->isTrimmable()) { |
|
138 | + foreach ($selectedChoices as $k => $v) { |
|
139 | + $selectedChoices[$k] = trim($v); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + $multiselectChoices = []; |
|
144 | + foreach ($selectedChoices as $value) { |
|
145 | + $results = []; |
|
146 | + foreach ($choices as $key => $choice) { |
|
147 | + if ($choice === $value) { |
|
148 | + $results[] = $key; |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + if (\count($results) > 1) { |
|
153 | + throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of "%s".', implode('" or "', $results))); |
|
154 | + } |
|
155 | + |
|
156 | + $result = array_search($value, $choices); |
|
157 | + |
|
158 | + if (!$isAssoc) { |
|
159 | + if (false !== $result) { |
|
160 | + $result = $choices[$result]; |
|
161 | + } elseif (isset($choices[$value])) { |
|
162 | + $result = $choices[$value]; |
|
163 | + } |
|
164 | + } elseif (false === $result && isset($choices[$value])) { |
|
165 | + $result = $value; |
|
166 | + } |
|
167 | + |
|
168 | + if (false === $result) { |
|
169 | + throw new InvalidArgumentException(sprintf($errorMessage, $value)); |
|
170 | + } |
|
171 | + |
|
172 | + // For associative choices, consistently return the key as string: |
|
173 | + $multiselectChoices[] = $isAssoc ? (string) $result : $result; |
|
174 | + } |
|
175 | + |
|
176 | + if ($multiselect) { |
|
177 | + return $multiselectChoices; |
|
178 | + } |
|
179 | + |
|
180 | + return current($multiselectChoices); |
|
181 | + }; |
|
182 | + } |
|
183 | 183 | } |
@@ -30,17 +30,17 @@ discard block |
||
30 | 30 | * @param array $choices The list of available choices |
31 | 31 | * @param mixed $default The default answer to return |
32 | 32 | */ |
33 | - public function __construct(string $question, array $choices, $default = null) |
|
33 | + public function __construct( string $question, array $choices, $default = null ) |
|
34 | 34 | { |
35 | - if (!$choices) { |
|
36 | - throw new \LogicException('Choice question must have at least 1 choice available.'); |
|
35 | + if ( ! $choices ) { |
|
36 | + throw new \LogicException( 'Choice question must have at least 1 choice available.' ); |
|
37 | 37 | } |
38 | 38 | |
39 | - parent::__construct($question, $default); |
|
39 | + parent::__construct( $question, $default ); |
|
40 | 40 | |
41 | 41 | $this->choices = $choices; |
42 | - $this->setValidator($this->getDefaultValidator()); |
|
43 | - $this->setAutocompleterValues($choices); |
|
42 | + $this->setValidator( $this->getDefaultValidator() ); |
|
43 | + $this->setAutocompleterValues( $choices ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return $this |
62 | 62 | */ |
63 | - public function setMultiselect(bool $multiselect) |
|
63 | + public function setMultiselect( bool $multiselect ) |
|
64 | 64 | { |
65 | 65 | $this->multiselect = $multiselect; |
66 | - $this->setValidator($this->getDefaultValidator()); |
|
66 | + $this->setValidator( $this->getDefaultValidator() ); |
|
67 | 67 | |
68 | 68 | return $this; |
69 | 69 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return $this |
95 | 95 | */ |
96 | - public function setPrompt(string $prompt) |
|
96 | + public function setPrompt( string $prompt ) |
|
97 | 97 | { |
98 | 98 | $this->prompt = $prompt; |
99 | 99 | |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return $this |
109 | 109 | */ |
110 | - public function setErrorMessage(string $errorMessage) |
|
110 | + public function setErrorMessage( string $errorMessage ) |
|
111 | 111 | { |
112 | 112 | $this->errorMessage = $errorMessage; |
113 | - $this->setValidator($this->getDefaultValidator()); |
|
113 | + $this->setValidator( $this->getDefaultValidator() ); |
|
114 | 114 | |
115 | 115 | return $this; |
116 | 116 | } |
@@ -120,64 +120,64 @@ discard block |
||
120 | 120 | $choices = $this->choices; |
121 | 121 | $errorMessage = $this->errorMessage; |
122 | 122 | $multiselect = $this->multiselect; |
123 | - $isAssoc = $this->isAssoc($choices); |
|
123 | + $isAssoc = $this->isAssoc( $choices ); |
|
124 | 124 | |
125 | - return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) { |
|
126 | - if ($multiselect) { |
|
125 | + return function( $selected ) use ( $choices, $errorMessage, $multiselect, $isAssoc ) { |
|
126 | + if ( $multiselect ) { |
|
127 | 127 | // Check for a separated comma values |
128 | - if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selected, $matches)) { |
|
129 | - throw new InvalidArgumentException(sprintf($errorMessage, $selected)); |
|
128 | + if ( ! preg_match( '/^[^,]+(?:,[^,]+)*$/', $selected, $matches ) ) { |
|
129 | + throw new InvalidArgumentException( sprintf( $errorMessage, $selected ) ); |
|
130 | 130 | } |
131 | 131 | |
132 | - $selectedChoices = explode(',', $selected); |
|
132 | + $selectedChoices = explode( ',', $selected ); |
|
133 | 133 | } else { |
134 | - $selectedChoices = [$selected]; |
|
134 | + $selectedChoices = [ $selected ]; |
|
135 | 135 | } |
136 | 136 | |
137 | - if ($this->isTrimmable()) { |
|
138 | - foreach ($selectedChoices as $k => $v) { |
|
139 | - $selectedChoices[$k] = trim($v); |
|
137 | + if ( $this->isTrimmable() ) { |
|
138 | + foreach ( $selectedChoices as $k => $v ) { |
|
139 | + $selectedChoices[ $k ] = trim( $v ); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - $multiselectChoices = []; |
|
144 | - foreach ($selectedChoices as $value) { |
|
145 | - $results = []; |
|
146 | - foreach ($choices as $key => $choice) { |
|
147 | - if ($choice === $value) { |
|
148 | - $results[] = $key; |
|
143 | + $multiselectChoices = [ ]; |
|
144 | + foreach ( $selectedChoices as $value ) { |
|
145 | + $results = [ ]; |
|
146 | + foreach ( $choices as $key => $choice ) { |
|
147 | + if ( $choice === $value ) { |
|
148 | + $results[ ] = $key; |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | - if (\count($results) > 1) { |
|
153 | - throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of "%s".', implode('" or "', $results))); |
|
152 | + if ( \count( $results ) > 1 ) { |
|
153 | + throw new InvalidArgumentException( sprintf( 'The provided answer is ambiguous. Value should be one of "%s".', implode( '" or "', $results ) ) ); |
|
154 | 154 | } |
155 | 155 | |
156 | - $result = array_search($value, $choices); |
|
156 | + $result = array_search( $value, $choices ); |
|
157 | 157 | |
158 | - if (!$isAssoc) { |
|
159 | - if (false !== $result) { |
|
160 | - $result = $choices[$result]; |
|
161 | - } elseif (isset($choices[$value])) { |
|
162 | - $result = $choices[$value]; |
|
158 | + if ( ! $isAssoc ) { |
|
159 | + if ( false !== $result ) { |
|
160 | + $result = $choices[ $result ]; |
|
161 | + } elseif ( isset( $choices[ $value ] ) ) { |
|
162 | + $result = $choices[ $value ]; |
|
163 | 163 | } |
164 | - } elseif (false === $result && isset($choices[$value])) { |
|
164 | + } elseif ( false === $result && isset( $choices[ $value ] ) ) { |
|
165 | 165 | $result = $value; |
166 | 166 | } |
167 | 167 | |
168 | - if (false === $result) { |
|
169 | - throw new InvalidArgumentException(sprintf($errorMessage, $value)); |
|
168 | + if ( false === $result ) { |
|
169 | + throw new InvalidArgumentException( sprintf( $errorMessage, $value ) ); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // For associative choices, consistently return the key as string: |
173 | - $multiselectChoices[] = $isAssoc ? (string) $result : $result; |
|
173 | + $multiselectChoices[ ] = $isAssoc ? (string)$result : $result; |
|
174 | 174 | } |
175 | 175 | |
176 | - if ($multiselect) { |
|
176 | + if ( $multiselect ) { |
|
177 | 177 | return $multiselectChoices; |
178 | 178 | } |
179 | 179 | |
180 | - return current($multiselectChoices); |
|
180 | + return current( $multiselectChoices ); |
|
181 | 181 | }; |
182 | 182 | } |
183 | 183 | } |
@@ -18,8 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @author Fabien Potencier <[email protected]> |
20 | 20 | */ |
21 | -class ChoiceQuestion extends Question |
|
22 | -{ |
|
21 | +class ChoiceQuestion extends Question { |
|
23 | 22 | private $choices; |
24 | 23 | private $multiselect = false; |
25 | 24 | private $prompt = ' > '; |
@@ -30,8 +29,7 @@ discard block |
||
30 | 29 | * @param array $choices The list of available choices |
31 | 30 | * @param mixed $default The default answer to return |
32 | 31 | */ |
33 | - public function __construct(string $question, array $choices, $default = null) |
|
34 | - { |
|
32 | + public function __construct(string $question, array $choices, $default = null) { |
|
35 | 33 | if (!$choices) { |
36 | 34 | throw new \LogicException('Choice question must have at least 1 choice available.'); |
37 | 35 | } |
@@ -48,8 +46,7 @@ discard block |
||
48 | 46 | * |
49 | 47 | * @return array |
50 | 48 | */ |
51 | - public function getChoices() |
|
52 | - { |
|
49 | + public function getChoices() { |
|
53 | 50 | return $this->choices; |
54 | 51 | } |
55 | 52 | |
@@ -60,8 +57,7 @@ discard block |
||
60 | 57 | * |
61 | 58 | * @return $this |
62 | 59 | */ |
63 | - public function setMultiselect(bool $multiselect) |
|
64 | - { |
|
60 | + public function setMultiselect(bool $multiselect) { |
|
65 | 61 | $this->multiselect = $multiselect; |
66 | 62 | $this->setValidator($this->getDefaultValidator()); |
67 | 63 | |
@@ -73,8 +69,7 @@ discard block |
||
73 | 69 | * |
74 | 70 | * @return bool |
75 | 71 | */ |
76 | - public function isMultiselect() |
|
77 | - { |
|
72 | + public function isMultiselect() { |
|
78 | 73 | return $this->multiselect; |
79 | 74 | } |
80 | 75 | |
@@ -83,8 +78,7 @@ discard block |
||
83 | 78 | * |
84 | 79 | * @return string |
85 | 80 | */ |
86 | - public function getPrompt() |
|
87 | - { |
|
81 | + public function getPrompt() { |
|
88 | 82 | return $this->prompt; |
89 | 83 | } |
90 | 84 | |
@@ -93,8 +87,7 @@ discard block |
||
93 | 87 | * |
94 | 88 | * @return $this |
95 | 89 | */ |
96 | - public function setPrompt(string $prompt) |
|
97 | - { |
|
90 | + public function setPrompt(string $prompt) { |
|
98 | 91 | $this->prompt = $prompt; |
99 | 92 | |
100 | 93 | return $this; |
@@ -107,8 +100,7 @@ discard block |
||
107 | 100 | * |
108 | 101 | * @return $this |
109 | 102 | */ |
110 | - public function setErrorMessage(string $errorMessage) |
|
111 | - { |
|
103 | + public function setErrorMessage(string $errorMessage) { |
|
112 | 104 | $this->errorMessage = $errorMessage; |
113 | 105 | $this->setValidator($this->getDefaultValidator()); |
114 | 106 |
@@ -21,282 +21,282 @@ |
||
21 | 21 | */ |
22 | 22 | class Question |
23 | 23 | { |
24 | - private $question; |
|
25 | - private $attempts; |
|
26 | - private $hidden = false; |
|
27 | - private $hiddenFallback = true; |
|
28 | - private $autocompleterCallback; |
|
29 | - private $validator; |
|
30 | - private $default; |
|
31 | - private $normalizer; |
|
32 | - private $trimmable = true; |
|
33 | - private $multiline = false; |
|
34 | - |
|
35 | - /** |
|
36 | - * @param string $question The question to ask to the user |
|
37 | - * @param string|bool|int|float|null $default The default answer to return if the user enters nothing |
|
38 | - */ |
|
39 | - public function __construct(string $question, $default = null) |
|
40 | - { |
|
41 | - $this->question = $question; |
|
42 | - $this->default = $default; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Returns the question. |
|
47 | - * |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getQuestion() |
|
51 | - { |
|
52 | - return $this->question; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Returns the default answer. |
|
57 | - * |
|
58 | - * @return string|bool|int|float|null |
|
59 | - */ |
|
60 | - public function getDefault() |
|
61 | - { |
|
62 | - return $this->default; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Returns whether the user response accepts newline characters. |
|
67 | - */ |
|
68 | - public function isMultiline(): bool |
|
69 | - { |
|
70 | - return $this->multiline; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Sets whether the user response should accept newline characters. |
|
75 | - * |
|
76 | - * @return $this |
|
77 | - */ |
|
78 | - public function setMultiline(bool $multiline): self |
|
79 | - { |
|
80 | - $this->multiline = $multiline; |
|
81 | - |
|
82 | - return $this; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Returns whether the user response must be hidden. |
|
87 | - * |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public function isHidden() |
|
91 | - { |
|
92 | - return $this->hidden; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Sets whether the user response must be hidden or not. |
|
97 | - * |
|
98 | - * @return $this |
|
99 | - * |
|
100 | - * @throws LogicException In case the autocompleter is also used |
|
101 | - */ |
|
102 | - public function setHidden(bool $hidden) |
|
103 | - { |
|
104 | - if ($this->autocompleterCallback) { |
|
105 | - throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
106 | - } |
|
107 | - |
|
108 | - $this->hidden = (bool) $hidden; |
|
109 | - |
|
110 | - return $this; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * In case the response can not be hidden, whether to fallback on non-hidden question or not. |
|
115 | - * |
|
116 | - * @return bool |
|
117 | - */ |
|
118 | - public function isHiddenFallback() |
|
119 | - { |
|
120 | - return $this->hiddenFallback; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Sets whether to fallback on non-hidden question if the response can not be hidden. |
|
125 | - * |
|
126 | - * @return $this |
|
127 | - */ |
|
128 | - public function setHiddenFallback(bool $fallback) |
|
129 | - { |
|
130 | - $this->hiddenFallback = (bool) $fallback; |
|
131 | - |
|
132 | - return $this; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Gets values for the autocompleter. |
|
137 | - * |
|
138 | - * @return iterable|null |
|
139 | - */ |
|
140 | - public function getAutocompleterValues() |
|
141 | - { |
|
142 | - $callback = $this->getAutocompleterCallback(); |
|
143 | - |
|
144 | - return $callback ? $callback('') : null; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Sets values for the autocompleter. |
|
149 | - * |
|
150 | - * @return $this |
|
151 | - * |
|
152 | - * @throws LogicException |
|
153 | - */ |
|
154 | - public function setAutocompleterValues(?iterable $values) |
|
155 | - { |
|
156 | - if (\is_array($values)) { |
|
157 | - $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values); |
|
158 | - |
|
159 | - $callback = static function () use ($values) { |
|
160 | - return $values; |
|
161 | - }; |
|
162 | - } elseif ($values instanceof \Traversable) { |
|
163 | - $valueCache = null; |
|
164 | - $callback = static function () use ($values, &$valueCache) { |
|
165 | - return $valueCache ?? $valueCache = iterator_to_array($values, false); |
|
166 | - }; |
|
167 | - } else { |
|
168 | - $callback = null; |
|
169 | - } |
|
170 | - |
|
171 | - return $this->setAutocompleterCallback($callback); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Gets the callback function used for the autocompleter. |
|
176 | - */ |
|
177 | - public function getAutocompleterCallback(): ?callable |
|
178 | - { |
|
179 | - return $this->autocompleterCallback; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Sets the callback function used for the autocompleter. |
|
184 | - * |
|
185 | - * The callback is passed the user input as argument and should return an iterable of corresponding suggestions. |
|
186 | - * |
|
187 | - * @return $this |
|
188 | - */ |
|
189 | - public function setAutocompleterCallback(callable $callback = null): self |
|
190 | - { |
|
191 | - if ($this->hidden && null !== $callback) { |
|
192 | - throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
193 | - } |
|
194 | - |
|
195 | - $this->autocompleterCallback = $callback; |
|
196 | - |
|
197 | - return $this; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Sets a validator for the question. |
|
202 | - * |
|
203 | - * @return $this |
|
204 | - */ |
|
205 | - public function setValidator(callable $validator = null) |
|
206 | - { |
|
207 | - $this->validator = $validator; |
|
208 | - |
|
209 | - return $this; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Gets the validator for the question. |
|
214 | - * |
|
215 | - * @return callable|null |
|
216 | - */ |
|
217 | - public function getValidator() |
|
218 | - { |
|
219 | - return $this->validator; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Sets the maximum number of attempts. |
|
224 | - * |
|
225 | - * Null means an unlimited number of attempts. |
|
226 | - * |
|
227 | - * @return $this |
|
228 | - * |
|
229 | - * @throws InvalidArgumentException in case the number of attempts is invalid |
|
230 | - */ |
|
231 | - public function setMaxAttempts(?int $attempts) |
|
232 | - { |
|
233 | - if (null !== $attempts) { |
|
234 | - $attempts = (int) $attempts; |
|
235 | - if ($attempts < 1) { |
|
236 | - throw new InvalidArgumentException('Maximum number of attempts must be a positive value.'); |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - $this->attempts = $attempts; |
|
241 | - |
|
242 | - return $this; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Gets the maximum number of attempts. |
|
247 | - * |
|
248 | - * Null means an unlimited number of attempts. |
|
249 | - * |
|
250 | - * @return int|null |
|
251 | - */ |
|
252 | - public function getMaxAttempts() |
|
253 | - { |
|
254 | - return $this->attempts; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Sets a normalizer for the response. |
|
259 | - * |
|
260 | - * The normalizer can be a callable (a string), a closure or a class implementing __invoke. |
|
261 | - * |
|
262 | - * @return $this |
|
263 | - */ |
|
264 | - public function setNormalizer(callable $normalizer) |
|
265 | - { |
|
266 | - $this->normalizer = $normalizer; |
|
267 | - |
|
268 | - return $this; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Gets the normalizer for the response. |
|
273 | - * |
|
274 | - * The normalizer can ba a callable (a string), a closure or a class implementing __invoke. |
|
275 | - * |
|
276 | - * @return callable|null |
|
277 | - */ |
|
278 | - public function getNormalizer() |
|
279 | - { |
|
280 | - return $this->normalizer; |
|
281 | - } |
|
282 | - |
|
283 | - protected function isAssoc(array $array) |
|
284 | - { |
|
285 | - return (bool) \count(array_filter(array_keys($array), 'is_string')); |
|
286 | - } |
|
287 | - |
|
288 | - public function isTrimmable(): bool |
|
289 | - { |
|
290 | - return $this->trimmable; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * @return $this |
|
295 | - */ |
|
296 | - public function setTrimmable(bool $trimmable): self |
|
297 | - { |
|
298 | - $this->trimmable = $trimmable; |
|
299 | - |
|
300 | - return $this; |
|
301 | - } |
|
24 | + private $question; |
|
25 | + private $attempts; |
|
26 | + private $hidden = false; |
|
27 | + private $hiddenFallback = true; |
|
28 | + private $autocompleterCallback; |
|
29 | + private $validator; |
|
30 | + private $default; |
|
31 | + private $normalizer; |
|
32 | + private $trimmable = true; |
|
33 | + private $multiline = false; |
|
34 | + |
|
35 | + /** |
|
36 | + * @param string $question The question to ask to the user |
|
37 | + * @param string|bool|int|float|null $default The default answer to return if the user enters nothing |
|
38 | + */ |
|
39 | + public function __construct(string $question, $default = null) |
|
40 | + { |
|
41 | + $this->question = $question; |
|
42 | + $this->default = $default; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Returns the question. |
|
47 | + * |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getQuestion() |
|
51 | + { |
|
52 | + return $this->question; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Returns the default answer. |
|
57 | + * |
|
58 | + * @return string|bool|int|float|null |
|
59 | + */ |
|
60 | + public function getDefault() |
|
61 | + { |
|
62 | + return $this->default; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Returns whether the user response accepts newline characters. |
|
67 | + */ |
|
68 | + public function isMultiline(): bool |
|
69 | + { |
|
70 | + return $this->multiline; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Sets whether the user response should accept newline characters. |
|
75 | + * |
|
76 | + * @return $this |
|
77 | + */ |
|
78 | + public function setMultiline(bool $multiline): self |
|
79 | + { |
|
80 | + $this->multiline = $multiline; |
|
81 | + |
|
82 | + return $this; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Returns whether the user response must be hidden. |
|
87 | + * |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public function isHidden() |
|
91 | + { |
|
92 | + return $this->hidden; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Sets whether the user response must be hidden or not. |
|
97 | + * |
|
98 | + * @return $this |
|
99 | + * |
|
100 | + * @throws LogicException In case the autocompleter is also used |
|
101 | + */ |
|
102 | + public function setHidden(bool $hidden) |
|
103 | + { |
|
104 | + if ($this->autocompleterCallback) { |
|
105 | + throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
106 | + } |
|
107 | + |
|
108 | + $this->hidden = (bool) $hidden; |
|
109 | + |
|
110 | + return $this; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * In case the response can not be hidden, whether to fallback on non-hidden question or not. |
|
115 | + * |
|
116 | + * @return bool |
|
117 | + */ |
|
118 | + public function isHiddenFallback() |
|
119 | + { |
|
120 | + return $this->hiddenFallback; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Sets whether to fallback on non-hidden question if the response can not be hidden. |
|
125 | + * |
|
126 | + * @return $this |
|
127 | + */ |
|
128 | + public function setHiddenFallback(bool $fallback) |
|
129 | + { |
|
130 | + $this->hiddenFallback = (bool) $fallback; |
|
131 | + |
|
132 | + return $this; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Gets values for the autocompleter. |
|
137 | + * |
|
138 | + * @return iterable|null |
|
139 | + */ |
|
140 | + public function getAutocompleterValues() |
|
141 | + { |
|
142 | + $callback = $this->getAutocompleterCallback(); |
|
143 | + |
|
144 | + return $callback ? $callback('') : null; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Sets values for the autocompleter. |
|
149 | + * |
|
150 | + * @return $this |
|
151 | + * |
|
152 | + * @throws LogicException |
|
153 | + */ |
|
154 | + public function setAutocompleterValues(?iterable $values) |
|
155 | + { |
|
156 | + if (\is_array($values)) { |
|
157 | + $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values); |
|
158 | + |
|
159 | + $callback = static function () use ($values) { |
|
160 | + return $values; |
|
161 | + }; |
|
162 | + } elseif ($values instanceof \Traversable) { |
|
163 | + $valueCache = null; |
|
164 | + $callback = static function () use ($values, &$valueCache) { |
|
165 | + return $valueCache ?? $valueCache = iterator_to_array($values, false); |
|
166 | + }; |
|
167 | + } else { |
|
168 | + $callback = null; |
|
169 | + } |
|
170 | + |
|
171 | + return $this->setAutocompleterCallback($callback); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Gets the callback function used for the autocompleter. |
|
176 | + */ |
|
177 | + public function getAutocompleterCallback(): ?callable |
|
178 | + { |
|
179 | + return $this->autocompleterCallback; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Sets the callback function used for the autocompleter. |
|
184 | + * |
|
185 | + * The callback is passed the user input as argument and should return an iterable of corresponding suggestions. |
|
186 | + * |
|
187 | + * @return $this |
|
188 | + */ |
|
189 | + public function setAutocompleterCallback(callable $callback = null): self |
|
190 | + { |
|
191 | + if ($this->hidden && null !== $callback) { |
|
192 | + throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
193 | + } |
|
194 | + |
|
195 | + $this->autocompleterCallback = $callback; |
|
196 | + |
|
197 | + return $this; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Sets a validator for the question. |
|
202 | + * |
|
203 | + * @return $this |
|
204 | + */ |
|
205 | + public function setValidator(callable $validator = null) |
|
206 | + { |
|
207 | + $this->validator = $validator; |
|
208 | + |
|
209 | + return $this; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Gets the validator for the question. |
|
214 | + * |
|
215 | + * @return callable|null |
|
216 | + */ |
|
217 | + public function getValidator() |
|
218 | + { |
|
219 | + return $this->validator; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Sets the maximum number of attempts. |
|
224 | + * |
|
225 | + * Null means an unlimited number of attempts. |
|
226 | + * |
|
227 | + * @return $this |
|
228 | + * |
|
229 | + * @throws InvalidArgumentException in case the number of attempts is invalid |
|
230 | + */ |
|
231 | + public function setMaxAttempts(?int $attempts) |
|
232 | + { |
|
233 | + if (null !== $attempts) { |
|
234 | + $attempts = (int) $attempts; |
|
235 | + if ($attempts < 1) { |
|
236 | + throw new InvalidArgumentException('Maximum number of attempts must be a positive value.'); |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + $this->attempts = $attempts; |
|
241 | + |
|
242 | + return $this; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Gets the maximum number of attempts. |
|
247 | + * |
|
248 | + * Null means an unlimited number of attempts. |
|
249 | + * |
|
250 | + * @return int|null |
|
251 | + */ |
|
252 | + public function getMaxAttempts() |
|
253 | + { |
|
254 | + return $this->attempts; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Sets a normalizer for the response. |
|
259 | + * |
|
260 | + * The normalizer can be a callable (a string), a closure or a class implementing __invoke. |
|
261 | + * |
|
262 | + * @return $this |
|
263 | + */ |
|
264 | + public function setNormalizer(callable $normalizer) |
|
265 | + { |
|
266 | + $this->normalizer = $normalizer; |
|
267 | + |
|
268 | + return $this; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Gets the normalizer for the response. |
|
273 | + * |
|
274 | + * The normalizer can ba a callable (a string), a closure or a class implementing __invoke. |
|
275 | + * |
|
276 | + * @return callable|null |
|
277 | + */ |
|
278 | + public function getNormalizer() |
|
279 | + { |
|
280 | + return $this->normalizer; |
|
281 | + } |
|
282 | + |
|
283 | + protected function isAssoc(array $array) |
|
284 | + { |
|
285 | + return (bool) \count(array_filter(array_keys($array), 'is_string')); |
|
286 | + } |
|
287 | + |
|
288 | + public function isTrimmable(): bool |
|
289 | + { |
|
290 | + return $this->trimmable; |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * @return $this |
|
295 | + */ |
|
296 | + public function setTrimmable(bool $trimmable): self |
|
297 | + { |
|
298 | + $this->trimmable = $trimmable; |
|
299 | + |
|
300 | + return $this; |
|
301 | + } |
|
302 | 302 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param string $question The question to ask to the user |
37 | 37 | * @param string|bool|int|float|null $default The default answer to return if the user enters nothing |
38 | 38 | */ |
39 | - public function __construct(string $question, $default = null) |
|
39 | + public function __construct( string $question, $default = null ) |
|
40 | 40 | { |
41 | 41 | $this->question = $question; |
42 | 42 | $this->default = $default; |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return $this |
77 | 77 | */ |
78 | - public function setMultiline(bool $multiline): self |
|
78 | + public function setMultiline( bool $multiline ): self |
|
79 | 79 | { |
80 | 80 | $this->multiline = $multiline; |
81 | 81 | |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @throws LogicException In case the autocompleter is also used |
101 | 101 | */ |
102 | - public function setHidden(bool $hidden) |
|
102 | + public function setHidden( bool $hidden ) |
|
103 | 103 | { |
104 | - if ($this->autocompleterCallback) { |
|
105 | - throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
104 | + if ( $this->autocompleterCallback ) { |
|
105 | + throw new LogicException( 'A hidden question cannot use the autocompleter.' ); |
|
106 | 106 | } |
107 | 107 | |
108 | - $this->hidden = (bool) $hidden; |
|
108 | + $this->hidden = (bool)$hidden; |
|
109 | 109 | |
110 | 110 | return $this; |
111 | 111 | } |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return $this |
127 | 127 | */ |
128 | - public function setHiddenFallback(bool $fallback) |
|
128 | + public function setHiddenFallback( bool $fallback ) |
|
129 | 129 | { |
130 | - $this->hiddenFallback = (bool) $fallback; |
|
130 | + $this->hiddenFallback = (bool)$fallback; |
|
131 | 131 | |
132 | 132 | return $this; |
133 | 133 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | { |
142 | 142 | $callback = $this->getAutocompleterCallback(); |
143 | 143 | |
144 | - return $callback ? $callback('') : null; |
|
144 | + return $callback ? $callback( '' ) : null; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -151,24 +151,24 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @throws LogicException |
153 | 153 | */ |
154 | - public function setAutocompleterValues(?iterable $values) |
|
154 | + public function setAutocompleterValues( ?iterable $values ) |
|
155 | 155 | { |
156 | - if (\is_array($values)) { |
|
157 | - $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values); |
|
156 | + if ( \is_array( $values ) ) { |
|
157 | + $values = $this->isAssoc( $values ) ? array_merge( array_keys( $values ), array_values( $values ) ) : array_values( $values ); |
|
158 | 158 | |
159 | - $callback = static function () use ($values) { |
|
159 | + $callback = static function() use ( $values ) { |
|
160 | 160 | return $values; |
161 | 161 | }; |
162 | - } elseif ($values instanceof \Traversable) { |
|
162 | + } elseif ( $values instanceof \Traversable ) { |
|
163 | 163 | $valueCache = null; |
164 | - $callback = static function () use ($values, &$valueCache) { |
|
165 | - return $valueCache ?? $valueCache = iterator_to_array($values, false); |
|
164 | + $callback = static function() use ( $values, &$valueCache ) { |
|
165 | + return $valueCache ?? $valueCache = iterator_to_array( $values, false ); |
|
166 | 166 | }; |
167 | 167 | } else { |
168 | 168 | $callback = null; |
169 | 169 | } |
170 | 170 | |
171 | - return $this->setAutocompleterCallback($callback); |
|
171 | + return $this->setAutocompleterCallback( $callback ); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -186,10 +186,10 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @return $this |
188 | 188 | */ |
189 | - public function setAutocompleterCallback(callable $callback = null): self |
|
189 | + public function setAutocompleterCallback( callable $callback = null ): self |
|
190 | 190 | { |
191 | - if ($this->hidden && null !== $callback) { |
|
192 | - throw new LogicException('A hidden question cannot use the autocompleter.'); |
|
191 | + if ( $this->hidden && null !== $callback ) { |
|
192 | + throw new LogicException( 'A hidden question cannot use the autocompleter.' ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | $this->autocompleterCallback = $callback; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @return $this |
204 | 204 | */ |
205 | - public function setValidator(callable $validator = null) |
|
205 | + public function setValidator( callable $validator = null ) |
|
206 | 206 | { |
207 | 207 | $this->validator = $validator; |
208 | 208 | |
@@ -228,12 +228,12 @@ discard block |
||
228 | 228 | * |
229 | 229 | * @throws InvalidArgumentException in case the number of attempts is invalid |
230 | 230 | */ |
231 | - public function setMaxAttempts(?int $attempts) |
|
231 | + public function setMaxAttempts( ?int $attempts ) |
|
232 | 232 | { |
233 | - if (null !== $attempts) { |
|
234 | - $attempts = (int) $attempts; |
|
235 | - if ($attempts < 1) { |
|
236 | - throw new InvalidArgumentException('Maximum number of attempts must be a positive value.'); |
|
233 | + if ( null !== $attempts ) { |
|
234 | + $attempts = (int)$attempts; |
|
235 | + if ( $attempts < 1 ) { |
|
236 | + throw new InvalidArgumentException( 'Maximum number of attempts must be a positive value.' ); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @return $this |
263 | 263 | */ |
264 | - public function setNormalizer(callable $normalizer) |
|
264 | + public function setNormalizer( callable $normalizer ) |
|
265 | 265 | { |
266 | 266 | $this->normalizer = $normalizer; |
267 | 267 | |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | return $this->normalizer; |
281 | 281 | } |
282 | 282 | |
283 | - protected function isAssoc(array $array) |
|
283 | + protected function isAssoc( array $array ) |
|
284 | 284 | { |
285 | - return (bool) \count(array_filter(array_keys($array), 'is_string')); |
|
285 | + return (bool)\count( array_filter( array_keys( $array ), 'is_string' ) ); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | public function isTrimmable(): bool |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | /** |
294 | 294 | * @return $this |
295 | 295 | */ |
296 | - public function setTrimmable(bool $trimmable): self |
|
296 | + public function setTrimmable( bool $trimmable ): self |
|
297 | 297 | { |
298 | 298 | $this->trimmable = $trimmable; |
299 | 299 |
@@ -19,8 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @author Fabien Potencier <[email protected]> |
21 | 21 | */ |
22 | -class Question |
|
23 | -{ |
|
22 | +class Question { |
|
24 | 23 | private $question; |
25 | 24 | private $attempts; |
26 | 25 | private $hidden = false; |
@@ -36,8 +35,7 @@ discard block |
||
36 | 35 | * @param string $question The question to ask to the user |
37 | 36 | * @param string|bool|int|float|null $default The default answer to return if the user enters nothing |
38 | 37 | */ |
39 | - public function __construct(string $question, $default = null) |
|
40 | - { |
|
38 | + public function __construct(string $question, $default = null) { |
|
41 | 39 | $this->question = $question; |
42 | 40 | $this->default = $default; |
43 | 41 | } |
@@ -47,8 +45,7 @@ discard block |
||
47 | 45 | * |
48 | 46 | * @return string |
49 | 47 | */ |
50 | - public function getQuestion() |
|
51 | - { |
|
48 | + public function getQuestion() { |
|
52 | 49 | return $this->question; |
53 | 50 | } |
54 | 51 | |
@@ -57,8 +54,7 @@ discard block |
||
57 | 54 | * |
58 | 55 | * @return string|bool|int|float|null |
59 | 56 | */ |
60 | - public function getDefault() |
|
61 | - { |
|
57 | + public function getDefault() { |
|
62 | 58 | return $this->default; |
63 | 59 | } |
64 | 60 | |
@@ -87,8 +83,7 @@ discard block |
||
87 | 83 | * |
88 | 84 | * @return bool |
89 | 85 | */ |
90 | - public function isHidden() |
|
91 | - { |
|
86 | + public function isHidden() { |
|
92 | 87 | return $this->hidden; |
93 | 88 | } |
94 | 89 | |
@@ -99,8 +94,7 @@ discard block |
||
99 | 94 | * |
100 | 95 | * @throws LogicException In case the autocompleter is also used |
101 | 96 | */ |
102 | - public function setHidden(bool $hidden) |
|
103 | - { |
|
97 | + public function setHidden(bool $hidden) { |
|
104 | 98 | if ($this->autocompleterCallback) { |
105 | 99 | throw new LogicException('A hidden question cannot use the autocompleter.'); |
106 | 100 | } |
@@ -115,8 +109,7 @@ discard block |
||
115 | 109 | * |
116 | 110 | * @return bool |
117 | 111 | */ |
118 | - public function isHiddenFallback() |
|
119 | - { |
|
112 | + public function isHiddenFallback() { |
|
120 | 113 | return $this->hiddenFallback; |
121 | 114 | } |
122 | 115 | |
@@ -125,8 +118,7 @@ discard block |
||
125 | 118 | * |
126 | 119 | * @return $this |
127 | 120 | */ |
128 | - public function setHiddenFallback(bool $fallback) |
|
129 | - { |
|
121 | + public function setHiddenFallback(bool $fallback) { |
|
130 | 122 | $this->hiddenFallback = (bool) $fallback; |
131 | 123 | |
132 | 124 | return $this; |
@@ -137,8 +129,7 @@ discard block |
||
137 | 129 | * |
138 | 130 | * @return iterable|null |
139 | 131 | */ |
140 | - public function getAutocompleterValues() |
|
141 | - { |
|
132 | + public function getAutocompleterValues() { |
|
142 | 133 | $callback = $this->getAutocompleterCallback(); |
143 | 134 | |
144 | 135 | return $callback ? $callback('') : null; |
@@ -151,8 +142,7 @@ discard block |
||
151 | 142 | * |
152 | 143 | * @throws LogicException |
153 | 144 | */ |
154 | - public function setAutocompleterValues(?iterable $values) |
|
155 | - { |
|
145 | + public function setAutocompleterValues(?iterable $values) { |
|
156 | 146 | if (\is_array($values)) { |
157 | 147 | $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values); |
158 | 148 | |
@@ -202,8 +192,7 @@ discard block |
||
202 | 192 | * |
203 | 193 | * @return $this |
204 | 194 | */ |
205 | - public function setValidator(callable $validator = null) |
|
206 | - { |
|
195 | + public function setValidator(callable $validator = null) { |
|
207 | 196 | $this->validator = $validator; |
208 | 197 | |
209 | 198 | return $this; |
@@ -214,8 +203,7 @@ discard block |
||
214 | 203 | * |
215 | 204 | * @return callable|null |
216 | 205 | */ |
217 | - public function getValidator() |
|
218 | - { |
|
206 | + public function getValidator() { |
|
219 | 207 | return $this->validator; |
220 | 208 | } |
221 | 209 | |
@@ -228,8 +216,7 @@ discard block |
||
228 | 216 | * |
229 | 217 | * @throws InvalidArgumentException in case the number of attempts is invalid |
230 | 218 | */ |
231 | - public function setMaxAttempts(?int $attempts) |
|
232 | - { |
|
219 | + public function setMaxAttempts(?int $attempts) { |
|
233 | 220 | if (null !== $attempts) { |
234 | 221 | $attempts = (int) $attempts; |
235 | 222 | if ($attempts < 1) { |
@@ -249,8 +236,7 @@ discard block |
||
249 | 236 | * |
250 | 237 | * @return int|null |
251 | 238 | */ |
252 | - public function getMaxAttempts() |
|
253 | - { |
|
239 | + public function getMaxAttempts() { |
|
254 | 240 | return $this->attempts; |
255 | 241 | } |
256 | 242 | |
@@ -261,8 +247,7 @@ discard block |
||
261 | 247 | * |
262 | 248 | * @return $this |
263 | 249 | */ |
264 | - public function setNormalizer(callable $normalizer) |
|
265 | - { |
|
250 | + public function setNormalizer(callable $normalizer) { |
|
266 | 251 | $this->normalizer = $normalizer; |
267 | 252 | |
268 | 253 | return $this; |
@@ -275,13 +260,11 @@ discard block |
||
275 | 260 | * |
276 | 261 | * @return callable|null |
277 | 262 | */ |
278 | - public function getNormalizer() |
|
279 | - { |
|
263 | + public function getNormalizer() { |
|
280 | 264 | return $this->normalizer; |
281 | 265 | } |
282 | 266 | |
283 | - protected function isAssoc(array $array) |
|
284 | - { |
|
267 | + protected function isAssoc(array $array) { |
|
285 | 268 | return (bool) \count(array_filter(array_keys($array), 'is_string')); |
286 | 269 | } |
287 | 270 |
@@ -18,40 +18,40 @@ |
||
18 | 18 | */ |
19 | 19 | class ConfirmationQuestion extends Question |
20 | 20 | { |
21 | - private $trueAnswerRegex; |
|
22 | - |
|
23 | - /** |
|
24 | - * @param string $question The question to ask to the user |
|
25 | - * @param bool $default The default answer to return, true or false |
|
26 | - * @param string $trueAnswerRegex A regex to match the "yes" answer |
|
27 | - */ |
|
28 | - public function __construct(string $question, bool $default = true, string $trueAnswerRegex = '/^y/i') |
|
29 | - { |
|
30 | - parent::__construct($question, $default); |
|
31 | - |
|
32 | - $this->trueAnswerRegex = $trueAnswerRegex; |
|
33 | - $this->setNormalizer($this->getDefaultNormalizer()); |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Returns the default answer normalizer. |
|
38 | - */ |
|
39 | - private function getDefaultNormalizer(): callable |
|
40 | - { |
|
41 | - $default = $this->getDefault(); |
|
42 | - $regex = $this->trueAnswerRegex; |
|
43 | - |
|
44 | - return function ($answer) use ($default, $regex) { |
|
45 | - if (\is_bool($answer)) { |
|
46 | - return $answer; |
|
47 | - } |
|
48 | - |
|
49 | - $answerIsTrue = (bool) preg_match($regex, $answer); |
|
50 | - if (false === $default) { |
|
51 | - return $answer && $answerIsTrue; |
|
52 | - } |
|
53 | - |
|
54 | - return '' === $answer || $answerIsTrue; |
|
55 | - }; |
|
56 | - } |
|
21 | + private $trueAnswerRegex; |
|
22 | + |
|
23 | + /** |
|
24 | + * @param string $question The question to ask to the user |
|
25 | + * @param bool $default The default answer to return, true or false |
|
26 | + * @param string $trueAnswerRegex A regex to match the "yes" answer |
|
27 | + */ |
|
28 | + public function __construct(string $question, bool $default = true, string $trueAnswerRegex = '/^y/i') |
|
29 | + { |
|
30 | + parent::__construct($question, $default); |
|
31 | + |
|
32 | + $this->trueAnswerRegex = $trueAnswerRegex; |
|
33 | + $this->setNormalizer($this->getDefaultNormalizer()); |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Returns the default answer normalizer. |
|
38 | + */ |
|
39 | + private function getDefaultNormalizer(): callable |
|
40 | + { |
|
41 | + $default = $this->getDefault(); |
|
42 | + $regex = $this->trueAnswerRegex; |
|
43 | + |
|
44 | + return function ($answer) use ($default, $regex) { |
|
45 | + if (\is_bool($answer)) { |
|
46 | + return $answer; |
|
47 | + } |
|
48 | + |
|
49 | + $answerIsTrue = (bool) preg_match($regex, $answer); |
|
50 | + if (false === $default) { |
|
51 | + return $answer && $answerIsTrue; |
|
52 | + } |
|
53 | + |
|
54 | + return '' === $answer || $answerIsTrue; |
|
55 | + }; |
|
56 | + } |
|
57 | 57 | } |
@@ -25,12 +25,12 @@ discard block |
||
25 | 25 | * @param bool $default The default answer to return, true or false |
26 | 26 | * @param string $trueAnswerRegex A regex to match the "yes" answer |
27 | 27 | */ |
28 | - public function __construct(string $question, bool $default = true, string $trueAnswerRegex = '/^y/i') |
|
28 | + public function __construct( string $question, bool $default = true, string $trueAnswerRegex = '/^y/i' ) |
|
29 | 29 | { |
30 | - parent::__construct($question, $default); |
|
30 | + parent::__construct( $question, $default ); |
|
31 | 31 | |
32 | 32 | $this->trueAnswerRegex = $trueAnswerRegex; |
33 | - $this->setNormalizer($this->getDefaultNormalizer()); |
|
33 | + $this->setNormalizer( $this->getDefaultNormalizer() ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | $default = $this->getDefault(); |
42 | 42 | $regex = $this->trueAnswerRegex; |
43 | 43 | |
44 | - return function ($answer) use ($default, $regex) { |
|
45 | - if (\is_bool($answer)) { |
|
44 | + return function( $answer ) use ( $default, $regex ) { |
|
45 | + if ( \is_bool( $answer ) ) { |
|
46 | 46 | return $answer; |
47 | 47 | } |
48 | 48 | |
49 | - $answerIsTrue = (bool) preg_match($regex, $answer); |
|
50 | - if (false === $default) { |
|
49 | + $answerIsTrue = (bool)preg_match( $regex, $answer ); |
|
50 | + if ( false === $default ) { |
|
51 | 51 | return $answer && $answerIsTrue; |
52 | 52 | } |
53 | 53 |
@@ -16,8 +16,7 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @author Fabien Potencier <[email protected]> |
18 | 18 | */ |
19 | -class ConfirmationQuestion extends Question |
|
20 | -{ |
|
19 | +class ConfirmationQuestion extends Question { |
|
21 | 20 | private $trueAnswerRegex; |
22 | 21 | |
23 | 22 | /** |
@@ -25,8 +24,7 @@ discard block |
||
25 | 24 | * @param bool $default The default answer to return, true or false |
26 | 25 | * @param string $trueAnswerRegex A regex to match the "yes" answer |
27 | 26 | */ |
28 | - public function __construct(string $question, bool $default = true, string $trueAnswerRegex = '/^y/i') |
|
29 | - { |
|
27 | + public function __construct(string $question, bool $default = true, string $trueAnswerRegex = '/^y/i') { |
|
30 | 28 | parent::__construct($question, $default); |
31 | 29 | |
32 | 30 | $this->trueAnswerRegex = $trueAnswerRegex; |