Passed
Push — master ( fe64ef...2e5fa1 )
by Ivan
02:01
created

ReplaceMetaTags::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\AjaxcomBundle\Mutation;
6
7
use Everlution\Ajaxcom\Handler;
8
use Everlution\AjaxcomBundle\AjaxcomException;
9
use Everlution\AjaxcomBundle\Service\RenderBlock;
10
11
/**
12
 * Class ReplaceMetaTags.
13
 *
14
 * @author Ivan Barlog <[email protected]>
15
 */
16
class ReplaceMetaTags implements MutatorInterface, RenderableInterface
17
{
18
    use RenderableTrait;
19
20
    /** @var RenderBlock */
21
    private $renderBlock;
22
    /** @var string */
23
    private $persistentClass;
24
25
    public function __construct(RenderBlock $renderBlock, string $persistentClass)
26
    {
27
        $this->renderBlock = $renderBlock;
28
        $this->persistentClass = $persistentClass;
29
    }
30
31
    public function mutate(Handler $ajax): Handler
32
    {
33
        $ajax->container(sprintf('meta:not(.%s)', $this->persistentClass))->remove();
34
35
        try {
36
            $metaTags = $this->renderBlock->render($this->view, 'metatags', $this->parameters);
37
            $ajax->container('meta:last-of-type')->insertAfter($metaTags);
38
        } catch (AjaxcomException $exception) {
39
            // do nothing
40
        } finally {
41
            return $ajax;
42
        }
43
    }
44
}
45