Passed
Push — master ( 57f3ff...f2fe82 )
by Melech
04:07
created

Message::asBanner()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 15
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[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 Valkyrja\Cli\Interaction\Message;
15
16
use Override;
0 ignored issues
show
Bug introduced by
The type Override 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
use Valkyrja\Cli\Interaction\Formatter\Contract\Formatter;
18
use Valkyrja\Cli\Interaction\Message\Contract\Message as Contract;
19
20
/**
21
 * Class Message.
22
 *
23
 * @author Melech Mizrachi
24
 */
25
class Message implements Contract
26
{
27
    /**
28
     * @param non-empty-string $text The text
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
29
     */
30
    public function __construct(
31
        protected string $text,
32
        protected Formatter|null $formatter = null
33
    ) {
34
    }
35
36
    /**
37
     * @inheritDoc
38
     *
39
     * @return non-empty-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
40
     */
41
    #[Override]
42
    public function getText(): string
43
    {
44
        return $this->text;
45
    }
46
47
    /**
48
     * @inheritDoc
49
     *
50
     * @return non-empty-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
51
     */
52
    #[Override]
53
    public function getFormattedText(): string
54
    {
55
        $text      = $this->getText();
56
        $formatter = $this->formatter;
57
58
        if ($formatter === null) {
59
            return $text;
60
        }
61
62
        return $formatter->formatText($text);
63
    }
64
65
    /**
66
     * @inheritDoc
67
     */
68
    #[Override]
69
    public function withText(string $text): static
70
    {
71
        $new = clone $this;
72
73
        $new->text = $text;
74
75
        return $new;
76
    }
77
78
    /**
79
     * @inheritDoc
80
     */
81
    #[Override]
82
    public function getFormatter(): Formatter|null
83
    {
84
        return $this->formatter;
85
    }
86
87
    /**
88
     * @inheritDoc
89
     */
90
    #[Override]
91
    public function withFormatter(Formatter|null $formatter): static
92
    {
93
        $new = clone $this;
94
95
        $new->formatter = $formatter;
96
97
        return $new;
98
    }
99
}
100