Completed
Push — master ( 67c65c...9a618a )
by WEBEWEB
06:47
created

AbstractImageTwigExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A bootstrapImage() 0 17 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\Image;
13
14
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension;
15
use WBW\Library\Core\Utility\StringUtility;
16
17
/**
18
 * Abstract image Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Image
22
 * @abstract
23
 */
24
abstract class AbstractImageTwigExtension extends AbstractBootstrapTwigExtension {
25
26
    /**
27
     * Constructor.
28
     */
29
    protected function __construct() {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Displays a Bootstrap image.
35
     *
36
     * @param string $src The image source
37
     * @param string $alt The image alternative.
38
     * @param string $width The image width.
39
     * @param string $height The image height.
40
     * @param string $class The image class.
41
     * @return string Returns the Bootstrap image.
42
     */
43
    protected function bootstrapImage($src, $alt, $width, $height, $class) {
44
45
        // Initialize the template.
46
        $template = "<img %attributes%/>";
47
48
        // Initialize the attributes.
49
        $attributes = [];
50
51
        $attributes["src"]    = $src;
52
        $attributes["alt"]    = $alt;
53
        $attributes["width"]  = $width;
54
        $attributes["height"] = $height;
55
        $attributes["class"]  = $class;
56
57
        // Return the HTML.
58
        return StringUtility::replace($template, ["%attributes%"], [StringUtility::parseArray($attributes)]);
59
    }
60
61
}
62