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

LanguageLink   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 2
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
}