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

ErrorMessageFormatter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 16
ccs 8
cts 11
cp 0.7272
rs 10
wmc 5

1 Method

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