NativeOperators   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 51
c 0
b 0
f 0
wmc 1
lcom 0
cbo 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 48 1
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);
0 ignored issues
show
Documentation introduced by
$customOperators is of type object<RulerZ\Target\Operators\Definitions>, but the function expects a object<self>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
    }
59
}
60