Completed
Push — master ( 2d0ab0...3edfb6 )
by Adrien
03:09
created

AlternateFormats   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
ccs 12
cts 12
cp 1
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
     *
22
     * @param array $formats
23
     * @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...
24
     *
25
     * @return string
26
     */
27 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...
28
    {
29 4
        $formatLinks = [];
30 4
        foreach ($formats as $format => $url) {
31
            // Inject format and locale parameters
32 4
            if (mb_strpos($url, '?') === false) {
33 3
                $url .= '?';
34
            } else {
35 1
                $url .= '&';
36
            }
37
38 4
            $url .= 'format=' . $format . '&lang=' . Zend_Registry::get('Zend_Locale')->getLanguage();
39
40 4
            $formatLinks[] = '<a class="' . $format . '" href="' . $url . '">' . self::$supportedFormats[$format]['name'] . '</a>';
41 4
            if ($title && isset(self::$supportedFormats[$format]['mime'])) {
42 4
                $this->view->headLink()->appendAlternate($url, self::$supportedFormats[$format]['mime'], $title);
43
            }
44
        }
45
46 4
        $result = '<p class="alternateFormats">' . $this->view->translate('Also available in:') . ' ' . implode(' | ', $formatLinks) . '</p>';
47
48 4
        return $result;
49
    }
50
}
51