Passed
Push — master ( ff2740...d05a86 )
by Alec
03:15 queued 13s
created

Rainbow::reverseSequence()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A Rainbow::ansi24Sequence() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Palette;
6
7
use AlecRabbit\Spinner\Core\Contract\IStyleFrame;
8
use AlecRabbit\Spinner\Core\Palette\A\AStylePalette;
9
use Traversable;
10
11
use function array_reverse;
12
use function sprintf;
13
14
final class Rainbow extends AStylePalette
15
{
16
    /**
17
     * @return Traversable<IStyleFrame>
18
     */
19
    protected function ansi4StyleFrames(): Traversable
20
    {
21
        yield from [
22
            $this->createFrame("\e[96m%s\e[39m"),
23
        ];
24
    }
25
26
    /**
27
     * @return Traversable<IStyleFrame>
28
     */
29
    protected function ansi8StyleFrames(): Traversable
30
    {
31
        /** @var string $item */
32
        foreach ($this->ansi8Sequence() as $item) {
33
            $element = sprintf("\e[38;5;%sm%%s\e[39m", $item);
0 ignored issues
show
Bug introduced by
$item of type array<integer,string> is incompatible with the type double|integer|string expected by parameter $values of sprintf(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
            $element = sprintf("\e[38;5;%sm%%s\e[39m", /** @scrutinizer ignore-type */ $item);
Loading history...
34
            yield $this->createFrame($element);
35
        }
36
    }
37
38
    /**
39
     * @return Traversable<string>
40
     */
41
    private function ansi8Sequence(): Traversable
42
    {
43
        yield from [
44
            '196',
45
            '208',
46
            '214',
47
            '220',
48
            '226',
49
            '190',
50
            '154',
51
            '118',
52
            '82',
53
            '46',
54
            '47',
55
            '48',
56
            '49',
57
            '50',
58
            '51',
59
            '45',
60
            '39',
61
            '33',
62
            '27',
63
            '56',
64
            '57',
65
            '93',
66
            '129',
67
            '165',
68
            '201',
69
            '200',
70
            '199',
71
            '198',
72
            '197',
73
        ];
74
    }
75
76
    /**
77
     * @return Traversable<IStyleFrame>
78
     */
79
    protected function ansi24StyleFrames(): Traversable
80
    {
81
        /** @var string $item */
82
        foreach ($this->ansi24Sequence() as $item) {
83
            $element = sprintf("\e[38;2;%sm%%s\e[39m", $item);
0 ignored issues
show
Bug introduced by
$item of type array<integer,string> is incompatible with the type double|integer|string expected by parameter $values of sprintf(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

83
            $element = sprintf("\e[38;2;%sm%%s\e[39m", /** @scrutinizer ignore-type */ $item);
Loading history...
84
            yield $this->createFrame($element);
85
        }
86
    }
87
88
    /**
89
     * @return Traversable<string>
90
     */
91
    private function ansi24Sequence(): Traversable
92
    {
93
        yield from $this->ansi24part1();
94
        yield from $this->ansi24part2();
95
        yield from $this->ansi24part3();
96
    }
97
98
    /**
99
     * @return Traversable<string>
100
     */
101
    private function ansi24part1(): Traversable
102
    {
103
        yield from [
104
            '255;0;0',
105
            '255;4;0',
106
            '255;8;0',
107
            '255;12;0',
108
            '255;16;0',
109
            '255;21;0',
110
            '255;25;0',
111
            '255;29;0',
112
            '255;33;0',
113
            '255;38;0',
114
            '255;42;0',
115
            '255;46;0',
116
            '255;50;0',
117
            '255;55;0',
118
            '255;59;0',
119
            '255;63;0',
120
            '255;67;0',
121
            '255;72;0',
122
            '255;76;0',
123
            '255;80;0',
124
            '255;84;0',
125
            '255;89;0',
126
            '255;93;0',
127
            '255;97;0',
128
            '255;102;0',
129
            '255;106;0',
130
            '255;110;0',
131
            '255;114;0',
132
            '255;119;0',
133
            '255;123;0',
134
            '255;127;0',
135
            '255;131;0',
136
            '255;136;0',
137
            '255;140;0',
138
            '255;144;0',
139
            '255;148;0',
140
            '255;153;0',
141
            '255;157;0',
142
            '255;161;0',
143
            '255;165;0',
144
            '255;170;0',
145
            '255;174;0',
146
            '255;178;0',
147
            '255;182;0',
148
            '255;187;0',
149
            '255;191;0',
150
            '255;195;0',
151
            '255;199;0',
152
            '255;204;0',
153
            '255;208;0',
154
            '255;212;0',
155
            '255;216;0',
156
            '255;220;0',
157
            '255;225;0',
158
            '255;229;0',
159
            '255;233;0',
160
            '255;238;0',
161
            '255;242;0',
162
            '255;246;0',
163
            '255;250;0',
164
            '255;255;0',
165
            '250;255;0',
166
            '246;255;0',
167
            '242;255;0',
168
            '238;255;0',
169
            '233;255;0',
170
            '229;255;0',
171
            '225;255;0',
172
            '221;255;0',
173
            '216;255;0',
174
            '212;255;0',
175
            '208;255;0',
176
            '203;255;0',
177
            '199;255;0',
178
            '195;255;0',
179
            '191;255;0',
180
            '187;255;0',
181
            '182;255;0',
182
            '178;255;0',
183
            '174;255;0',
184
            '170;255;0',
185
            '165;255;0',
186
            '161;255;0',
187
            '157;255;0',
188
            '153;255;0',
189
            '148;255;0',
190
            '144;255;0',
191
            '140;255;0',
192
            '136;255;0',
193
            '131;255;0',
194
            '127;255;0',
195
            '123;255;0',
196
            '119;255;0',
197
            '114;255;0',
198
            '110;255;0',
199
            '106;255;0',
200
            '101;255;0',
201
            '97;255;0',
202
            '93;255;0',
203
            '89;255;0',
204
            '84;255;0',
205
            '80;255;0',
206
            '76;255;0',
207
            '72;255;0',
208
            '68;255;0',
209
            '63;255;0',
210
            '59;255;0',
211
            '55;255;0',
212
            '51;255;0',
213
            '46;255;0',
214
            '42;255;0',
215
            '38;255;0',
216
            '33;255;0',
217
            '29;255;0',
218
            '25;255;0',
219
            '21;255;0',
220
            '16;255;0',
221
            '12;255;0',
222
            '8;255;0',
223
            '4;255;0',
224
        ];
225
    }
226
227
    /**
228
     * @return Traversable<string>
229
     */
230
    private function ansi24part2(): Traversable
231
    {
232
        yield from [
233
            '0;255;0',
234
            '0;255;4',
235
            '0;255;8',
236
            '0;255;12',
237
            '0;255;16',
238
            '0;255;21',
239
            '0;255;25',
240
            '0;255;29',
241
            '0;255;33',
242
            '0;255;38',
243
            '0;255;42',
244
            '0;255;46',
245
            '0;255;50',
246
            '0;255;55',
247
            '0;255;59',
248
            '0;255;63',
249
            '0;255;67',
250
            '0;255;72',
251
            '0;255;76',
252
            '0;255;80',
253
            '0;255;85',
254
            '0;255;89',
255
            '0;255;93',
256
            '0;255;97',
257
            '0;255;102',
258
            '0;255;106',
259
            '0;255;110',
260
            '0;255;114',
261
            '0;255;119',
262
            '0;255;123',
263
            '0;255;127',
264
            '0;255;131',
265
            '0;255;135',
266
            '0;255;140',
267
            '0;255;144',
268
            '0;255;148',
269
            '0;255;153',
270
            '0;255;157',
271
            '0;255;161',
272
            '0;255;165',
273
            '0;255;169',
274
            '0;255;174',
275
            '0;255;178',
276
            '0;255;182',
277
            '0;255;187',
278
            '0;255;191',
279
            '0;255;195',
280
            '0;255;199',
281
            '0;255;203',
282
            '0;255;208',
283
            '0;255;212',
284
            '0;255;216',
285
            '0;255;221',
286
            '0;255;225',
287
            '0;255;229',
288
            '0;255;233',
289
            '0;255;237',
290
            '0;255;242',
291
            '0;255;246',
292
            '0;255;250',
293
            '0;255;255',
294
            '0;250;255',
295
            '0;246;255',
296
            '0;242;255',
297
            '0;238;255',
298
            '0;233;255',
299
            '0;229;255',
300
            '0;225;255',
301
            '0;220;255',
302
            '0;216;255',
303
            '0;212;255',
304
            '0;208;255',
305
            '0;203;255',
306
            '0;199;255',
307
            '0;195;255',
308
            '0;191;255',
309
            '0;187;255',
310
            '0;182;255',
311
            '0;178;255',
312
            '0;174;255',
313
            '0;169;255',
314
            '0;165;255',
315
            '0;161;255',
316
            '0;157;255',
317
            '0;153;255',
318
            '0;148;255',
319
            '0;144;255',
320
            '0;140;255',
321
            '0;136;255',
322
            '0;131;255',
323
            '0;127;255',
324
            '0;123;255',
325
            '0;119;255',
326
            '0;114;255',
327
            '0;110;255',
328
            '0;106;255',
329
            '0;102;255',
330
            '0;97;255',
331
            '0;93;255',
332
            '0;89;255',
333
            '0;84;255',
334
            '0;80;255',
335
            '0;76;255',
336
            '0;72;255',
337
            '0;67;255',
338
            '0;63;255',
339
            '0;59;255',
340
            '0;55;255',
341
            '0;51;255',
342
            '0;46;255',
343
            '0;42;255',
344
            '0;38;255',
345
            '0;33;255',
346
            '0;29;255',
347
            '0;25;255',
348
            '0;21;255',
349
            '0;16;255',
350
            '0;12;255',
351
            '0;8;255',
352
            '0;4;255',
353
        ];
354
    }
355
356
    /**
357
     * @return Traversable<string>
358
     */
359
    private function ansi24part3(): Traversable
360
    {
361
        yield from [
362
            '0;0;255',
363
            '4;0;255',
364
            '8;0;255',
365
            '12;0;255',
366
            '16;0;255',
367
            '21;0;255',
368
            '25;0;255',
369
            '29;0;255',
370
            '33;0;255',
371
            '38;0;255',
372
            '42;0;255',
373
            '46;0;255',
374
            '50;0;255',
375
            '55;0;255',
376
            '59;0;255',
377
            '63;0;255',
378
            '67;0;255',
379
            '72;0;255',
380
            '76;0;255',
381
            '80;0;255',
382
            '84;0;255',
383
            '89;0;255',
384
            '93;0;255',
385
            '97;0;255',
386
            '101;0;255',
387
            '106;0;255',
388
            '110;0;255',
389
            '114;0;255',
390
            '119;0;255',
391
            '123;0;255',
392
            '127;0;255',
393
            '131;0;255',
394
            '135;0;255',
395
            '140;0;255',
396
            '144;0;255',
397
            '148;0;255',
398
            '153;0;255',
399
            '157;0;255',
400
            '161;0;255',
401
            '165;0;255',
402
            '170;0;255',
403
            '174;0;255',
404
            '178;0;255',
405
            '182;0;255',
406
            '187;0;255',
407
            '191;0;255',
408
            '195;0;255',
409
            '199;0;255',
410
            '204;0;255',
411
            '208;0;255',
412
            '212;0;255',
413
            '216;0;255',
414
            '221;0;255',
415
            '225;0;255',
416
            '229;0;255',
417
            '233;0;255',
418
            '238;0;255',
419
            '242;0;255',
420
            '246;0;255',
421
            '250;0;255',
422
            '255;0;255',
423
            '255;0;250',
424
            '255;0;246',
425
            '255;0;242',
426
            '255;0;238',
427
            '255;0;233',
428
            '255;0;229',
429
            '255;0;225',
430
            '255;0;221',
431
            '255;0;216',
432
            '255;0;212',
433
            '255;0;208',
434
            '255;0;203',
435
            '255;0;199',
436
            '255;0;195',
437
            '255;0;191',
438
            '255;0;187',
439
            '255;0;182',
440
            '255;0;178',
441
            '255;0;174',
442
            '255;0;170',
443
            '255;0;165',
444
            '255;0;161',
445
            '255;0;157',
446
            '255;0;152',
447
            '255;0;148',
448
            '255;0;144',
449
            '255;0;140',
450
            '255;0;135',
451
            '255;0;131',
452
            '255;0;127',
453
            '255;0;123',
454
            '255;0;119',
455
            '255;0;114',
456
            '255;0;110',
457
            '255;0;106',
458
            '255;0;102',
459
            '255;0;97',
460
            '255;0;93',
461
            '255;0;89',
462
            '255;0;85',
463
            '255;0;80',
464
            '255;0;76',
465
            '255;0;72',
466
            '255;0;67',
467
            '255;0;63',
468
            '255;0;59',
469
            '255;0;55',
470
            '255;0;51',
471
            '255;0;46',
472
            '255;0;42',
473
            '255;0;38',
474
            '255;0;34',
475
            '255;0;29',
476
            '255;0;25',
477
            '255;0;21',
478
            '255;0;16',
479
            '255;0;12',
480
            '255;0;8',
481
            '255;0;4',
482
        ];
483
    }
484
}
485