Passed
Push — feature/initial-implementation ( fb0c51...553b70 )
by Fike
02:25
created

PropertyMappingView::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\API\Entity\Mapping;
6
7
class PropertyMappingView implements PropertyMappingViewInterface
8
{
9
    /**
10
     * @var string|null
11
     */
12
    private $type;
13
    /**
14
     * @var string|null
15
     */
16
    private $targetClass;
17
    /**
18
     * @var array
19
     */
20
    private $parameters = [];
21
22
    /**
23
     * @return null|string
24
     */
25
    public function getType(): ?string
26
    {
27
        return $this->type;
28
    }
29
30
    /**
31
     * @param null|string $type
32
     * @return $this
33
     */
34
    public function setType(string $type)
35
    {
36
        $this->type = $type;
37
        return $this;
38
    }
39
40
    /**
41
     * @return null|string
42
     */
43
    public function getTargetClass(): ?string
44
    {
45
        return $this->targetClass;
46
    }
47
48
    /**
49
     * @param null|string $targetClass
50
     * @return $this
51
     */
52
    public function setTargetClass(string $targetClass)
53
    {
54
        $this->targetClass = $targetClass;
55
        return $this;
56
    }
57
58
    /**
59
     * @return array
60
     */
61
    public function getParameters(): array
62
    {
63
        return $this->parameters;
64
    }
65
66
    /**
67
     * @param array $parameters
68
     * @return $this
69
     */
70
    public function setParameters(array $parameters)
71
    {
72
        $this->parameters = $parameters;
73
        return $this;
74
    }
75
76
    public function setParameter(string $name, $value): PropertyMappingView
77
    {
78
        $this->parameters[$name] = $value;
79
        return $this;
80
    }
81
82
    public static function merge(PropertyMappingViewInterface ...$views): PropertyMappingView
83
    {
84
        $target = new PropertyMappingView();
85
        foreach ($views as $view) {
86
            if ($view->getType()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $view->getType() of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
87
                $target->setType($view->getType());
88
            }
89
            if ($view->getTargetClass()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $view->getTargetClass() of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
90
                $target->setTargetClass($view->getTargetClass());
91
            }
92
            foreach ($view->getParameters() as $parameter => $value) {
93
                $target->setParameter($parameter, $value);
94
            }
95
        }
96
        return $target;
97
    }
98
}
99