ViewHelper   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 76
rs 10
c 2
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A sideCssClass() 0 5 2
A isLast() 0 5 1
A zeroNumber() 0 4 2
A evenNumber() 0 8 1
A oddNumber() 0 8 1
1
<?php
2
/**
3
 * @link https://github.com/yiimaker/yii2-helpers
4
 * @copyright Copyright (c) 2017 Yii Maker
5
 * @license BSD 3-Clause License
6
 */
7
8
namespace ymaker\helpers;
9
10
/**
11
 * View helper.
12
 *
13
 * @author Vladimir Kuprienko <[email protected]>
14
 */
15
class ViewHelper
16
{
17
    /**
18
     * This class should not be instantiate.
19
     */
20
    private function __construct()
21
    {
22
    }
23
24
    /**
25
     * Returns side CSS class for block. This method should use in loops.
26
     *
27
     * @param string $right CSS class for right block.
28
     * @param string $left  CSS class for left block.
29
     *
30
     * @return string
31
     */
32
    public static function sideCssClass($right = 'right', $left = 'left')
33
    {
34
        static $index = 0;
35
        return ($index++ % 2 == 0) ? $right : $left;
36
    }
37
38
    /**
39
     * Check whether is last iteration of the loop.
40
     *
41
     * @param int $total
42
     *
43
     * @return bool
44
     */
45
    public static function isLast($total)
46
    {
47
        static $current = 0;
48
        return (++$current) === $total;
49
    }
50
51
    /**
52
     * If number less than 9 before this number will be added zero.
53
     *
54
     * @param int|string $number
55
     *
56
     * @return int|string
57
     */
58
    public static function zeroNumber($number)
59
    {
60
        return ($number < 10) ? ('0' . $number) : $number;
61
    }
62
63
    /**
64
     * Generates even numbers.
65
     *
66
     * @return int Returns even number.
67
     */
68
    public static function evenNumber()
69
    {
70
        static $number = 0;
71
        $current = $number;
72
        $number += 2;
73
74
        return $current;
75
    }
76
77
    /**
78
     * Generates odd numbers.
79
     *
80
     * @return int Returns add number.
81
     */
82
    public static function oddNumber()
83
    {
84
        static $number = 1;
85
        $current = $number;
86
        $number += 2;
87
88
        return $current;
89
    }
90
}
91