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

FallbackTranslator   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 64.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 13
c 1
b 0
f 0
dl 0
loc 50
ccs 11
cts 17
cp 0.6471
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A translate() 0 18 5
A getLocale() 0 3 1
A setLocale() 0 2 1
A withCategory() 0 3 1
A addCategorySource() 0 2 1
A addCategorySources() 0 2 1
A withLocale() 0 3 1
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