EvalExecution   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 18
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A patch() 0 8 1
1
<?php
2
3
namespace Kambo\Testing\ClassOpener\ClassManipulation\Patcher;
4
5
use PhpParser\PrettyPrinter\Standard;
6
use Kambo\Testing\ClassOpener\ClassManipulation\Patcher;
7
8
/**
9
 * Patch class with its modified version.
10
 *
11
 * @author  Bohuslav Simek <[email protected]>
12
 * @license MIT
13
 */
14
class EvalExecution implements Patcher
15
{
16
    /**
17
     * Replace global class definition with class defined in the provided nodes.
18
     *
19
     * @param Node[] $statmentNodes Array of statements
20
     *
21
     * @return void
22
     */
23 3
    public function patch(array $statmentNodes)
24
    {
25 3
        $prettyPrinter = new Standard;
26 3
        $newClassCode  = $prettyPrinter->prettyPrintFile($statmentNodes).PHP_EOL;
27
28
        // Force PHP interpreter to use modified version of the class, by evaluating.
29 3
        eval('?>' . $newClassCode);
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
30 3
    }
31
}
32