Test Failed
Pull Request — stable (#292)
by Victor
01:45
created

FigletString::rightToLeft()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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