@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Sets the decorated flag. |
23 | 23 | */ |
24 | - public function setDecorated(bool $decorated); |
|
24 | + public function setDecorated( bool $decorated ); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Gets the decorated flag. |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * Sets a new style. |
35 | 35 | */ |
36 | - public function setStyle(string $name, OutputFormatterStyleInterface $style); |
|
36 | + public function setStyle( string $name, OutputFormatterStyleInterface $style ); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Checks if output formatter has style with specified name. |
40 | 40 | * |
41 | 41 | * @return bool |
42 | 42 | */ |
43 | - public function hasStyle(string $name); |
|
43 | + public function hasStyle( string $name ); |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Gets style options from style with specified name. |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @throws \InvalidArgumentException When style isn't defined |
51 | 51 | */ |
52 | - public function getStyle(string $name); |
|
52 | + public function getStyle( string $name ); |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Formats a message according to the given styles. |
56 | 56 | */ |
57 | - public function format(?string $message); |
|
57 | + public function format( ?string $message ); |
|
58 | 58 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | private $emptyStyle; |
28 | 28 | |
29 | - public function __construct(OutputFormatterStyleInterface $emptyStyle = null) |
|
29 | + public function __construct( OutputFormatterStyleInterface $emptyStyle = null ) |
|
30 | 30 | { |
31 | 31 | $this->emptyStyle = $emptyStyle ?? new OutputFormatterStyle(); |
32 | 32 | $this->reset(); |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function reset() |
39 | 39 | { |
40 | - $this->styles = []; |
|
40 | + $this->styles = [ ]; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Pushes a style in the stack. |
45 | 45 | */ |
46 | - public function push(OutputFormatterStyleInterface $style) |
|
46 | + public function push( OutputFormatterStyleInterface $style ) |
|
47 | 47 | { |
48 | - $this->styles[] = $style; |
|
48 | + $this->styles[ ] = $style; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -55,25 +55,25 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @throws InvalidArgumentException When style tags incorrectly nested |
57 | 57 | */ |
58 | - public function pop(OutputFormatterStyleInterface $style = null) |
|
58 | + public function pop( OutputFormatterStyleInterface $style = null ) |
|
59 | 59 | { |
60 | - if (empty($this->styles)) { |
|
60 | + if ( empty( $this->styles ) ) { |
|
61 | 61 | return $this->emptyStyle; |
62 | 62 | } |
63 | 63 | |
64 | - if (null === $style) { |
|
65 | - return array_pop($this->styles); |
|
64 | + if ( null === $style ) { |
|
65 | + return array_pop( $this->styles ); |
|
66 | 66 | } |
67 | 67 | |
68 | - foreach (array_reverse($this->styles, true) as $index => $stackedStyle) { |
|
69 | - if ($style->apply('') === $stackedStyle->apply('')) { |
|
70 | - $this->styles = \array_slice($this->styles, 0, $index); |
|
68 | + foreach ( array_reverse( $this->styles, true ) as $index => $stackedStyle ) { |
|
69 | + if ( $style->apply( '' ) === $stackedStyle->apply( '' ) ) { |
|
70 | + $this->styles = \array_slice( $this->styles, 0, $index ); |
|
71 | 71 | |
72 | 72 | return $stackedStyle; |
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | - throw new InvalidArgumentException('Incorrectly nested style tag found.'); |
|
76 | + throw new InvalidArgumentException( 'Incorrectly nested style tag found.' ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -83,17 +83,17 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function getCurrent() |
85 | 85 | { |
86 | - if (empty($this->styles)) { |
|
86 | + if ( empty( $this->styles ) ) { |
|
87 | 87 | return $this->emptyStyle; |
88 | 88 | } |
89 | 89 | |
90 | - return $this->styles[\count($this->styles) - 1]; |
|
90 | + return $this->styles[ \count( $this->styles ) - 1 ]; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | 94 | * @return $this |
95 | 95 | */ |
96 | - public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) |
|
96 | + public function setEmptyStyle( OutputFormatterStyleInterface $emptyStyle ) |
|
97 | 97 | { |
98 | 98 | $this->emptyStyle = $emptyStyle; |
99 | 99 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * {@inheritdoc} |
20 | 20 | */ |
21 | - public function apply(string $text): string |
|
21 | + public function apply( string $text ): string |
|
22 | 22 | { |
23 | 23 | return $text; |
24 | 24 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * {@inheritdoc} |
28 | 28 | */ |
29 | - public function setBackground(string $color = null): void |
|
29 | + public function setBackground( string $color = null ): void |
|
30 | 30 | { |
31 | 31 | // do nothing |
32 | 32 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * {@inheritdoc} |
36 | 36 | */ |
37 | - public function setForeground(string $color = null): void |
|
37 | + public function setForeground( string $color = null ): void |
|
38 | 38 | { |
39 | 39 | // do nothing |
40 | 40 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * {@inheritdoc} |
44 | 44 | */ |
45 | - public function setOption(string $option): void |
|
45 | + public function setOption( string $option ): void |
|
46 | 46 | { |
47 | 47 | // do nothing |
48 | 48 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * {@inheritdoc} |
52 | 52 | */ |
53 | - public function setOptions(array $options): void |
|
53 | + public function setOptions( array $options ): void |
|
54 | 54 | { |
55 | 55 | // do nothing |
56 | 56 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * {@inheritdoc} |
60 | 60 | */ |
61 | - public function unsetOption(string $option): void |
|
61 | + public function unsetOption( string $option ): void |
|
62 | 62 | { |
63 | 63 | // do nothing |
64 | 64 | } |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | class OutputFormatter implements WrappableOutputFormatterInterface |
23 | 23 | { |
24 | 24 | private $decorated; |
25 | - private $styles = []; |
|
25 | + private $styles = [ ]; |
|
26 | 26 | private $styleStack; |
27 | 27 | |
28 | 28 | public function __clone() |
29 | 29 | { |
30 | 30 | $this->styleStack = clone $this->styleStack; |
31 | - foreach ($this->styles as $key => $value) { |
|
32 | - $this->styles[$key] = clone $value; |
|
31 | + foreach ( $this->styles as $key => $value ) { |
|
32 | + $this->styles[ $key ] = clone $value; |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return string Escaped text |
40 | 40 | */ |
41 | - public static function escape(string $text) |
|
41 | + public static function escape( string $text ) |
|
42 | 42 | { |
43 | - $text = preg_replace('/([^\\\\]?)</', '$1\\<', $text); |
|
43 | + $text = preg_replace( '/([^\\\\]?)</', '$1\\<', $text ); |
|
44 | 44 | |
45 | - return self::escapeTrailingBackslash($text); |
|
45 | + return self::escapeTrailingBackslash( $text ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @internal |
52 | 52 | */ |
53 | - public static function escapeTrailingBackslash(string $text): string |
|
53 | + public static function escapeTrailingBackslash( string $text ): string |
|
54 | 54 | { |
55 | - if (str_ends_with($text, '\\')) { |
|
56 | - $len = \strlen($text); |
|
57 | - $text = rtrim($text, '\\'); |
|
58 | - $text = str_replace("\0", '', $text); |
|
59 | - $text .= str_repeat("\0", $len - \strlen($text)); |
|
55 | + if ( str_ends_with( $text, '\\' ) ) { |
|
56 | + $len = \strlen( $text ); |
|
57 | + $text = rtrim( $text, '\\' ); |
|
58 | + $text = str_replace( "\0", '', $text ); |
|
59 | + $text .= str_repeat( "\0", $len - \strlen( $text ) ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | return $text; |
@@ -67,17 +67,17 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param OutputFormatterStyleInterface[] $styles Array of "name => FormatterStyle" instances |
69 | 69 | */ |
70 | - public function __construct(bool $decorated = false, array $styles = []) |
|
70 | + public function __construct( bool $decorated = false, array $styles = [ ] ) |
|
71 | 71 | { |
72 | 72 | $this->decorated = $decorated; |
73 | 73 | |
74 | - $this->setStyle('error', new OutputFormatterStyle('white', 'red')); |
|
75 | - $this->setStyle('info', new OutputFormatterStyle('green')); |
|
76 | - $this->setStyle('comment', new OutputFormatterStyle('yellow')); |
|
77 | - $this->setStyle('question', new OutputFormatterStyle('black', 'cyan')); |
|
74 | + $this->setStyle( 'error', new OutputFormatterStyle( 'white', 'red' ) ); |
|
75 | + $this->setStyle( 'info', new OutputFormatterStyle( 'green' ) ); |
|
76 | + $this->setStyle( 'comment', new OutputFormatterStyle( 'yellow' ) ); |
|
77 | + $this->setStyle( 'question', new OutputFormatterStyle( 'black', 'cyan' ) ); |
|
78 | 78 | |
79 | - foreach ($styles as $name => $style) { |
|
80 | - $this->setStyle($name, $style); |
|
79 | + foreach ( $styles as $name => $style ) { |
|
80 | + $this->setStyle( $name, $style ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $this->styleStack = new OutputFormatterStyleStack(); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | /** |
87 | 87 | * {@inheritdoc} |
88 | 88 | */ |
89 | - public function setDecorated(bool $decorated) |
|
89 | + public function setDecorated( bool $decorated ) |
|
90 | 90 | { |
91 | 91 | $this->decorated = $decorated; |
92 | 92 | } |
@@ -102,87 +102,87 @@ discard block |
||
102 | 102 | /** |
103 | 103 | * {@inheritdoc} |
104 | 104 | */ |
105 | - public function setStyle(string $name, OutputFormatterStyleInterface $style) |
|
105 | + public function setStyle( string $name, OutputFormatterStyleInterface $style ) |
|
106 | 106 | { |
107 | - $this->styles[strtolower($name)] = $style; |
|
107 | + $this->styles[ strtolower( $name ) ] = $style; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * {@inheritdoc} |
112 | 112 | */ |
113 | - public function hasStyle(string $name) |
|
113 | + public function hasStyle( string $name ) |
|
114 | 114 | { |
115 | - return isset($this->styles[strtolower($name)]); |
|
115 | + return isset( $this->styles[ strtolower( $name ) ] ); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
119 | 119 | * {@inheritdoc} |
120 | 120 | */ |
121 | - public function getStyle(string $name) |
|
121 | + public function getStyle( string $name ) |
|
122 | 122 | { |
123 | - if (!$this->hasStyle($name)) { |
|
124 | - throw new InvalidArgumentException(sprintf('Undefined style: "%s".', $name)); |
|
123 | + if ( ! $this->hasStyle( $name ) ) { |
|
124 | + throw new InvalidArgumentException( sprintf( 'Undefined style: "%s".', $name ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | - return $this->styles[strtolower($name)]; |
|
127 | + return $this->styles[ strtolower( $name ) ]; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * {@inheritdoc} |
132 | 132 | */ |
133 | - public function format(?string $message) |
|
133 | + public function format( ?string $message ) |
|
134 | 134 | { |
135 | - return $this->formatAndWrap($message, 0); |
|
135 | + return $this->formatAndWrap( $message, 0 ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * {@inheritdoc} |
140 | 140 | */ |
141 | - public function formatAndWrap(?string $message, int $width) |
|
141 | + public function formatAndWrap( ?string $message, int $width ) |
|
142 | 142 | { |
143 | 143 | $offset = 0; |
144 | 144 | $output = ''; |
145 | 145 | $tagRegex = '[a-z][^<>]*+'; |
146 | 146 | $currentLineLength = 0; |
147 | - preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, \PREG_OFFSET_CAPTURE); |
|
148 | - foreach ($matches[0] as $i => $match) { |
|
149 | - $pos = $match[1]; |
|
150 | - $text = $match[0]; |
|
147 | + preg_match_all( "#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, \PREG_OFFSET_CAPTURE ); |
|
148 | + foreach ( $matches[ 0 ] as $i => $match ) { |
|
149 | + $pos = $match[ 1 ]; |
|
150 | + $text = $match[ 0 ]; |
|
151 | 151 | |
152 | - if (0 != $pos && '\\' == $message[$pos - 1]) { |
|
152 | + if ( 0 != $pos && '\\' == $message[ $pos - 1 ] ) { |
|
153 | 153 | continue; |
154 | 154 | } |
155 | 155 | |
156 | 156 | // add the text up to the next tag |
157 | - $output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset), $output, $width, $currentLineLength); |
|
158 | - $offset = $pos + \strlen($text); |
|
157 | + $output .= $this->applyCurrentStyle( substr( $message, $offset, $pos - $offset ), $output, $width, $currentLineLength ); |
|
158 | + $offset = $pos + \strlen( $text ); |
|
159 | 159 | |
160 | 160 | // opening tag? |
161 | - if ($open = '/' != $text[1]) { |
|
162 | - $tag = $matches[1][$i][0]; |
|
161 | + if ( $open = '/' != $text[ 1 ] ) { |
|
162 | + $tag = $matches[ 1 ][ $i ][ 0 ]; |
|
163 | 163 | } else { |
164 | - $tag = $matches[3][$i][0] ?? ''; |
|
164 | + $tag = $matches[ 3 ][ $i ][ 0 ] ?? ''; |
|
165 | 165 | } |
166 | 166 | |
167 | - if (!$open && !$tag) { |
|
167 | + if ( ! $open && ! $tag ) { |
|
168 | 168 | // </> |
169 | 169 | $this->styleStack->pop(); |
170 | - } elseif (null === $style = $this->createStyleFromString($tag)) { |
|
171 | - $output .= $this->applyCurrentStyle($text, $output, $width, $currentLineLength); |
|
172 | - } elseif ($open) { |
|
173 | - $this->styleStack->push($style); |
|
170 | + } elseif ( null === $style = $this->createStyleFromString( $tag ) ) { |
|
171 | + $output .= $this->applyCurrentStyle( $text, $output, $width, $currentLineLength ); |
|
172 | + } elseif ( $open ) { |
|
173 | + $this->styleStack->push( $style ); |
|
174 | 174 | } else { |
175 | - $this->styleStack->pop($style); |
|
175 | + $this->styleStack->pop( $style ); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | - $output .= $this->applyCurrentStyle(substr($message, $offset), $output, $width, $currentLineLength); |
|
179 | + $output .= $this->applyCurrentStyle( substr( $message, $offset ), $output, $width, $currentLineLength ); |
|
180 | 180 | |
181 | - if (str_contains($output, "\0")) { |
|
182 | - return strtr($output, ["\0" => '\\', '\\<' => '<']); |
|
181 | + if ( str_contains( $output, "\0" ) ) { |
|
182 | + return strtr( $output, [ "\0" => '\\', '\\<' => '<' ] ); |
|
183 | 183 | } |
184 | 184 | |
185 | - return str_replace('\\<', '<', $output); |
|
185 | + return str_replace( '\\<', '<', $output ); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -196,32 +196,32 @@ discard block |
||
196 | 196 | /** |
197 | 197 | * Tries to create new style instance from string. |
198 | 198 | */ |
199 | - private function createStyleFromString(string $string): ?OutputFormatterStyleInterface |
|
199 | + private function createStyleFromString( string $string ): ?OutputFormatterStyleInterface |
|
200 | 200 | { |
201 | - if (isset($this->styles[$string])) { |
|
202 | - return $this->styles[$string]; |
|
201 | + if ( isset( $this->styles[ $string ] ) ) { |
|
202 | + return $this->styles[ $string ]; |
|
203 | 203 | } |
204 | 204 | |
205 | - if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', $string, $matches, \PREG_SET_ORDER)) { |
|
205 | + if ( ! preg_match_all( '/([^=]+)=([^;]+)(;|$)/', $string, $matches, \PREG_SET_ORDER ) ) { |
|
206 | 206 | return null; |
207 | 207 | } |
208 | 208 | |
209 | 209 | $style = new OutputFormatterStyle(); |
210 | - foreach ($matches as $match) { |
|
211 | - array_shift($match); |
|
212 | - $match[0] = strtolower($match[0]); |
|
213 | - |
|
214 | - if ('fg' == $match[0]) { |
|
215 | - $style->setForeground(strtolower($match[1])); |
|
216 | - } elseif ('bg' == $match[0]) { |
|
217 | - $style->setBackground(strtolower($match[1])); |
|
218 | - } elseif ('href' === $match[0]) { |
|
219 | - $style->setHref($match[1]); |
|
220 | - } elseif ('options' === $match[0]) { |
|
221 | - preg_match_all('([^,;]+)', strtolower($match[1]), $options); |
|
222 | - $options = array_shift($options); |
|
223 | - foreach ($options as $option) { |
|
224 | - $style->setOption($option); |
|
210 | + foreach ( $matches as $match ) { |
|
211 | + array_shift( $match ); |
|
212 | + $match[ 0 ] = strtolower( $match[ 0 ] ); |
|
213 | + |
|
214 | + if ( 'fg' == $match[ 0 ] ) { |
|
215 | + $style->setForeground( strtolower( $match[ 1 ] ) ); |
|
216 | + } elseif ( 'bg' == $match[ 0 ] ) { |
|
217 | + $style->setBackground( strtolower( $match[ 1 ] ) ); |
|
218 | + } elseif ( 'href' === $match[ 0 ] ) { |
|
219 | + $style->setHref( $match[ 1 ] ); |
|
220 | + } elseif ( 'options' === $match[ 0 ] ) { |
|
221 | + preg_match_all( '([^,;]+)', strtolower( $match[ 1 ] ), $options ); |
|
222 | + $options = array_shift( $options ); |
|
223 | + foreach ( $options as $option ) { |
|
224 | + $style->setOption( $option ); |
|
225 | 225 | } |
226 | 226 | } else { |
227 | 227 | return null; |
@@ -234,50 +234,50 @@ discard block |
||
234 | 234 | /** |
235 | 235 | * Applies current style from stack to text, if must be applied. |
236 | 236 | */ |
237 | - private function applyCurrentStyle(string $text, string $current, int $width, int &$currentLineLength): string |
|
237 | + private function applyCurrentStyle( string $text, string $current, int $width, int &$currentLineLength ): string |
|
238 | 238 | { |
239 | - if ('' === $text) { |
|
239 | + if ( '' === $text ) { |
|
240 | 240 | return ''; |
241 | 241 | } |
242 | 242 | |
243 | - if (!$width) { |
|
244 | - return $this->isDecorated() ? $this->styleStack->getCurrent()->apply($text) : $text; |
|
243 | + if ( ! $width ) { |
|
244 | + return $this->isDecorated() ? $this->styleStack->getCurrent()->apply( $text ) : $text; |
|
245 | 245 | } |
246 | 246 | |
247 | - if (!$currentLineLength && '' !== $current) { |
|
248 | - $text = ltrim($text); |
|
247 | + if ( ! $currentLineLength && '' !== $current ) { |
|
248 | + $text = ltrim( $text ); |
|
249 | 249 | } |
250 | 250 | |
251 | - if ($currentLineLength) { |
|
252 | - $prefix = substr($text, 0, $i = $width - $currentLineLength)."\n"; |
|
253 | - $text = substr($text, $i); |
|
251 | + if ( $currentLineLength ) { |
|
252 | + $prefix = substr( $text, 0, $i = $width - $currentLineLength ) . "\n"; |
|
253 | + $text = substr( $text, $i ); |
|
254 | 254 | } else { |
255 | 255 | $prefix = ''; |
256 | 256 | } |
257 | 257 | |
258 | - preg_match('~(\\n)$~', $text, $matches); |
|
259 | - $text = $prefix.preg_replace('~([^\\n]{'.$width.'})\\ *~', "\$1\n", $text); |
|
260 | - $text = rtrim($text, "\n").($matches[1] ?? ''); |
|
258 | + preg_match( '~(\\n)$~', $text, $matches ); |
|
259 | + $text = $prefix . preg_replace( '~([^\\n]{' . $width . '})\\ *~', "\$1\n", $text ); |
|
260 | + $text = rtrim( $text, "\n" ) . ( $matches[ 1 ] ?? '' ); |
|
261 | 261 | |
262 | - if (!$currentLineLength && '' !== $current && "\n" !== substr($current, -1)) { |
|
263 | - $text = "\n".$text; |
|
262 | + if ( ! $currentLineLength && '' !== $current && "\n" !== substr( $current, -1 ) ) { |
|
263 | + $text = "\n" . $text; |
|
264 | 264 | } |
265 | 265 | |
266 | - $lines = explode("\n", $text); |
|
266 | + $lines = explode( "\n", $text ); |
|
267 | 267 | |
268 | - foreach ($lines as $line) { |
|
269 | - $currentLineLength += \strlen($line); |
|
270 | - if ($width <= $currentLineLength) { |
|
268 | + foreach ( $lines as $line ) { |
|
269 | + $currentLineLength += \strlen( $line ); |
|
270 | + if ( $width <= $currentLineLength ) { |
|
271 | 271 | $currentLineLength = 0; |
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
275 | - if ($this->isDecorated()) { |
|
276 | - foreach ($lines as $i => $line) { |
|
277 | - $lines[$i] = $this->styleStack->getCurrent()->apply($line); |
|
275 | + if ( $this->isDecorated() ) { |
|
276 | + foreach ( $lines as $i => $line ) { |
|
277 | + $lines[ $i ] = $this->styleStack->getCurrent()->apply( $line ); |
|
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - return implode("\n", $lines); |
|
281 | + return implode( "\n", $lines ); |
|
282 | 282 | } |
283 | 283 | } |
@@ -33,28 +33,28 @@ discard block |
||
33 | 33 | * @param string|null $foreground The style foreground color name |
34 | 34 | * @param string|null $background The style background color name |
35 | 35 | */ |
36 | - public function __construct(string $foreground = null, string $background = null, array $options = []) |
|
36 | + public function __construct( string $foreground = null, string $background = null, array $options = [ ] ) |
|
37 | 37 | { |
38 | - $this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options); |
|
38 | + $this->color = new Color( $this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * {@inheritdoc} |
43 | 43 | */ |
44 | - public function setForeground(string $color = null) |
|
44 | + public function setForeground( string $color = null ) |
|
45 | 45 | { |
46 | - $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); |
|
46 | + $this->color = new Color( $this->foreground = $color ?: '', $this->background, $this->options ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * {@inheritdoc} |
51 | 51 | */ |
52 | - public function setBackground(string $color = null) |
|
52 | + public function setBackground( string $color = null ) |
|
53 | 53 | { |
54 | - $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); |
|
54 | + $this->color = new Color( $this->foreground, $this->background = $color ?: '', $this->options ); |
|
55 | 55 | } |
56 | 56 | |
57 | - public function setHref(string $url): void |
|
57 | + public function setHref( string $url ): void |
|
58 | 58 | { |
59 | 59 | $this->href = $url; |
60 | 60 | } |
@@ -62,47 +62,47 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * {@inheritdoc} |
64 | 64 | */ |
65 | - public function setOption(string $option) |
|
65 | + public function setOption( string $option ) |
|
66 | 66 | { |
67 | - $this->options[] = $option; |
|
68 | - $this->color = new Color($this->foreground, $this->background, $this->options); |
|
67 | + $this->options[ ] = $option; |
|
68 | + $this->color = new Color( $this->foreground, $this->background, $this->options ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
72 | 72 | * {@inheritdoc} |
73 | 73 | */ |
74 | - public function unsetOption(string $option) |
|
74 | + public function unsetOption( string $option ) |
|
75 | 75 | { |
76 | - $pos = array_search($option, $this->options); |
|
77 | - if (false !== $pos) { |
|
78 | - unset($this->options[$pos]); |
|
76 | + $pos = array_search( $option, $this->options ); |
|
77 | + if ( false !== $pos ) { |
|
78 | + unset( $this->options[ $pos ] ); |
|
79 | 79 | } |
80 | 80 | |
81 | - $this->color = new Color($this->foreground, $this->background, $this->options); |
|
81 | + $this->color = new Color( $this->foreground, $this->background, $this->options ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * {@inheritdoc} |
86 | 86 | */ |
87 | - public function setOptions(array $options) |
|
87 | + public function setOptions( array $options ) |
|
88 | 88 | { |
89 | - $this->color = new Color($this->foreground, $this->background, $this->options = $options); |
|
89 | + $this->color = new Color( $this->foreground, $this->background, $this->options = $options ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * {@inheritdoc} |
94 | 94 | */ |
95 | - public function apply(string $text) |
|
95 | + public function apply( string $text ) |
|
96 | 96 | { |
97 | - if (null === $this->handlesHrefGracefully) { |
|
98 | - $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') |
|
99 | - && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100); |
|
97 | + if ( null === $this->handlesHrefGracefully ) { |
|
98 | + $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv( 'TERMINAL_EMULATOR' ) |
|
99 | + && ( ! getenv( 'KONSOLE_VERSION' ) || (int)getenv( 'KONSOLE_VERSION' ) > 201100 ); |
|
100 | 100 | } |
101 | 101 | |
102 | - if (null !== $this->href && $this->handlesHrefGracefully) { |
|
102 | + if ( null !== $this->href && $this->handlesHrefGracefully ) { |
|
103 | 103 | $text = "\033]8;;$this->href\033\\$text\033]8;;\033\\"; |
104 | 104 | } |
105 | 105 | |
106 | - return $this->color->apply($text); |
|
106 | + return $this->color->apply( $text ); |
|
107 | 107 | } |
108 | 108 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * {@inheritdoc} |
23 | 23 | */ |
24 | - public function format(?string $message): void |
|
24 | + public function format( ?string $message ): void |
|
25 | 25 | { |
26 | 26 | // do nothing |
27 | 27 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * {@inheritdoc} |
31 | 31 | */ |
32 | - public function getStyle(string $name): OutputFormatterStyleInterface |
|
32 | + public function getStyle( string $name ): OutputFormatterStyleInterface |
|
33 | 33 | { |
34 | - if ($this->style) { |
|
34 | + if ( $this->style ) { |
|
35 | 35 | return $this->style; |
36 | 36 | } |
37 | 37 | // to comply with the interface we must return a OutputFormatterStyleInterface |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * {@inheritdoc} |
43 | 43 | */ |
44 | - public function hasStyle(string $name): bool |
|
44 | + public function hasStyle( string $name ): bool |
|
45 | 45 | { |
46 | 46 | return false; |
47 | 47 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * {@inheritdoc} |
59 | 59 | */ |
60 | - public function setDecorated(bool $decorated): void |
|
60 | + public function setDecorated( bool $decorated ): void |
|
61 | 61 | { |
62 | 62 | // do nothing |
63 | 63 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * {@inheritdoc} |
67 | 67 | */ |
68 | - public function setStyle(string $name, OutputFormatterStyleInterface $style): void |
|
68 | + public function setStyle( string $name, OutputFormatterStyleInterface $style ): void |
|
69 | 69 | { |
70 | 70 | // do nothing |
71 | 71 | } |
@@ -21,32 +21,32 @@ |
||
21 | 21 | /** |
22 | 22 | * Sets style foreground color. |
23 | 23 | */ |
24 | - public function setForeground(string $color = null); |
|
24 | + public function setForeground( string $color = null ); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Sets style background color. |
28 | 28 | */ |
29 | - public function setBackground(string $color = null); |
|
29 | + public function setBackground( string $color = null ); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Sets some specific style option. |
33 | 33 | */ |
34 | - public function setOption(string $option); |
|
34 | + public function setOption( string $option ); |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Unsets some specific style option. |
38 | 38 | */ |
39 | - public function unsetOption(string $option); |
|
39 | + public function unsetOption( string $option ); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Sets multiple style options at once. |
43 | 43 | */ |
44 | - public function setOptions(array $options); |
|
44 | + public function setOptions( array $options ); |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * Applies the style to a given text. |
48 | 48 | * |
49 | 49 | * @return string |
50 | 50 | */ |
51 | - public function apply(string $text); |
|
51 | + public function apply( string $text ); |
|
52 | 52 | } |
@@ -21,5 +21,5 @@ |
||
21 | 21 | /** |
22 | 22 | * Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping). |
23 | 23 | */ |
24 | - public function formatAndWrap(?string $message, int $width); |
|
24 | + public function formatAndWrap( ?string $message, int $width ); |
|
25 | 25 | } |
@@ -21,78 +21,78 @@ discard block |
||
21 | 21 | private $output; |
22 | 22 | private $input; |
23 | 23 | |
24 | - public function __construct(OutputInterface $output, $input = null) |
|
24 | + public function __construct( OutputInterface $output, $input = null ) |
|
25 | 25 | { |
26 | 26 | $this->output = $output; |
27 | - $this->input = $input ?? (\defined('STDIN') ? \STDIN : fopen('php://input', 'r+')); |
|
27 | + $this->input = $input ?? ( \defined( 'STDIN' ) ? \STDIN : fopen( 'php://input', 'r+' ) ); |
|
28 | 28 | } |
29 | 29 | |
30 | - public function moveUp(int $lines = 1): self |
|
30 | + public function moveUp( int $lines = 1 ): self |
|
31 | 31 | { |
32 | - $this->output->write(sprintf("\x1b[%dA", $lines)); |
|
32 | + $this->output->write( sprintf( "\x1b[%dA", $lines ) ); |
|
33 | 33 | |
34 | 34 | return $this; |
35 | 35 | } |
36 | 36 | |
37 | - public function moveDown(int $lines = 1): self |
|
37 | + public function moveDown( int $lines = 1 ): self |
|
38 | 38 | { |
39 | - $this->output->write(sprintf("\x1b[%dB", $lines)); |
|
39 | + $this->output->write( sprintf( "\x1b[%dB", $lines ) ); |
|
40 | 40 | |
41 | 41 | return $this; |
42 | 42 | } |
43 | 43 | |
44 | - public function moveRight(int $columns = 1): self |
|
44 | + public function moveRight( int $columns = 1 ): self |
|
45 | 45 | { |
46 | - $this->output->write(sprintf("\x1b[%dC", $columns)); |
|
46 | + $this->output->write( sprintf( "\x1b[%dC", $columns ) ); |
|
47 | 47 | |
48 | 48 | return $this; |
49 | 49 | } |
50 | 50 | |
51 | - public function moveLeft(int $columns = 1): self |
|
51 | + public function moveLeft( int $columns = 1 ): self |
|
52 | 52 | { |
53 | - $this->output->write(sprintf("\x1b[%dD", $columns)); |
|
53 | + $this->output->write( sprintf( "\x1b[%dD", $columns ) ); |
|
54 | 54 | |
55 | 55 | return $this; |
56 | 56 | } |
57 | 57 | |
58 | - public function moveToColumn(int $column): self |
|
58 | + public function moveToColumn( int $column ): self |
|
59 | 59 | { |
60 | - $this->output->write(sprintf("\x1b[%dG", $column)); |
|
60 | + $this->output->write( sprintf( "\x1b[%dG", $column ) ); |
|
61 | 61 | |
62 | 62 | return $this; |
63 | 63 | } |
64 | 64 | |
65 | - public function moveToPosition(int $column, int $row): self |
|
65 | + public function moveToPosition( int $column, int $row ): self |
|
66 | 66 | { |
67 | - $this->output->write(sprintf("\x1b[%d;%dH", $row + 1, $column)); |
|
67 | + $this->output->write( sprintf( "\x1b[%d;%dH", $row + 1, $column ) ); |
|
68 | 68 | |
69 | 69 | return $this; |
70 | 70 | } |
71 | 71 | |
72 | 72 | public function savePosition(): self |
73 | 73 | { |
74 | - $this->output->write("\x1b7"); |
|
74 | + $this->output->write( "\x1b7" ); |
|
75 | 75 | |
76 | 76 | return $this; |
77 | 77 | } |
78 | 78 | |
79 | 79 | public function restorePosition(): self |
80 | 80 | { |
81 | - $this->output->write("\x1b8"); |
|
81 | + $this->output->write( "\x1b8" ); |
|
82 | 82 | |
83 | 83 | return $this; |
84 | 84 | } |
85 | 85 | |
86 | 86 | public function hide(): self |
87 | 87 | { |
88 | - $this->output->write("\x1b[?25l"); |
|
88 | + $this->output->write( "\x1b[?25l" ); |
|
89 | 89 | |
90 | 90 | return $this; |
91 | 91 | } |
92 | 92 | |
93 | 93 | public function show(): self |
94 | 94 | { |
95 | - $this->output->write("\x1b[?25h\x1b[?0c"); |
|
95 | + $this->output->write( "\x1b[?25h\x1b[?0c" ); |
|
96 | 96 | |
97 | 97 | return $this; |
98 | 98 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function clearLine(): self |
104 | 104 | { |
105 | - $this->output->write("\x1b[2K"); |
|
105 | + $this->output->write( "\x1b[2K" ); |
|
106 | 106 | |
107 | 107 | return $this; |
108 | 108 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function clearLineAfter(): self |
114 | 114 | { |
115 | - $this->output->write("\x1b[K"); |
|
115 | + $this->output->write( "\x1b[K" ); |
|
116 | 116 | |
117 | 117 | return $this; |
118 | 118 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function clearOutput(): self |
124 | 124 | { |
125 | - $this->output->write("\x1b[0J"); |
|
125 | + $this->output->write( "\x1b[0J" ); |
|
126 | 126 | |
127 | 127 | return $this; |
128 | 128 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function clearScreen(): self |
134 | 134 | { |
135 | - $this->output->write("\x1b[2J"); |
|
135 | + $this->output->write( "\x1b[2J" ); |
|
136 | 136 | |
137 | 137 | return $this; |
138 | 138 | } |
@@ -144,25 +144,25 @@ discard block |
||
144 | 144 | { |
145 | 145 | static $isTtySupported; |
146 | 146 | |
147 | - if (null === $isTtySupported && \function_exists('proc_open')) { |
|
148 | - $isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes); |
|
147 | + if ( null === $isTtySupported && \function_exists( 'proc_open' ) ) { |
|
148 | + $isTtySupported = (bool)@proc_open( 'echo 1 >/dev/null', [ [ 'file', '/dev/tty', 'r' ], [ 'file', '/dev/tty', 'w' ], [ 'file', '/dev/tty', 'w' ] ], $pipes ); |
|
149 | 149 | } |
150 | 150 | |
151 | - if (!$isTtySupported) { |
|
152 | - return [1, 1]; |
|
151 | + if ( ! $isTtySupported ) { |
|
152 | + return [ 1, 1 ]; |
|
153 | 153 | } |
154 | 154 | |
155 | - $sttyMode = shell_exec('stty -g'); |
|
156 | - shell_exec('stty -icanon -echo'); |
|
155 | + $sttyMode = shell_exec( 'stty -g' ); |
|
156 | + shell_exec( 'stty -icanon -echo' ); |
|
157 | 157 | |
158 | - @fwrite($this->input, "\033[6n"); |
|
158 | + @fwrite( $this->input, "\033[6n" ); |
|
159 | 159 | |
160 | - $code = trim(fread($this->input, 1024)); |
|
160 | + $code = trim( fread( $this->input, 1024 ) ); |
|
161 | 161 | |
162 | - shell_exec(sprintf('stty %s', $sttyMode)); |
|
162 | + shell_exec( sprintf( 'stty %s', $sttyMode ) ); |
|
163 | 163 | |
164 | - sscanf($code, "\033[%d;%dR", $row, $col); |
|
164 | + sscanf( $code, "\033[%d;%dR", $row, $col ); |
|
165 | 165 | |
166 | - return [$col, $row]; |
|
166 | + return [ $col, $row ]; |
|
167 | 167 | } |
168 | 168 | } |