Completed
Push — master ( 68be21...073c54 )
by Kévin
02:41
created

FileEvaluator::evaluate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace RulerZ\Compiler;
4
5
class FileEvaluator implements Evaluator
6
{
7
    private $directory;
8
9
    /**
10
     * @param string $directory The directory in which the compiled executors are stored. Defaults to the system's temp directory.
11
     */
12
    public function __construct($directory = null)
13
    {
14
        $this->directory = $directory ?: sys_get_temp_dir();
15
    }
16
17
    /**
18
     * @inheritdoc
19
     */
20
    public function evaluate($ruleIdentifier, callable $compiler)
21
    {
22
        $fileName = $this->directory . DIRECTORY_SEPARATOR . 'rulerz_executor_' . $ruleIdentifier;
23
24
        if (!file_exists($fileName)) {
25
            file_put_contents($fileName, '<?php'."\n".$compiler());
26
        }
27
28
        require $fileName;
29
    }
30
}
31