Completed
Push — master ( cff333...106755 )
by WEBEWEB
01:23
created

GridHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 40
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getCSSClassname() 0 27 6
1
<?php
2
3
/*
4
 * This file is part of the bootstrap-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\BootstrapBundle\Helper;
13
14
/**
15
 * Grid helper.
16
 *
17
 * @author webeweb <https://github.com/webeweb/>
18
 * @package WBW\Bundle\BootstrapBundle\Helper
19
 */
20
class GridHelper {
21
22
    /**
23
     * Get a CSS classname.
24
     *
25
     * @param string $size The size.
26
     * @param int $value The value.
27
     * @param string $suffix The suffix.
28
     * @param int $min The min value.
29
     * @param int $max The max value.
30
     * @return string Returns the CSS classname.
31
     */
32
    public static function getCSSClassname($size, $value, $suffix, $min = 1, $max = 12) {
33
34
        // Check the value.
35
        if ($value < $min || $max < $value) {
36
            return "";
37
        }
38
39
        // Initialize the values.
40
        $sizes    = ["lg", "md", "sm", "xs"];
41
        $suffixes = ["offset", "pull", "push", ""];
42
43
        // Check the size.
44
        if (false === in_array($size, $sizes)) {
45
            return "";
46
        }
47
48
        // Check the suffixes.
49
        if (false === in_array($suffix, $suffixes)) {
50
            return "";
51
        }
52
        if ("" !== $suffix) {
53
            $suffix .= "-";
54
        }
55
56
        // Returns the classname.
57
        return implode("-", ["col", $size, $suffix . $value]);
58
    }
59
}