Script::evaluate()   A
last analyzed

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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Pilipinews\Website\Sunstar;
4
5
use Nacmartin\PhpExecJs\PhpExecJs as Executor;
6
use Nacmartin\PhpExecJs\Runtime\ExternalRuntime;
7
8
/**
9
 * Sunstar Script Evaluator
10
 *
11
 * @package Pilipinews
12
 * @author  Rougin Gutib <[email protected]>
13
 */
14
class Script
15
{
16
    /**
17
     * @var \Nacmartin\PhpExecJs\PhpExecJs
18
     */
19
    protected $executor;
20
21
    /**
22
     * Initializes the evaluator instance.
23
     */
24 33
    public function __construct()
25
    {
26 33
        $binaries = array('node', 'nodejs');
27
28 33
        $runtime = new ExternalRuntime(null, $binaries);
29
30 33
        $this->executor = new Executor($runtime);
31 33
    }
32
33
    /**
34
     * Evaluates the given Javascript code.
35
     *
36
     * @param  string $script
37
     * @return string
38
     */
39
    public function evaluate($script)
40
    {
41
        return $this->executor->evalJs($script);
42
    }
43
}
44