ReplaceTitle::mutate()   A
last analyzed

Complexity

Conditions 2
Paths 5

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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