Test Failed
Pull Request — stable (#292)
by Victor
02:14 queued 22s
created

FigletString::parseOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Components\Logo;
15
16
use Zend\Text\Figlet\Figlet as ZendFiglet;
0 ignored issues
show
Bug introduced by
The type Zend\Text\Figlet\Figlet was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
/**
19
 * @internal
20
 */
21
final class FigletString
22
{
23
24
    private $string;
25
26
    private $figlet;
27
28
    public function __construct(string $name, $config)
29
    {
30
        $this->string = $name;
31
        $this->figlet = new ZendFiglet();
32
33
        $this->parseOptions($config);
34
    }
35
36
    private function parseOptions($config)
37
    {
38
        $this
39
            ->font($config->get('logo.font'))
40
            ->outputWidth($config->get('logo.outputWidth'))
41
            ->justification($config->get('logo.justification'))
42
            ->rightToLeft($config->get('logo.rightToLeft'));
43
    }
44
45
    private function font($font)
46
    {
47
        if (is_null($font)) {
48
            return $this;
49
        }
50
51
        $this->figlet->setFont($font);
52
53
        return $this;
54
    }
55
56
    private function outputWidth($outputWidth)
57
    {
58
        $this->figlet->setOutputWidth($outputWidth);
59
60
        return $this;
61
    }
62
63
    private function justification($justification)
64
    {
65
        switch ($justification) {
66
            case 'left':
67
                $this->figlet->setJustification(ZendFiglet::JUSTIFICATION_LEFT);
68
                break;
69
            case 'center':
70
                $this->figlet->setJustification(ZendFiglet::JUSTIFICATION_LEFT);
71
                break;
72
            case 'right':
73
                $this->figlet->setJustification(ZendFiglet::JUSTIFICATION_LEFT);
74
                break;
75
            case null:
76
                // Let ZendFiglet handle the justification
77
                break;
78
            default:
79
                throw new \InvalidArgumentException('Invalid value given for the `logo.justification` option');
80
        }
81
82
        return $this;
83
    }
84
85
    private function rightToLeft($rightToLeft)
86
    {
87
        switch ($rightToLeft) {
88
            case 'right-to-left':
89
                $this->figlet->setRightToLeft(ZendFiglet::DIRECTION_RIGHT_TO_LEFT);
90
                break;
91
            case 'left-to-right':
92
                $this->figlet->setRightToLeft(ZendFiglet::DIRECTION_LEFT_TO_RIGHT);
93
                break;
94
            case null:
95
                // Let ZendFiglet handle this
96
                break;
97
            default:
98
                throw new \InvalidArgumentException('Invalid value given for the `logo.rightToLeft` option');
99
        }
100
101
        return $this;
102
    }
103
104
    public function __toString()
105
    {
106
        $rendered = $this->figlet->render($this->string);
107
108
        return "\n$rendered\n";
109
    }
110
111
}