AbstractModalTwigExtension::adminBSBModalHeader()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the adminbsb-material-design-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\AdminBSBBundle\Twig\Extension\UI;
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 modal Twig extension.
22
 *
23
 * @author webeweb <https://github.com/webeweb/>
24
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension\UI
25
 * @abstract
26
 */
27
abstract class AbstractModalTwigExtension 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 modal header.
44
     *
45
     * @param string $content The content.
46
     * @param string|null $icon The icon.
47
     * @return string Returns the AdminBSB modal header.
48
     */
49
    protected function adminBSBModalHeader(string $content, ?string $icon): string {
50
51
        $innerHTML = $content;
52
        if (null !== $icon) {
53
            $innerHTML = RendererTwigExtension::renderIcon($this->getTwigEnvironment(), $icon, "margin: -4px 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...
54
        }
55
56
        return $this->getTypographyTwigExtension()->bootstrapHeading3Function(["class" => "modal-title", "content" => $innerHTML]);
57
    }
58
}
59