Passed
Push — master ( 743cc2...6ffec3 )
by Oleg
02:50
created

CodeLoader::loadCode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration;
5
6
use org\bovigo\vfs\vfsStream;
7
use org\bovigo\vfs\vfsStreamDirectory;
8
9
class CodeLoader
10
{
11
    /**
12
     * @var vfsStreamDirectory
13
     */
14
    static private $root ;
15
    static private $declared = [];
16
17
    static private function init()
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
18
    {
19
        if (self::$root === null) {
20
            self::$root = vfsStream::setup();
21
        }
22
    }
23
24
    static public function loadCode(string $code, string $fileName): void
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
25
    {
26
        self::init();
27
        if (!self::isDeclared($code)) {
28
            file_put_contents(self::$root->url() . "/$fileName", $code);
29
            include self::$root->url() . "/$fileName";
30
            self::$declared[] = md5($code);
31
        }
32
    }
33
34
    static private function isDeclared(string $code): bool
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
35
    {
36
        return in_array(md5($code), self::$declared);
37
    }
38
}
39