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

ErrorMessage::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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 173
    public function __construct(string $message, array $parameters = [], ?ErrorMessageFormatterInterface $formatter = null)
14
    {
15 173
        $this->message = $message;
16 173
        $this->parameters = $parameters;
17 173
        $this->formatter = $formatter ?? new ErrorMessageFormatter();
18 173
    }
19
20 67
    public function getMessage(): string
21
    {
22 67
        return $this->message;
23
    }
24
25 67
    public function getParameters(): array
26
    {
27 67
        return $this->parameters;
28
    }
29
30 67
    public function getFormattedMessage(): string
31
    {
32 67
        return $this->formatter->format($this);
33
    }
34
35 66
    public function __toString(): string
36
    {
37 66
        return $this->getFormattedMessage();
38
    }
39
}
40