Completed
Pull Request — development (#560)
by Thomas
09:56 queued 02:10
created

function.season.php ➔ smarty_function_season()   C

Complexity

Conditions 10
Paths 10

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 12
nc 10
nop 2
dl 0
loc 21
rs 6.6746
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Smarty plugin
4
 *
5
 * @package Smarty
6
 * @subpackage plugins
7
 ***
8
 * Smarty {season winter='...' spring='...' summer='...' autumn='...'} function plugin
9
 * @param $params
10
 * @param $smarty
11
 * @return mixed
12
 */
13
function smarty_function_season($params, &$smarty)
0 ignored issues
show
Unused Code introduced by
The parameter $smarty is not used and could be removed.

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

Loading history...
14
{
15
    $season = date('z');
16
    if (isset($params['season'])) {
17
        $season = $params['season'];
18
    }
19
20
    if ($season <= 81 || $season >= 355) {
21
        return $params['winter'];
22
    }
23
24
    if ($season >= 82 && $season <= 173) {
25
        return $params['spring'];
26
    }
27
    if ($season >= 174 && $season <= 264) {
28
        return $params['summer'];
29
    }
30
    if ($season >= 265 && $season <= 354) {
31
        return $params['autumn'];
32
    }
33
}
34