StyleConverter::convert()   B
last analyzed

Complexity

Conditions 6
Paths 32

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 26
ccs 13
cts 13
cp 1
rs 8.439
cc 6
eloc 13
nc 32
nop 1
crap 6
1
<?php
2
3
/*
4
 * This file is part of the webmozart/console package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\Console\Adapter;
13
14
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
15
use Webmozart\Console\Api\Formatter\Style;
16
17
/**
18
 * Converts {@link Style} instances to Symfony's {@link OutputFormatterStyle}.
19
 *
20
 * @since  1.0
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24
class StyleConverter
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
25
{
26
    /**
27
     * Converts a {@link Style} instance to an {@link OutputFormatterStyle}.
28
     *
29
     * @param Style $style The style to convert.
30
     *
31
     * @return OutputFormatterStyle The converted style.
32
     */
33 259
    public static function convert(Style $style)
34
    {
35 259
        $options = array();
36
37 259
        if ($style->isBold()) {
38 237
            $options[] = 'bold';
39
        }
40
41 259
        if ($style->isBlinking()) {
42 1
            $options[] = 'blink';
43
        }
44
45 259
        if ($style->isUnderlined()) {
46 231
            $options[] = 'underscore';
47
        }
48
49 259
        if ($style->isInverse()) {
50 1
            $options[] = 'reverse';
51
        }
52
53 259
        if ($style->isHidden()) {
54 2
            $options[] = 'conceal';
55
        }
56
57 259
        return new OutputFormatterStyle($style->getForegroundColor(), $style->getBackgroundColor(), $options);
58
    }
59
60
    private function __construct()
61
    {
62
    }
63
}
64