Passed
Pull Request — master (#258)
by Alexander
02:18
created

FallbackTranslator::withLocale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
use Yiisoft\Translator\CategorySource;
8
use Yiisoft\Translator\TranslatorInterface;
9
10
use function is_array;
11
use function is_object;
12
use function is_resource;
13
14
final class FallbackTranslator implements TranslatorInterface
15
{
16
    public function addCategorySource(CategorySource $category): void
17
    {
18
        // do nothing
19
    }
20
21
    public function addCategorySources(array $categories): void
22
    {
23
        // do nothing
24
    }
25
26
    public function setLocale(string $locale): void
27
    {
28
        // do nothing
29
    }
30
31
    public function getLocale(): string
32
    {
33
        return 'en';
34
    }
35
36 350
    public function translate(
37
        string $id,
38
        array $parameters = [],
39
        string $category = null,
40
        string $locale = null
41
    ): string {
42 350
        $replacements = [];
43 350
        foreach ($parameters as $key => $value) {
44 350
            if (is_array($value)) {
45 32
                $value = 'array';
46 350
            } elseif (is_object($value)) {
47 7
                $value = 'object';
48 350
            } elseif (is_resource($value)) {
49 1
                $value = 'resource';
50
            }
51 350
            $replacements['{' . $key . '}'] = $value;
52
        }
53 350
        return strtr($id, $replacements);
54
    }
55
56
    public function withCategory(string $category): TranslatorInterface
57
    {
58
        return $this;
59
    }
60
61
    public function withLocale(string $locale): TranslatorInterface
62
    {
63
        return $this;
64
    }
65
}
66