Skip to content

Commit 81bc9a0

Browse files
committed
Fix CS
1 parent e631b09 commit 81bc9a0

File tree

6 files changed

+58
-58
lines changed

6 files changed

+58
-58
lines changed

SensioLabs/AnsiConverter/AnsiToHtmlConverter.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function __construct(?Theme $theme = null, $inlineStyles = true, $charset
3030
$this->inlineStyles = $inlineStyles;
3131
$this->charset = $charset;
3232
$this->inlineColors = $this->theme->asArray();
33-
$this->colorNames = array(
33+
$this->colorNames = [
3434
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white',
3535
'', '',
3636
'brblack', 'brred', 'brgreen', 'bryellow', 'brblue', 'brmagenta', 'brcyan', 'brwhite',
37-
);
37+
];
3838
}
3939

4040
public function convert($text)
@@ -44,7 +44,7 @@ public function convert($text)
4444
// remove character set sequences
4545
$text = preg_replace('#\e(\(|\))(A|B|[0-2])#', '', $text);
4646

47-
$text = htmlspecialchars($text, PHP_VERSION_ID >= 50400 ? ENT_QUOTES | ENT_SUBSTITUTE : ENT_QUOTES, $this->charset);
47+
$text = htmlspecialchars($text, \PHP_VERSION_ID >= 50400 ? \ENT_QUOTES | \ENT_SUBSTITUTE : \ENT_QUOTES, $this->charset);
4848

