Passed
Push — feature/initial-implementation ( 0c2c6c...79751f )
by Fike
01:54
created

PropertyMappingView::getTargetClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Mapping;
6
7
use AmaTeam\ElasticSearch\API\Mapping\PropertyMappingViewInterface;
8
9
class PropertyMappingView implements PropertyMappingViewInterface
10
{
11
    /**
12
     * @var string|null
13
     */
14
    private $type;
15
    /**
16
     * @var string|null
17
     */
18
    private $targetClass;
19
    /**
20
     * @var array
21
     */
22
    private $parameters = [];
23
24
    /**
25
     * @return null|string
26
     */
27
    public function getType(): ?string
28
    {
29
        return $this->type;
30
    }
31
32
    /**
33
     * @param null|string $type
34
     * @return $this
35
     */
36
    public function setType($type)
37
    {
38
        $this->type = $type;
39
        return $this;
40
    }
41
42
    /**
43
     * @return null|string
44
     */
45
    public function getTargetClass(): ?string
46
    {
47
        return $this->targetClass;
48
    }
49
50
    /**
51
     * @param null|string $targetClass
52
     * @return $this
53
     */
54
    public function setTargetClass(string $targetClass)
55
    {
56
        $this->targetClass = $targetClass;
57
        return $this;
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function getParameters(): array
64
    {
65
        return $this->parameters;
66
    }
67
68
    /**
69
     * @param array $parameters
70
     * @return $this
71
     */
72
    public function setParameters(array $parameters)
73
    {
74
        $this->parameters = $parameters;
75
        return $this;
76
    }
77
78
    public function setParameter(string $name, $value): PropertyMappingView
79
    {
80
        $this->parameters[$name] = $value;
81
        return $this;
82
    }
83
84
    public static function merge(PropertyMappingViewInterface ...$views): PropertyMappingView
85
    {
86
        $target = new PropertyMappingView();
87
        foreach ($views as $view) {
88
            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...
89
                $target->setType($view->getType());
90
            }
91
            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...
92
                $target->setTargetClass($view->getTargetClass());
93
            }
94
            foreach ($view->getParameters() as $parameter => $value) {
95
                $target->setParameter($parameter, $value);
96
            }
97
        }
98
        return $target;
99
    }
100
}
101