Passed
Push — master ( f1bbc8...8d94c2 )
by Gabor
06:08
created

TranslateFilter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 77
ccs 0
cts 31
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 4 1
A getDefinition() 0 4 1
A getDescription() 0 4 1
A getOptions() 0 4 1
A __invoke() 0 13 2
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Renderer\Filter;
15
16
use WebHemi\Configuration\ServiceInterface as ConfigurationInterface;
17
use WebHemi\Environment\ServiceInterface as EnvironmentInterface;
18
use WebHemi\I18n\DriverInterface;
19
use WebHemi\Renderer\FilterInterface;
20
21
/**
22
 * Class TranslateFilter
23
 */
24
class TranslateFilter implements FilterInterface
25
{
26
    /** @var DriverInterface */
27
    private $driver;
28
29
    /**
30
     * TranslateFilter constructor.
31
     *
32
     * @param DriverInterface $driver
33
     */
34
    public function __construct(DriverInterface $driver)
35
    {
36
        $this->driver = $driver;
37
    }
38
39
    /**
40
     * Should return the name of the helper.
41
     *
42
     * @return string
43
     */
44
    public static function getName() : string
45
    {
46
        return 't';
47
    }
48
49
    /**
50
     * Should return the definition of the helper.
51
     *
52
     * @return string
53
     */
54
    public static function getDefinition() : string
55
    {
56
        return '{{ "Some %s in English"|t("idea") }}';
57
    }
58
59
    /**
60
     * Should return a description text.
61
     *
62
     * @return string
63
     */
64
    public static function getDescription() : string
65
    {
66
        return 'Translates the text into the language configured for the application.';
67
    }
68
69
    /**
70
     * Gets filter options for the render.
71
     *
72
     * @return array
73
     */
74
    public static function getOptions() : array
75
    {
76
        return [];
77
    }
78
79
    /**
80
     * Parses the input text as a markdown script and outputs the HTML.
81
     *
82
     * @uses TagParserFilter::getCurrentUri()
83
     *
84
     * @param string
85
     * @return string
86
     */
87
    public function __invoke() : string
88
    {
89
        $arguments = func_get_args() ?? [];
90
        $text = array_shift($arguments);
91
        $text = $this->driver->translate($text);
92
93
        if (!empty($arguments)) {
94
            array_unshift($arguments, $text);
95
            $text = call_user_func_array('sprintf', $arguments);
96
        }
97
98
        return $text;
99
    }
100
}
101