Passed
Push — comment-flagging ( 6669bb...9d978e )
by Simon
06:56 queued 02:53
created

smarty_function_defaultsort()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 22
rs 9.2222
cc 6
nc 6
nop 2
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
/**
10
 * Sets up the cookie-based default sorting on request tables
11
 *
12
 * @param                          $params
13
 * @param Smarty_Internal_Template $template
14
 *
15
 * @return string
16
 */
17
function smarty_function_defaultsort($params, Smarty_Internal_Template $template)
0 ignored issues
show
Unused Code introduced by
The parameter $template is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

17
function smarty_function_defaultsort($params, /** @scrutinizer ignore-unused */ Smarty_Internal_Template $template)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
{
19
    if (empty($params['id'])) {
20
        return "";
21
    }
22
23
    $attr = 'data-sortname="' . htmlspecialchars($params['id'], ENT_QUOTES) . '"';
24
25
    if (empty($params['req'])) {
26
        return $attr;
27
    }
28
29
    if ($params['dir'] !== 'asc' && $params['dir'] !== 'desc') {
30
        $params['dir'] = 'asc';
31
    }
32
33
    $sort = '';
34
    if ($params['req'] === $params['id']) {
35
        $sort = ' data-defaultsort="' . htmlspecialchars($params['dir'], ENT_QUOTES) . '"';
36
    }
37
38
    return $attr . $sort;
39
}