Passed
Pull Request — master (#99)
by Def
03:05 queued 46s
created

ErrorMessageFormatter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 76.92%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 18
ccs 10
cts 13
cp 0.7692
rs 10
c 1
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 16 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
final class ErrorMessageFormatter implements ErrorMessageFormatterInterface
8
{
9 81
    public function format(ErrorMessage $errorMessage): string
10
    {
11 81
        $replacements = [];
12 81
        foreach ($errorMessage->getParameters() as $key => $value) {
13 45
            if ($value instanceof ErrorMessage) {
14 1
                $value = $this->format($value);
15 45
            } elseif (is_array($value)) {
16
                $value = 'array';
17 45
            } elseif (is_object($value)) {
18
                $value = 'object';
19 45
            } elseif (is_resource($value)) {
20
                $value = 'resource';
21
            }
22 45
            $replacements['{' . $key . '}'] = $value;
23
        }
24 81
        return strtr($errorMessage->getMessage(), $replacements);
25
    }
26
}
27