Completed
Push — master ( 06b292...adafac )
by Nicolai
02:22
created

BaseExpressionFunction   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 94
rs 10
c 0
b 0
f 0
wmc 8
lcom 3
cbo 2

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A init() 0 3 1
A resolveName() 0 4 1
A resolveCompiler() 0 4 1
A resolveEvaluator() 0 4 1
provideCompiler() 0 1 ?
provideEvaluator() 0 1 ?
A getName() 0 4 1
A getCompiler() 0 4 1
A getEvaluator() 0 4 1
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\Testing\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
    public final function __construct()
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
40
    {
41
        $this->init();
42
    }
43
    
44
    /**
45
     * Initialize the ExpressionFunction
46
     *
47
     * @return void
48
     */
49
    protected function init()
50
    {
51
    }
52
    
53
    /**
54
     * @return string
55
     */
56
    private function resolveName() : string
57
    {
58
        return $this->name = $this->name ?? Str::camel(class_basename($this));
59
    }
60
    
61
    /**
62
     * @return callable A callable able to compile the function
63
     */
64
    private function resolveCompiler() : callable
65
    {
66
        return $this->compiler = $this->compiler ?? $this->provideCompiler();
67
    }
68
    
69
    /**
70
     * @return callable A callable able to evaluate the function
71
     */
72
    private function resolveEvaluator() : callable
73
    {
74
        return $this->evaluator = $this->evaluator ?? $this->provideEvaluator();
75
    }
76
    
77
    /**
78
     * @return callable
79
     */
80
    protected abstract function provideCompiler() : callable;
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
81
    
82
    /**
83
     * @return callable
84
     */
85
    protected abstract function provideEvaluator() : callable;
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
86
    
87
    /**
88
     * @return string
89
     */
90
    public final function getName() : string
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
91
    {
92
        return $this->resolveName();
93
    }
94
    
95
    /**
96
     * @return callable
97
     */
98
    public final function getCompiler() : callable
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
99
    {
100
        return $this->resolveCompiler();
101
    }
102
    
103
    /**
104
     * @return callable
105
     */
106
    public final function getEvaluator() : callable
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
107
    {
108
        return $this->resolveEvaluator();
109
    }
110
    
111
}