Completed
Push — master ( 8d04e0...512520 )
by Vladimir
01:29
created

ViewHelper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 74
rs 10
c 0
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.
26
     * This method should use in loops.
27
     *
28
     * @param string $right CSS class for right block.
29
     * @param string $left CSS class for left block.
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
     * @return bool
43
     */
44
    public static function isLast($total)
45
    {
46
        static $current = 0;
47
        return (++$current) === $total;
48
    }
49
50
    /**
51
     * If number less than 9 before this number will be added zero.
52
     *
53
     * @param int|string $number
54
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
55
     */
56
    public static function zeroNumber($number)
57
    {
58
        return ($number < 10) ? ('0' . $number) : $number;
59
    }
60
61
    /**
62
     * Generates even numbers.
63
     *
64
     * @return int Returns even number.
65
     */
66
    public static function evenNumber()
67
    {
68
        static $number = 0;
69
        $current = $number;
70
        $number += 2;
71
72
        return $current;
73
    }
74
75
    /**
76
     * Generates odd numbers.
77
     *
78
     * @return int Returns add number.
79
     */
80
    public static function oddNumber()
81
    {
82
        static $number = 1;
83
        $current = $number;
84
        $number += 2;
85
86
        return $current;
87
    }
88
}
89