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

FileEvaluator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
wmc 4
lcom 1
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A evaluate() 0 10 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