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

GridHelper::getCSSClassname()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.8657
c 0
b 0
f 0
cc 6
nc 5
nop 5
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
}