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

AbstractGridTwigExtension::bootstrapGrid()   F

Complexity

Conditions 15
Paths 1280

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 1.7499
c 0
b 0
f 0
cc 15
nc 1280
nop 6

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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