Sort   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
c 0
b 0
f 0
dl 0
loc 28
rs 10
ccs 8
cts 9
cp 0.8889

1 Method

Rating   Name   Duplication   Size   Complexity  
A sort() 0 15 4
1
<?php
2
3
namespace mQueue\View\Helper;
4
5
use Zend_View_Helper_Abstract;
6
7
class Sort extends Zend_View_Helper_Abstract
8
{
9
    /**
10
     * Return an HTML links to be able to sort (will typically be in table header)
11
     *
12
     * @param string $label
13
     * @param string $column
14
     * @param string $selectedSortKey
15
     * @param string $selectedSortOrder
16
     * @param array $additionalParameters
17
     *
18
     * @return string
19
     */
20 1
    public function sort($label, $column, $selectedSortKey, $selectedSortOrder, array $additionalParameters = null)
21
    {
22 1
        if ($additionalParameters === null) {
23
            $additionalParameters = [];
24
        }
25
26 1
        $orders = ['desc' => 'asc', 'asc' => 'desc'];
27 1
        if (!in_array($selectedSortOrder, $orders)) {
28 1
            $selectedSortOrder = reset($orders);
29
        }
30
31 1
        $url = $this->view->urlParams(array_merge($additionalParameters, ['sort' => $column, 'sortOrder' => $orders[$selectedSortOrder]]));
32 1
        $result = '<a class="sort ' . ($column == $selectedSortKey ? $selectedSortOrder : '') . '" title="' . $this->view->escape($this->view->translate('Sort by "%s"', [$label])) . '" href="' . $url . '">' . $this->view->escape($label) . '</a>';
33
34 1
        return $result;
35
    }
36
}
37