Passed
Pull Request — master (#99)
by Def
02:23
created

ErrorMessage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 32
ccs 14
cts 14
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getParameters() 0 3 1
A __construct() 0 5 1
A getMessage() 0 3 1
A __toString() 0 3 1
A getFormattedMessage() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
final class ErrorMessage
8
{
9
    private string $message = '';
10
    private array $parameters = [];
11
    private ErrorMessageFormatterInterface $formatter;
12
13 175
    public function __construct(string $message, array $parameters = [], ?ErrorMessageFormatterInterface $formatter = null)
14
    {
15 175
        $this->message = $message;
16 175
        $this->parameters = $parameters;
17 175
        $this->formatter = $formatter ?? new ErrorMessageFormatter();
18 175
    }
19
20 70
    public function getMessage(): string
21
    {
22 70
        return $this->message;
23
    }
24
25 70
    public function getParameters(): array
26
    {
27 70
        return $this->parameters;
28
    }
29
30 70
    public function getFormattedMessage(?ErrorMessageFormatterInterface $formatter = null): string
31
    {
32 70
        $formatter = $formatter ?? $this->formatter;
33 70
        return $formatter->format($this);
34
    }
35
36 69
    public function __toString(): string
37
    {
38 69
        return $this->getFormattedMessage();
39
    }
40
}
41