AbstractCardTwigExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A adminBSBCardHeader() 0 12 3
1
<?php
2
3
/*
4
 * This file is part of the adminbsb-material-design-bundle package.
5
 *
6
 * (c) 2017 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\AdminBSBBundle\Twig\Extension\Widget;
13
14
use Twig\Environment;
15
use WBW\Bundle\AdminBSBBundle\Twig\Extension\AbstractTwigExtension;
16
use WBW\Bundle\AdminBSBBundle\Twig\Extension\RendererTwigExtension;
17
use WBW\Bundle\AdminBSBBundle\Twig\Extension\Typography\TypographyTwigExtension;
18
use WBW\Bundle\AdminBSBBundle\Twig\Extension\Typography\TypographyTwigExtensionTrait;
19
20
/**
21
 * Abstract card twig extension.
22
 *
23
 * @author webeweb <https://github.com/webeweb/>
24
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension\Widget
25
 * @abstract
26
 */
27
abstract class AbstractCardTwigExtension extends AbstractTwigExtension {
28
29
    use TypographyTwigExtensionTrait;
30
31
    /**
32
     * Constructor.
33
     *
34
     * @param Environment $twigEnvironment The Twig environment.
35
     * @param TypographyTwigExtension $typographyTwigExtension The Typography Twig extension.
36
     */
37
    public function __construct(Environment $twigEnvironment, TypographyTwigExtension $typographyTwigExtension) {
38
        parent::__construct($twigEnvironment);
39
        $this->setTypographyTwigExtension($typographyTwigExtension);
40
    }
41
42
    /**
43
     * Displays an AdminBSB card header.
44
     *
45
     * @param string $content The content.
46
     * @param string|null $description The description.
47
     * @param string|null $icon The icon.
48
     * @return string Returns the AdminBSB card header.
49
     */
50
    protected function adminBSBCardHeader(string $content, ?string $description, ?string $icon): string {
51
52
        $innerHTML = $content;
53
        if (null !== $description) {
54
            $innerHTML .= static::coreHTMLElement("small", $description);
55
        }
56
        if (null !== $icon) {
57
            $innerHTML = RendererTwigExtension::renderIcon($this->getTwigEnvironment(), $icon, "margin: -4px 4px 0 0; vertical-align: sub;") . $innerHTML;
0 ignored issues
show
Bug introduced by
It seems like $this->getTwigEnvironment() can be null; however, renderIcon() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
58
        }
59
60
        return $this->getTypographyTwigExtension()->bootstrapHeading2Function(["class" => "card-header", "content" => $innerHTML]);
61
    }
62
}
63