Transpiler::transpileFeature()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
crap 2
1
<?php
2
3
4
namespace JanPiet\PhpTranspiler;
5
6
use JanPiet\PhpTranspiler\Feature\FeatureInterface;
7
use PhpParser\ParserFactory;
8
use PhpParser\PrettyPrinter\Standard;
9
10
class Transpiler
11
{
12
    /**
13
     * @param string $sourceFileContents
14
     * @param FeatureInterface[] ...$feature
15
     * @return string
16
     */
17 15
    public function transpileFeature(string $sourceFileContents, FeatureInterface ...$features): string
18
    {
19 15
        $parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
20 15
        $nodes = $parser->parse($sourceFileContents);
21
22 15
        $search = new NodeSearch($nodes);
23
24 15
        foreach ($features as $feature) {
25 15
            $feature->fix($search);
26
        }
27
28 15
        $prettyPrinter = new Standard();
29
30 15
        return $prettyPrinter->prettyPrintFile($search->getTree());
31
    }
32
}
33