4949
// carriage return
5050
$text = preg_replace('#^.*\r(?!\n)#m', '', $text);
@@ -56,7 +56,7 @@ public function convert($text)
5656
if ('backspace' == $token[0]) {
5757
$j = $i;
5858
while (--$j >= 0) {
59-
if ('text' == $tokens[$j][0] && strlen($tokens[$j][1]) > 0) {
59+
if ('text' == $tokens[$j][0] && '' !== $tokens[$j][1]) {
6060
$tokens[$j][1] = substr($tokens[$j][1], 0, -1);
6161

6262
break;
@@ -75,9 +75,9 @@ public function convert($text)
7575
}
7676

7777
if ($this->inlineStyles) {
78-
$html = sprintf('<span style="background-color: %s; color: %s">%s</span>', $this->inlineColors['black'], $this->inlineColors['white'], $html);
78+
$html = \sprintf('<span style="background-color: %s; color: %s">%s</span>', $this->inlineColors['black'], $this->inlineColors['white'], $html);
7979
} else {
80-
$html = sprintf('<span class="ansi_color_bg_black ansi_color_fg_white">%s</span>', $html);
80+
$html = \sprintf('<span class="ansi_color_bg_black ansi_color_fg_white">%s</span>', $html);
8181
}
8282

8383
// remove empty span
@@ -135,75 +135,75 @@ protected function convertAnsiToColor($ansi)
135135
}
136136

137137
// options: bold => 1, dim => 2, italic => 3, underscore => 4, blink => 5, rapid blink => 6, reverse => 7, conceal => 8, strikethrough => 9
138-
if (in_array(1, $options) || $hi) { // high intensity equals regular bold
138+
if (\in_array(1, $options) || $hi) { // high intensity equals regular bold
139139
$fg += 10;
140140
// bold does not affect background color
141141
}
142142

143-
if (in_array(2, $options)) { // dim
143+
if (\in_array(2, $options)) { // dim
144144
$fg = ($fg >= 10) ? $fg - 10 : $fg;
145145
}
146146

147-
if (in_array(3, $options)) {
147+
if (\in_array(3, $options)) {
148148
$as .= '; font-style: italic';
149149
$cs .= ' ansi_color_italic';
150150
}
151151

152-
if (in_array(4, $options)) {
152+
if (\in_array(4, $options)) {
153153
$as .= '; text-decoration: underline';
154154
$cs .= ' ansi_color_underline';
155155
}
156156

157-
if (in_array(9, $options)) {
157+
if (\in_array(9, $options)) {
158158
$as .= '; text-decoration: line-through';
159159
$cs .= ' ansi_color_strikethrough';
160160
}
161161

162-
if (in_array(7, $options)) {
162+
if (\in_array(7, $options)) {
163163
$tmp = $fg;
164164
$fg = $bg;
165165
$bg = $tmp;
166166
}
167167
}
168168

169169
if ($this->inlineStyles) {
170-
return sprintf('</span><span style="background-color: %s; color: %s%s">', $this->inlineColors[$this->colorNames[$bg]], $this->inlineColors[$this->colorNames[$fg]], $as);
170+
return \sprintf('</span><span style="background-color: %s; color: %s%s">', $this->inlineColors[$this->colorNames[$bg]], $this->inlineColors[$this->colorNames[$fg]], $as);
171171
} else {
172-
return sprintf('</span><span class="ansi_color_bg_%s ansi_color_fg_%s%s">', $this->colorNames[$bg], $this->colorNames[$fg], $cs);
172+
return \sprintf('</span><span class="ansi_color_bg_%s ansi_color_fg_%s%s">', $this->colorNames[$bg], $this->colorNames[$fg], $cs);
173173
}
174174
}
175175

176176
protected function tokenize($text)
177177
{
178-
$tokens = array();
179-
preg_match_all("/(?:\e\[(.*?)m|(\x08))/", $text, $matches, PREG_OFFSET_CAPTURE);
178+
$tokens = [];
179+
preg_match_all("/(?:\e\[(.*?)m|(\x08))/", $text, $matches, \PREG_OFFSET_CAPTURE);
180180

181-
$codes = array();
181+
$codes = [];
182182
$offset = 0;
183183
foreach ($matches[0] as $i => $match) {
184184
if ($match[1] - $offset > 0) {
185-
$tokens[] = array('text', substr($text, $offset, $match[1] - $offset));
185+
$tokens[] = ['text', substr($text, $offset, $match[1] - $offset)];
186186
}
187187

188188
foreach (explode(';', $matches[1][$i][0]) as $code) {
189189
if ('0' == $code || '' == $code) {
190-
$codes = array();
190+
$codes = [];
191191
} else {
192192
// remove existing occurrence to avoid processing duplicate styles
193-
if (in_array($code, $codes) && ($key = array_search($code, $codes)) !== false) {
193+
if (\in_array($code, $codes) && ($key = array_search($code, $codes)) !== false) {
194194
unset($codes[$key]);
195195
}
196196
}
197197

198198
$codes[] = $code;
199199
}
200200

201-
$tokens[] = array("\x08" == $match[0] ? 'backspace' : 'color', implode(';', $codes));
202-
$offset = $match[1] + strlen($match[0]);
201+
$tokens[] = ["\x08" == $match[0] ? 'backspace' : 'color', implode(';', $codes)];
202+
$offset = $match[1] + \strlen($match[0]);
203203
}
204204

205-
if ($offset < strlen($text)) {
206-
$tokens[] = array('text', substr($text, $offset));
205+
if ($offset < \strlen($text)) {
206+
$tokens[] = ['text', substr($text, $offset)];
207207
}
208208

209209
return $tokens;

SensioLabs/AnsiConverter/Tests/AnsiToHtmlConverterTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,58 +27,58 @@ public function testConvert($expected, $input)
2727

2828
public static function getConvertData()
2929
{
30-
return array(
30+
return [
3131
// text is escaped
32-
array('<span style="background-color: black; color: white">foo &lt;br /&gt;</span>', 'foo <br />'),
32+
['<span style="background-color: black; color: white">foo &lt;br /&gt;</span>', 'foo <br />'],
3333

3434
// newlines are preserved
35-
array("<span style=\"background-color: black; color: white\">foo\nbar</span>", "foo\nbar"),
35+
["<span style=\"background-color: black; color: white\">foo\nbar</span>", "foo\nbar"],
3636

3737
// backspaces
38-
array('<span style="background-color: black; color: white">foo </span>', "foobar\x08\x08\x08 "),
39-
array('<span style="background-color: black; color: white">foo</span><span style="background-color: black; color: white"> </span>', "foob\e[31;41ma\e[0mr\x08\x08\x08 "),
38+
['<span style="background-color: black; color: white">foo </span>', "foobar\x08\x08\x08 "],
39+
['<span style="background-color: black; color: white">foo</span><span style="background-color: black; color: white"> </span>', "foob\e[31;41ma\e[0mr\x08\x08\x08 "],
4040

4141
// color
42-
array('<span style="background-color: darkred; color: darkred">foo</span>', "\e[31;41mfoo\e[0m"),
42+
['<span style="background-color: darkred; color: darkred">foo</span>', "\e[31;41mfoo\e[0m"],
4343

4444
// color with [m as a termination (equivalent to [0m])
45-
array('<span style="background-color: darkred; color: darkred">foo</span>', "\e[31;41mfoo\e[m"),
45+
['<span style="background-color: darkred; color: darkred">foo</span>', "\e[31;41mfoo\e[m"],
4646

4747
// bright color
48-
array('<span style="background-color: darkred; color: red">foo</span>', "\e[31;41;1mfoo\e[0m"),
48+
['<span style="background-color: darkred; color: red">foo</span>', "\e[31;41;1mfoo\e[0m"],
4949

5050
// carriage returns
51-
array('<span style="background-color: black; color: white">foobar</span>', "foo\rbar\rfoobar"),
51+
['<span style="background-color: black; color: white">foobar</span>', "foo\rbar\rfoobar"],
5252

5353
// underline
54-
array('<span style="background-color: black; color: white; text-decoration: underline">foo</span>', "\e[4mfoo\e[0m"),
54+
['<span style="background-color: black; color: white; text-decoration: underline">foo</span>', "\e[4mfoo\e[0m"],
5555

5656
// italic
57-
array('<span style="background-color: black; color: white; font-style: italic">foo</span>', "\e[3mfoo\e[0m"),
57+
['<span style="background-color: black; color: white; font-style: italic">foo</span>', "\e[3mfoo\e[0m"],
5858

5959
// strikethrough
60-
array('<span style="background-color: black; color: white; text-decoration: line-through">foo</span>', "\e[9mfoo\e[0m"),
60+
['<span style="background-color: black; color: white; text-decoration: line-through">foo</span>', "\e[9mfoo\e[0m"],
6161

6262
// high intensity = normal bold
63-
array('<span style="background-color: black; color: red">foo</span>', "\e[91mfoo\e[0m"),
63+
['<span style="background-color: black; color: red">foo</span>', "\e[91mfoo\e[0m"],
6464

6565
// high intensity dimmed = normal
66-
array('<span style="background-color: black; color: darkred">foo</span>', "\e[2;91mfoo\e[0m"),
66+
['<span style="background-color: black; color: darkred">foo</span>', "\e[2;91mfoo\e[0m"],
6767

6868
// high intensity background
69-
array('<span style="background-color: magenta; color: white">foo</span>', "\e[105mfoo\e[0m"),
69+
['<span style="background-color: magenta; color: white">foo</span>', "\e[105mfoo\e[0m"],
7070

7171
// bold and background (bold does not affect background color)
72-
array('<span style="background-color: darkred; color: lightcyan">foo</span>', "\e[1;41;36mfoo\e[0m"),
72+
['<span style="background-color: darkred; color: lightcyan">foo</span>', "\e[1;41;36mfoo\e[0m"],
7373

7474
// bold and background (high intensity)
75-
array('<span style="background-color: red; color: lightcyan">foo</span>', "\e[1;101;96mfoo\e[0m"),
75+
['<span style="background-color: red; color: lightcyan">foo</span>', "\e[1;101;96mfoo\e[0m"],
7676

7777
// non valid unicode codepoints substitution (only available with PHP >= 5.4)
78-
PHP_VERSION_ID < 50400 ?: array('<span style="background-color: black; color: white">foo '."\xEF\xBF\xBD".'</span>', "foo \xF4\xFF\xFF\xFF"),
78+
\PHP_VERSION_ID < 50400 ?: ['<span style="background-color: black; color: white">foo '."\xEF\xBF\xBD".'</span>', "foo \xF4\xFF\xFF\xFF"],
7979

8080
// codes in sequence - remember enabled styling like bold, italic, etc. (until we hit a reset)
81-
array('<span style="background-color: black; color: lightgreen">foo</span><span style="background-color: black; color: lightgreen">bar</span><span style="background-color: black; color: white">foo</span>', "\e[1;32mfoo\e[32mbar\e[mfoo"),
82-
);
81+
['<span style="background-color: black; color: lightgreen">foo</span><span style="background-color: black; color: lightgreen">bar</span><span style="background-color: black; color: white">foo</span>', "\e[1;32mfoo\e[32mbar\e[mfoo"],
82+
];
8383
}
8484
}

SensioLabs/AnsiConverter/Theme/AnsiTheme.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AnsiTheme extends Theme
1818
{
1919
public function asArray()
2020
{
21-
return array(
21+
return [
2222
// normal
2323
'black' => '#000000',
2424
'red' => '#AA0000',
@@ -38,6 +38,6 @@ public function asArray()
3838
'brmagenta' => '#FF55FF',
3939
'brcyan' => '#55FFFF',
4040
'brwhite' => '#FFFFFF',
41-
);
41+
];
4242
}
4343
}

SensioLabs/AnsiConverter/Theme/SolarizedTheme.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SolarizedTheme extends Theme
2020
{
2121
public function asArray()
2222
{
23-
return array(
23+
return [
2424
// normal
2525
'black' => '#073642',
2626
'red' => '#dc322f',
@@ -40,6 +40,6 @@ public function asArray()
4040
'brmagenta' => '#6c71c4',
4141
'brcyan' => '#93a1a1',
4242
'brwhite' => '#fdf6e3',
43-
);
43+
];
4444
}
4545
}

SensioLabs/AnsiConverter/Theme/SolarizedXTermTheme.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SolarizedXTermTheme extends Theme
2020
{
2121
public function asArray()
2222
{
23-
return array(
23+
return [
2424
// normal
2525
'black' => '#262626',
2626
'red' => '#d70000',
@@ -40,6 +40,6 @@ public function asArray()
4040
'brmagenta' => '#5f5faf',
4141
'brcyan' => '#8a8a8a',
4242
'brwhite' => '#ffffd7',
43-
);
43+
];
4444
}
4545
}

SensioLabs/AnsiConverter/Theme/Theme.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ class Theme
1818
{
1919
public function asCss($prefix = 'ansi_color')
2020
{
21-
$css = array();
21+
$css = [];
2222
foreach ($this->asArray() as $name => $color) {
23-
$css[] = sprintf('.%s_fg_%s { color: %s }', $prefix, $name, $color);
24-
$css[] = sprintf('.%s_bg_%s { background-color: %s }', $prefix, $name, $color);
23+
$css[] = \sprintf('.%s_fg_%s { color: %s }', $prefix, $name, $color);
24+
$css[] = \sprintf('.%s_bg_%s { background-color: %s }', $prefix, $name, $color);
2525
}
2626

27-
$css[] = sprintf('.%s_italic { font-style: italic }', $prefix);
28-
$css[] = sprintf('.%s_underline { text-decoration: underline }', $prefix);
29-
$css[] = sprintf('.%s_strikethrough { text-decoration: line-through }', $prefix);
27+
$css[] = \sprintf('.%s_italic { font-style: italic }', $prefix);
28+
$css[] = \sprintf('.%s_underline { text-decoration: underline }', $prefix);
29+
$css[] = \sprintf('.%s_strikethrough { text-decoration: line-through }', $prefix);
3030

3131
return implode("\n", $css);
3232
}
3333

3434
public function asArray()
3535
{
36-
return array(
36+
return [
3737
'black' => 'black',
3838
'red' => 'darkred',
3939
'green' => 'green',
@@ -51,6 +51,6 @@ public function asArray()
5151
'brmagenta' => 'magenta',
5252
'brcyan' => 'lightcyan',
5353
'brwhite' => 'white',
54-
);
54+
];
5555
}
5656
}

0 commit comments

Comments
 (0)