TwigRenderer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 21
ccs 7
cts 7
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 3
A render() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\TagBag\Renderer;
6
7
use Setono\TagBag\Tag\TagInterface;
8
use Setono\TagBag\Tag\TemplateTagInterface;
9
use Setono\TagBag\Tag\TwigTagInterface;
10
use Twig\Environment;
11
12
final class TwigRenderer implements RendererInterface
13
{
14
    /** @var Environment */
15
    private $environment;
16
17 3
    public function __construct(Environment $environment)
18
    {
19 3
        $this->environment = $environment;
20 3
    }
21
22 2
    public function supports(TagInterface $tag): bool
23
    {
24 2
        return $tag instanceof TwigTagInterface || ($tag instanceof TemplateTagInterface && $tag->getTemplateType() === 'twig');
25
    }
26
27
    /**
28
     * @param TemplateTagInterface|TagInterface $tag
29
     */
30 1
    public function render(TagInterface $tag): string
31
    {
32 1
        return $this->environment->render($tag->getTemplate(), $tag->getContext());
0 ignored issues
show
Bug introduced by
The method getContext() does not exist on Setono\TagBag\Tag\TagInterface. It seems like you code against a sub-type of Setono\TagBag\Tag\TagInterface such as Setono\TagBag\Tag\TemplateTagInterface or Setono\TagBag\Tag\TemplateTag. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        return $this->environment->render($tag->getTemplate(), $tag->/** @scrutinizer ignore-call */ getContext());
Loading history...
Bug introduced by
The method getTemplate() does not exist on Setono\TagBag\Tag\TagInterface. It seems like you code against a sub-type of Setono\TagBag\Tag\TagInterface such as Setono\TagBag\Tag\TemplateTagInterface or Setono\TagBag\Tag\TemplateTag. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        return $this->environment->render($tag->/** @scrutinizer ignore-call */ getTemplate(), $tag->getContext());
Loading history...
33
    }
34
}
35