JsHelper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 42
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addString() 0 4 1
A newJsObject() 0 6 1
A initVar() 0 4 1
1
<?php
2
/**
3
 * Created on Tue Oct 27 2020.
4
 *
5
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
6
 * @copyright Copyright (c) 2010 - 2020 Sergey Coderius
7
 * @author Sergey Coderius <[email protected]>
8
 *
9
 * @see https://github.com/coderius - My github. See more my packages here...
10
 * @see https://coderius.biz.ua/ - My dev. blog
11
 *
12
 * Contact email: [email protected] - Have suggestions, contact me |:=)
13
 */
14
15
namespace coderius\swiperslider;
16
17
use Yii;
18
19
/**
20
 * Js helper class for php.
21
 */
22
class JsHelper
23
{
24
    /**
25
     * initVar function.
26
     *
27
     * @param string        $name
28
     * @param object|string $value . Object type: \yii\web\JsExpression
29
     *
30
     * @return string
31
     */
32 6
    public static function initVar($name, $value)
33
    {
34 6
        return "var {$name} = {$value}";
35
    }
36
37
    /**
38
     * addString function.
39
     *
40
     * @param string $value
41
     *
42
     * @return string
43
     */
44 6
    public static function addString($value)
45
    {
46 6
        return "\"{$value}\"";
47
    }
48
49
    /**
50
     * newJsObject function.
51
     *
52
     * @param string $instanceName
53
     * @param array  $params
54
     *
55
     * @return string \yii\web\JsExpression. See https://www.yiiframework.com/doc/api/2.0/yii-web-jsexpression for more information about it.
56
     */
57 6
    public static function newJsObject($instanceName, $params = [])
58
    {
59 6
        $params = implode(',', $params);
60
61 6
        return new \yii\web\JsExpression("new {$instanceName}({$params})");
62
    }
63
}
64