Passed
Pull Request — master (#144)
by
unknown
01:43
created

JsonpRenderer::setCallbackParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
namespace Yiisoft\Yii\Web\ErrorHandler;
5
6
/**
7
 * Formats exception into JSONP string
8
 */
9
final class JsonpRenderer extends JsonRenderer
10
{
11
12
    /**
13
     * @var string
14
     */
15
    private $callbackParameter = 'callback';
16
    /**
17
     * @var string|null
18
     */
19
    private $callback = null;
20
21 3
    public function render(\Throwable $t): string
22
    {
23 3
        $result = parent::render($t);
24 3
        $callback = $this->callback ?? $this->request->getQueryParams()[$this->callbackParameter] ?? 'console.log';
25 3
        return sprintf('%s(%s)', $callback, $result);
26
    }
27
28
    /**
29
     * @param string the name of the GET parameter that specifies the callback.
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\Web\ErrorHandler\the was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
     * @return static
31
     */
32 3
    public function setCallbackParameter(string $name)
33
    {
34 3
        $this->callbackParameter = $name;
35 3
        return $this;
36
    }
37
38
    /**
39
     * @param string|null callback used. If NULL, callback will use from GET.
40
     * @return static
41
     */
42 3
    public function setCallback(?string $name)
43
    {
44 3
        $this->callback = $name;
45 3
        return $this;
46
    }
47
}
48