BaseExpressionFunction::provideEvaluator()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
c 0
b 0
f 0
1
<?php
2
3
4
namespace SmartWeb\ModuleTesting\ExpressionLanguage\Functions;
5
6
use Illuminate\Support\Str;
7
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
8
use function class_basename;
9
10
11
/**
12
 * Base class for expression functions.
13
 *
14
 * @inheritDoc
15
 *
16
 * @package SmartWeb\ModuleTesting\ExpressionLanguage\Functions
17
 */
18
abstract class BaseExpressionFunction extends ExpressionFunction
19
{
20
    
21
    /**
22
     * @var string
23
     */
24
    protected $name;
25
    
26
    /**
27
     * @var callable
28
     */
29
    private $compiler;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
30
    
31
    /**
32
     * @var callable
33
     */
34
    private $evaluator;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
35
    
36
    /**
37
     * BaseExpressionFunction constructor.
38
     */
39
    final public function __construct()
40
    {
41
        $this->init();
42
    }
43
    
44
    /**
45
     * Initialize the ExpressionFunction
46
     *
47
     * @return void
48
     */
49
    abstract protected function init();
50
    
51
    /**
52
     * @return string
53
     */
54
    private function resolveName() : string
55
    {
56
        return $this->name = $this->name ?? Str::camel(class_basename($this));
57
    }
58
    
59
    /**
60
     * @return callable A callable able to compile the function
61
     */
62
    private function resolveCompiler() : callable
63
    {
64
        return $this->compiler = $this->compiler ?? $this->provideCompiler();
65
    }
66
    
67
    /**
68
     * @return callable A callable able to evaluate the function
69
     */
70
    private function resolveEvaluator() : callable
71
    {
72
        return $this->evaluator = $this->evaluator ?? $this->provideEvaluator();
73
    }
74
    
75
    /**
76
     * @return callable
77
     */
78
    abstract protected function provideCompiler() : callable;
79
    
80
    /**
81
     * @return callable
82
     */
83
    abstract protected function provideEvaluator() : callable;
84
    
85
    /**
86
     * @return string
87
     */
88
    final public function getName() : string
89
    {
90
        return $this->resolveName();
91
    }
92
    
93
    /**
94
     * @return callable
95
     */
96
    final public function getCompiler() : callable
97
    {
98
        return $this->resolveCompiler();
99
    }
100
    
101
    /**
102
     * @return callable
103
     */
104
    final public function getEvaluator() : callable
105
    {
106
        return $this->resolveEvaluator();
107
    }
108
    
109
}
110