GridTwigExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 82
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrapGridFunction() 0 11 1
A bootstrapGridOffsetFunction() 0 3 1
A bootstrapGridPullFunction() 0 3 1
A bootstrapGridPushFunction() 0 3 1
A bootstrapGridStackedFunction() 0 3 1
A getFunctions() 0 9 1
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 Twig\TwigFunction;
15
use WBW\Library\Core\Argument\Helper\ArrayHelper;
16
17
/**
18
 * Grid Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\CSS
22
 * @link https://getbootstrap.com/docs/3.3/css/#grid
23
 */
24
class GridTwigExtension extends AbstractGridTwigExtension {
25
26
    /**
27
     * Service name.
28
     *
29
     * @var string
30
     */
31
    const SERVICE_NAME = "wbw.bootstrap.twig.extension.css.grid";
32
33
    /**
34
     * Displays a Bootstrap grid.
35
     *
36
     * @param array $args The arguments.
37
     * @return string Returns the Bootstrap grid.
38
     */
39
    public function bootstrapGridFunction(array $args = []): string {
40
41
        $output = [];
42
43
        $output[] = $this->bootstrapGridStackedFunction($args);
44
        $output[] = $this->bootstrapGridOffsetFunction($args);
45
        $output[] = $this->bootstrapGridPushFunction($args);
46
        $output[] = $this->bootstrapGridPullFunction($args);
47
48
        return trim(implode(" ", $output));
49
    }
50
51
    /**
52
     * Displays a Bootstrap grid with offset.
53
     *
54
     * @param array $args The arguments.
55
     * @return string Returns the Bootstrap grid with offset.
56
     */
57
    public function bootstrapGridOffsetFunction(array $args = []): string {
58
        return $this->bootstrapGrid(ArrayHelper::get($args, "lgOffset"), ArrayHelper::get($args, "mdOffset"), ArrayHelper::get($args, "smOffset"), ArrayHelper::get($args, "xsOffset"), ArrayHelper::get($args, "recopyOffset", false), "offset");
59
    }
60
61
    /**
62
     * Displays a Bootstrap grid with pull.
63
     *
64
     * @param array $args The arguments.
65
     * @return string Returns the Bootstrap grid with pull.
66
     */
67
    public function bootstrapGridPullFunction(array $args = []): string {
68
        return $this->bootstrapGrid(ArrayHelper::get($args, "lgPull"), ArrayHelper::get($args, "mdPull"), ArrayHelper::get($args, "smPull"), ArrayHelper::get($args, "xsPull"), ArrayHelper::get($args, "recopyPull", false), "pull");
69
    }
70
71
    /**
72
     * Displays a Bootstrap grid with push.
73
     *
74
     * @param array $args The arguments.
75
     * @return string Returns the Bootstrap grid with push.
76
     */
77
    public function bootstrapGridPushFunction(array $args = []): string {
78
        return $this->bootstrapGrid(ArrayHelper::get($args, "lgPush"), ArrayHelper::get($args, "mdPush"), ArrayHelper::get($args, "smPush"), ArrayHelper::get($args, "xsPush"), ArrayHelper::get($args, "recopyPush", false), "push");
79
    }
80
81
    /**
82
     * Displays a Bootstrap grid with stacked-to-horizontal.
83
     *
84
     * @param array $args The arguments.
85
     * @return string Returns the Bootstrap grid with stacked-to-horizontal.
86
     */
87
    public function bootstrapGridStackedFunction(array $args = []): string {
88
        return $this->bootstrapGrid(ArrayHelper::get($args, "lg"), ArrayHelper::get($args, "md"), ArrayHelper::get($args, "sm"), ArrayHelper::get($args, "xs"), ArrayHelper::get($args, "recopy", false), "");
89
    }
90
91
    /**
92
     * Get the Twig functions.
93
     *
94
     * @return TwigFunction[] Returns the Twig functions.
95
     */
96
    public function getFunctions(): array {
97
        return [
98
            new TwigFunction("bootstrapGrid", [$this, "bootstrapGridFunction"], ["is_safe" => ["html"]]),
99
            new TwigFunction("bootstrapGridOffset", [$this, "bootstrapGridOffsetFunction"], ["is_safe" => ["html"]]),
100
            new TwigFunction("bootstrapGridPull", [$this, "bootstrapGridPullFunction"], ["is_safe" => ["html"]]),
101
            new TwigFunction("bootstrapGridPush", [$this, "bootstrapGridPushFunction"], ["is_safe" => ["html"]]),
102
            new TwigFunction("bootstrapGridStacked", [$this, "bootstrapGridStackedFunction"], ["is_safe" => ["html"]]),
103
        ];
104
    }
105
}
106