Completed
Push — master ( b64488...0289b2 )
by Klochok
14:29
created

HookTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 0
dl 0
loc 18
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace hipanel\widgets;
4
5
use hipanel\actions\Action;
6
use yii\helpers\Json;
7
use yii\web\View;
8
9
trait HookTrait
10
{
11
    public ?string $url = null;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?', expecting T_FUNCTION or T_CONST
Loading history...
12
13
    public function registerJsHook(string $reqHeaderParamName): void
14
    {
15
        $id = $this->getId();
16
        $headerName = Action::EXPECTED_AJAX_RESPONSE_HEADER_NAME;
17
        $url = $this->url ? Json::encode($this->url) : 'document.URL';
18
        $this->view->registerJs("$.ajax({
19
           type: 'GET',
20
           url: {$url},
21
           beforeSend: xhr => {
22
             xhr.setRequestHeader('{$headerName}', '{$reqHeaderParamName}');
23
           },
24
           success: html => {
25
             $('#{$id}').html(html);
26
           }
27
        });", View::POS_LOAD);
28
    }
29
}
30