Completed
Push — security-enhancements ( 371440...81b18e )
by Alexander
08:56
created

JsExpression   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 28
rs 10
ccs 6
cts 6
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 4 1
A __construct() 0 5 1
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\Object;
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 Object
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 5
    public function __construct($expression, $config = [])
35
    {
36 5
        $this->expression = $expression;
37 5
        parent::__construct($config);
38 5
    }
39
40
    /**
41
     * The PHP magic function converting an object into a string.
42
     * @return string the JavaScript expression.
43
     */
44 1
    public function __toString()
45
    {
46 1
        return $this->expression;
47
    }
48
}
49