Completed
Push — sf/improvement-coverage ( b3937e...01a837 )
by Kiyotaka
51:20 queued 45:08
created

EccubeBlockExtension::getFunctions()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 1
nop 0
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
ccs 9
cts 9
cp 1
crap 3
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Twig\Extension;
15
16
use Twig\Environment;
17
use Twig\Extension\AbstractExtension;
18
use Twig\TwigFunction;
19
20
class EccubeBlockExtension extends AbstractExtension
21
{
22
    protected $twig;
23
24
    protected $blockTemplates;
25
26 472
    public function __construct(Environment $twig, array $blockTemplates)
27
    {
28 472
        $this->twig = $twig;
29 472
        $this->blockTemplates = $blockTemplates;
30
    }
31
32
    public function getFunctions()
33
    {
34
        return [
35 248
            new TwigFunction('eccube_block_*', function ($name, array $parameters = []) {
36 47
                $sources = $this->blockTemplates;
37 47
                foreach ($sources as $source) {
38 2
                    $template = $this->twig->loadTemplate($source);
39 2
                    if ($template->hasBlock($name, $parameters)) {
40 2
                        echo $template->renderBlock($name, $parameters);
41
42 2
                        return;
43
                    }
44
                }
45 45
                @trigger_error($name.' block is not found', E_USER_WARNING);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
46 248
            }, ['pre_escape' => 'html', 'is_safe' => ['html']]),
47
        ];
48
    }
49
}
50