1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RulerZ\Target\Native; |
6
|
|
|
|
7
|
|
|
use RulerZ\Target\Operators\Definitions; |
8
|
|
|
|
9
|
|
|
class NativeOperators |
10
|
|
|
{ |
11
|
|
|
public static function create(Definitions $customOperators): Definitions |
12
|
|
|
{ |
13
|
|
|
$defaultInlineOperators = [ |
14
|
|
|
'and' => function ($a, $b) { |
15
|
|
|
return sprintf('(%s && %s)', $a, $b); |
16
|
|
|
}, |
17
|
|
|
'or' => function ($a, $b) { |
18
|
|
|
return sprintf('(%s || %s)', $a, $b); |
19
|
|
|
}, |
20
|
|
|
'not' => function ($a) { |
21
|
|
|
return sprintf('!(%s)', $a); |
22
|
|
|
}, |
23
|
|
|
'=' => function ($a, $b) { |
24
|
|
|
return sprintf('%s == %s', $a, $b); |
25
|
|
|
}, |
26
|
|
|
'is' => function ($a, $b) { |
27
|
|
|
return sprintf('%s === %s', $a, $b); |
28
|
|
|
}, |
29
|
|
|
'!=' => function ($a, $b) { |
30
|
|
|
return sprintf('%s != %s', $a, $b); |
31
|
|
|
}, |
32
|
|
|
'>' => function ($a, $b) { |
33
|
|
|
return sprintf('%s > %s', $a, $b); |
34
|
|
|
}, |
35
|
|
|
'>=' => function ($a, $b) { |
36
|
|
|
return sprintf('%s >= %s', $a, $b); |
37
|
|
|
}, |
38
|
|
|
'<' => function ($a, $b) { |
39
|
|
|
return sprintf('%s < %s', $a, $b); |
40
|
|
|
}, |
41
|
|
|
'<=' => function ($a, $b) { |
42
|
|
|
return sprintf('%s <= %s', $a, $b); |
43
|
|
|
}, |
44
|
|
|
'in' => function ($a, $b) { |
45
|
|
|
return sprintf('in_array(%s, %s)', $a, $b); |
46
|
|
|
}, |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
$defaultOperators = [ |
50
|
|
|
'sum' => function () { |
51
|
|
|
return array_sum(func_get_args()); |
52
|
|
|
}, |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
$definitions = new Definitions($defaultOperators, $defaultInlineOperators); |
56
|
|
|
|
57
|
|
|
return $definitions->mergeWith($customOperators); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: