Passed
Push — master ( 955c83...94d693 )
by Alexander
02:18
created

Formatter::format()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 10
nc 5
nop 2
dl 0
loc 14
ccs 11
cts 11
cp 1
crap 5
rs 9.6111
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
class Formatter implements FormatterInterface
8
{
9 168
    public function format(string $message, array $parameters = []): string
10
    {
11 168
        $replacements = [];
12 168
        foreach ($parameters as $key => $value) {
13 71
            if (is_array($value)) {
14 1
                $value = 'array';
15 70
            } elseif (is_object($value)) {
16 2
                $value = 'object';
17 68
            } elseif (is_resource($value)) {
18 1
                $value = 'resource';
19
            }
20 71
            $replacements['{' . $key . '}'] = $value;
21
        }
22 168
        return strtr($message, $replacements);
23
    }
24
}
25