AlternateFormats   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

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

1 Method

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