Passed
Push — master ( 98c791...98aa4d )
by Ivan
03:51
created

AjaxcomTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
dl 0
loc 63
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 9 2
A replaceBlockContent() 0 5 1
A refreshAjaxBlock() 0 5 1
A replaceClass() 0 5 1
A doNotChangeUrl() 0 5 1
A removeAjaxBlock() 0 5 1
A renderAjaxBlock() 0 5 1
A addCallback() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\AjaxcomBundle\Controller;
6
7
use Everlution\AjaxcomBundle\DataObject\Callback;
8
use Everlution\AjaxcomBundle\Service\Ajaxcom;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * Class BaseController.
13
 *
14
 * @author Ivan Barlog <[email protected]>
15
 */
16
trait AjaxcomTrait
17
{
18
    public function render($view, array $parameters = array(), Response $response = null): Response
19
    {
20
        $request = $this->get('request_stack')->getMasterRequest();
21
22
        if ($request->server->get(Ajaxcom::AJAX_COM_HEADER, false)) {
23
            return $this->get('ajaxcom.handler')->handle($view, $parameters);
24
        }
25
26
        return parent::render($view, $parameters, $response);
27
    }
28
29
    protected function replaceBlockContent(string $selector, string $blockId): self
30
    {
31
        $this->get('ajaxcom.mutation.replace_content')->add($selector, $blockId);
32
33
        return $this;
34
    }
35
36
    protected function renderAjaxBlock(string $id): self
37
    {
38
        $this->get('ajaxcom.mutation.add_blocks')->add($id);
39
40
        return $this;
41
    }
42
43
    protected function refreshAjaxBlock(string $id): self
44
    {
45
        $this->get('ajaxcom.mutation.add_blocks')->refresh($id);
46
47
        return $this;
48
    }
49
50
    protected function removeAjaxBlock(string $selector): self
51
    {
52
        $this->get('ajaxcom.mutation.remove_blocks')->add($selector);
53
54
        return $this;
55
    }
56
57
    protected function addCallback(string $functionName, array $parameters = []): self
58
    {
59
        $this->get('ajaxcom.mutation.callbacks')->add(new Callback($functionName, $parameters));
60
61
        return $this;
62
    }
63
64
    protected function replaceClass(string $selector, string $class): self
65
    {
66
        $this->get('ajaxcom.mutation.replace_class')->add($selector, $class);
67
68
        return $this;
69
    }
70
71
    protected function doNotChangeUrl(): self
72
    {
73
        $this->get('ajaxcom.mutation.change_url')->doNotChangeUrl();
74
75
        return $this;
76
    }
77
78
    abstract protected function get($id);
79
}
80