Completed
Push — 2.1 ( 0cb910...fafa40 )
by
unknown
40:37 queued 36:49
created

JsExpression::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace yii\web;
9
10
use yii\base\BaseObject;
11
12
/**
13
 * JsExpression marks a string as a JavaScript expression.
14
 *
15
 * When using [[\yii\helpers\Json::encode()]] or [[\yii\helpers\Json::htmlEncode()]] to encode a value, JsonExpression objects
16
 * will be specially handled and encoded as a JavaScript expression instead of a string.
17
 *
18
 * @author Qiang Xue <[email protected]>
19
 * @since 2.0
20
 */
21
class JsExpression extends BaseObject
22
{
23
    /**
24
     * @var string the JavaScript expression represented by this object
25
     */
26
    public $expression;
27
28
29
    /**
30
     * Constructor.
31
     * @param string $expression the JavaScript expression represented by this object
32
     * @param array $config additional configurations for this object
33
     */
34 2
    public function __construct($expression, $config = [])
35
    {
36 2
        $this->expression = $expression;
37 2
        parent::__construct($config);
38 2
    }
39
40
    /**
41
     * The PHP magic function converting an object into a string.
42
     * @return string the JavaScript expression.
43
     */
44
    public function __toString()
45
    {
46
        return $this->expression;
47
    }
48
}
49