GridHelper::getCSSClassname()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.0444
c 0
b 0
f 0
cc 6
nc 4
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|null $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|null Returns the CSS classname.
31
     */
32
    public static function getCSSClassname(string $size, ?int $value, string $suffix, int $min = 1, int $max = 12): ?string {
33
34
        if ($value < $min || $max < $value) {
35
            return null;
36
        }
37
38
        $sizes    = ["lg", "md", "sm", "xs"];
39
        $suffixes = ["offset", "pull", "push", ""];
40
41
        if (false === in_array($size, $sizes) || false === in_array($suffix, $suffixes)) {
42
            return null;
43
        }
44
        if ("" !== $suffix) {
45
            $suffix .= "-";
46
        }
47
48
        return implode("-", ["col", $size, $suffix . $value]);
49
    }
50
}
51