Passed
Push — master ( afdc6b...e39cc4 )
by Adrien
03:24
created

AlternateFormats   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 18
c 0
b 0
f 0
dl 0
loc 41
ccs 0
cts 17
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A alternateFormats() 0 22 5
1
<?php
2
3
namespace mQueue\View\Helper;
4
5
use Zend_Registry;
6
use Zend_View_Helper_Abstract;
7
8
class AlternateFormats extends Zend_View_Helper_Abstract
9
{
10
    protected static $supportedFormats = [
11
        'rss' => [
12
            'name' => 'RSS',
13
        ],
14
        'csv' => [
15
            'name' => 'CSV',
16
        ],
17
    ];
18
19
    /**
20
     * Returns a string of HTML links for end-user, and also append 'alternate' links to HTML header
21
     *
22
     * @param array $formats
23
     * @param string $title
24
     *
25
     * @return string
26
     */
27
    public function alternateFormats(array $formats, $title = null)
28
    {
29
        $formatLinks = [];
30
        foreach ($formats as $format => $url) {
31
            // Inject format and locale parameters
32
            if (mb_strpos($url, '?') === false) {
33
                $url .= '?';
34
            } else {
35
                $url .= '&';
36
            }
37
38
            $url .= 'format=' . $format . '&lang=' . Zend_Registry::get('Zend_Locale')->getLanguage();
39
40
            $formatLinks[] = '<a class="' . $format . '" href="' . $url . '">' . self::$supportedFormats[$format]['name'] . '</a>';
41
            if ($title && isset(self::$supportedFormats[$format]['mime'])) {
42
                $this->view->headLink()->appendAlternate($url, self::$supportedFormats[$format]['mime'], $title);
43
            }
44
        }
45
46
        $result = '<p class="alternateFormats">' . $this->view->translate('Also available in:') . ' ' . implode(' | ', $formatLinks) . '</p>';
47
48
        return $result;
49
    }
50
}
51