Test Failed
Pull Request — master (#19)
by Flo
04:22
created

LanguageLink::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
/**
3
 * Class LanguageLink | LanguageLink.php
4
 * @package Faulancer\View\Helper
5
 * @author  Florian Knapp <[email protected]>
6
 */
7
namespace Faulancer\View\Helper;
8
9
use Faulancer\Service\Config;
10
use Faulancer\View\AbstractViewHelper;
11
12
/**
13
 * Class LanguageLink
14
 */
15
class LanguageLink extends AbstractViewHelper
16
{
17
18
    protected $languageTextMapping = [
19
        'de' => 'Deutsch',
20
        'en' => 'English',
21
        'hr' => 'Hrvatski'
22
    ];
23
24
    public function __invoke()
25
    {
26
        /** @var Config $config */
27
        $config       = $this->getServiceLocator()->get(Config::class);
28
        $translations = $config->get('translation');
29
30
        $result  = [];
31
        $pattern = '<a rel="alternate" hreflang="%s" class="lang %s" href="?lang=%s">%s</a>';
32
33
        foreach ($translations as $key => $content) {
34
            $result[] = sprintf($pattern, strtolower($key), strtolower($key), $key, $this->languageTextMapping[$key]);
35
        }
36
37
        return implode('', $result);
38
    }
39
40
}