Passed
Pull Request — master (#25)
by Alexander
07:37
created

JsExpression::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Json;
6
7
/**
8
 * JsExpression marks a string as a JavaScript expression.
9
 * When using [[\Yiisoft\Json\Json::encode()]] or [[\Yiisoft\Json\Json::htmlEncode()]] to encode a value, JsonExpression objects
10
 * will be specially handled and encoded as a JavaScript expression instead of a string.
11
 */
12
class JsExpression
13
{
14
    /**
15
     * @var string the JavaScript expression represented by this object
16
     */
17
    public $expression;
18
19
    /**
20
     * Constructor.
21
     *
22
     * @param string $expression the JavaScript expression represented by this object
23
     */
24
    public function __construct($expression)
25
    {
26
        $this->expression = $expression;
27
    }
28
29
    /**
30
     * The PHP magic function converting an object into a string.
31
     *
32
     * @return string the JavaScript expression.
33
     */
34
    public function __toString()
35
    {
36
        return $this->expression;
37
    }
38
}
39