Passed
Pull Request — master (#8)
by
unknown
04:03
created

AppendContent::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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\DataObject\Block;
10
use Everlution\AjaxcomBundle\Service\RenderBlock;
11
12
/**
13
 * Class AppendContent.
14
 * @author Robert Stribrnsky <[email protected]>
15
 */
16
class AppendContent implements MutatorInterface, RenderableInterface
17
{
18
    use RenderableTrait;
19
20
    /** @var Block */
21
    private $block;
22
    /** @var RenderBlock */
23
    private $renderBlock;
24
25
    public function __construct(RenderBlock $renderBlock)
26
    {
27
        $this->renderBlock = $renderBlock;
28
    }
29
30
    public function mutate(Handler $ajaxcom): Handler
31
    {
32
        try {
33
            $html = $this->renderBlock->render($this->block, $this->view, $this->parameters);
34
        } catch (AjaxcomException $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
35
36
        }
37
38
        $ajaxcom->container($this->block->getId())->append($html);
39
40
        return $ajaxcom;
41
    }
42
43
    public function add(string $id): self
44
    {
45
        $this->block = new Block($id);
46
47
        return $this;
48
    }
49
}
50