Completed
Push — master ( 7d0ef3...14c63c )
by WEBEWEB
03:01
created

AbstractGridTwigExtension   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 16
lcom 0
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
F bootstrapGrid() 0 27 15
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\Twig\Extension\CSS;
13
14
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension;
15
16
/**
17
 * Abstract grid Twig extension.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\CSS
21
 * @abstract
22
 */
23
abstract class AbstractGridTwigExtension extends AbstractBootstrapTwigExtension {
24
25
    /**
26
     * Constructor.
27
     */
28
    protected function __construct() {
29
        parent::__construct();
30
    }
31
32
    /**
33
     * Displays a Bootstrap grid.
34
     *
35
     * @param string $lg The large column size.
36
     * @param string $md The medium column size.
37
     * @param string $sm The small column size.
38
     * @param string $xs The extra-small column size.
39
     * @param string $recopy Recopy ?
40
     * @param string $prefix The column prefix.
41
     * @return string Returns the Bootstrap grid.
42
     */
43
    protected function bootstrapGrid($lg, $md, $sm, $xs, $recopy, $prefix) {
44
45
        // Initialize the values.
46
        $found  = null;
47
        $values = [&$lg, &$md, &$sm, &$xs];
48
49
        // Handle each value.
50
        foreach ($values as &$current) {
51
            if (1 <= $current && $current <= 12) {
52
                $found = $current;
53
            }
54
            if (null === $current && true === $recopy && null !== $found) {
55
                $current = $found;
56
            }
57
        }
58
59
        // Initialize the columns.
60
        $columns = [];
61
62
        $columns[] = 1 <= $lg && $lg <= 12 ? "col-lg-" . $prefix . $lg : null;
63
        $columns[] = 1 <= $md && $md <= 12 ? "col-md-" . $prefix . $md : null;
64
        $columns[] = 1 <= $sm && $sm <= 12 ? "col-sm-" . $prefix . $sm : null;
65
        $columns[] = 1 <= $xs && $xs <= 12 ? "col-xs-" . $prefix . $xs : null;
66
67
        // Return the columns.
68
        return trim(implode(" ", $columns));
69
    }
70
71
}
72