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

ReplaceTitle::mutate()   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 5
nop 1
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 ReplaceTitle.
13
 *
14
 * @author Ivan Barlog <[email protected]>
15
 */
16
class ReplaceTitle implements MutatorInterface, RenderableInterface
17
{
18
    use RenderableTrait;
19
20
    /** @var RenderBlock */
21
    private $renderBlock;
22
23
    public function __construct(RenderBlock $renderBlock)
24
    {
25
        $this->renderBlock = $renderBlock;
26
    }
27
28
    public function mutate(Handler $ajax): Handler
29
    {
30
        try {
31
            $title = $this->renderBlock->render($this->view, 'title', $this->parameters);
32
            $ajax->container('title')->html($title);
33
        } catch (AjaxcomException $exception) {
34
            // do nothing
35
        } finally {
36
            return $ajax;
37
        }
38
    }
39
}
40