AjaxcomTrait   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 23
c 1
b 0
f 0
dl 0
loc 74
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A replaceBlockContent() 0 5 1
A refreshAjaxBlock() 0 5 1
A appendAjaxBlock() 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
A prependAjaxBlock() 0 5 1
A render() 0 9 2
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
 * The trait expects you provide a get($service) method,
17
 * for example via Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait
18
 */
19
trait AjaxcomTrait
20
{
21
    public function render($view, array $parameters = array(), Response $response = null): Response
22
    {
23
        $request = $this->get('request_stack')->getMasterRequest();
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        $request = $this->/** @scrutinizer ignore-call */ get('request_stack')->getMasterRequest();
Loading history...
24
25
        if ($request->server->get(Ajaxcom::AJAX_COM_HEADER, false)) {
26
            return $this->get('ajaxcom.handler')->handle($view, $parameters);
27
        }
28
29
        return parent::render($view, $parameters, $response);
30
    }
31
32
    protected function replaceBlockContent(string $selector, string $blockId): self
33
    {
34
        $this->get('ajaxcom.mutation.replace_content')->add($selector, $blockId);
35
36
        return $this;
37
    }
38
39
    protected function renderAjaxBlock(string $id): self
40
    {
41
        $this->get('ajaxcom.mutation.add_blocks')->add($id);
42
43
        return $this;
44
    }
45
46
    protected function refreshAjaxBlock(string $id): self
47
    {
48
        $this->get('ajaxcom.mutation.add_blocks')->refresh($id);
49
50
        return $this;
51
    }
52
53
    protected function removeAjaxBlock(string $selector): self
54
    {
55
        $this->get('ajaxcom.mutation.remove_blocks')->add($selector);
56
57
        return $this;
58
    }
59
60
    protected function addCallback(string $functionName, array $parameters = []): self
61
    {
62
        $this->get('ajaxcom.mutation.callbacks')->add(new Callback($functionName, $parameters));
63
64
        return $this;
65
    }
66
67
    protected function replaceClass(string $selector, string $class): self
68
    {
69
        $this->get('ajaxcom.mutation.replace_class')->add($selector, $class);
70
71
        return $this;
72
    }
73
74
    protected function doNotChangeUrl(): self
75
    {
76
        $this->get('ajaxcom.mutation.change_url')->doNotChangeUrl();
77
78
        return $this;
79
    }
80
81
    protected function appendAjaxBlock(string $id): self
82
    {
83
        $this->get('ajaxcom.mutation.append_blocks')->add($id);
84
85
        return $this;
86
    }
87
88
    protected function prependAjaxBlock(string $id): self
89
    {
90
        $this->get('ajaxcom.mutation.prepend_blocks')->add($id);
91
92
        return $this;
93
    }
94
}
95