Completed
Branch master (2d0ab0)
by Adrien
07:23
created

AlternateFormats   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B alternateFormats() 0 23 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
     * @param array $formats
22
     * @param string $title
0 ignored issues
show
Documentation introduced by
Should the type for parameter $title not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
23
     * @return string
24
     */
25 4
    public function alternateFormats(array $formats, $title = null)
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
26
    {
27 4
        $formatLinks = [];
28 4
        foreach ($formats as $format => $url) {
29
            // Inject format and locale parameters
30 4
            if (mb_strpos($url, '?') === false) {
31 3
                $url .= '?';
32
            } else {
33 1
                $url .= '&';
34
            }
35
36 4
            $url .= 'format=' . $format . '&lang=' . Zend_Registry::get('Zend_Locale')->getLanguage();
37
38 4
            $formatLinks[] = '<a class="' . $format . '" href="' . $url . '">' . self::$supportedFormats[$format]['name'] . '</a>';
39 4
            if ($title && isset(self::$supportedFormats[$format]['mime'])) {
40
                $this->view->headLink()->appendAlternate($url, self::$supportedFormats[$format]['mime'], $title);
41
            }
42
        }
43
44 4
        $result = '<p class="alternateFormats">' . $this->view->translate('Also available in:') . ' ' . implode(' | ', $formatLinks) . '</p>';
45
46 4
        return $result;
47
    }
48
}
49