Completed
Push — master ( 274043...94c6c6 )
by Tomáš
03:17
created

CommonData::hasEID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Inspirum\Balikobot\Model\Values\Package;
4
5
use Inspirum\Balikobot\Definitions\Option;
6
7
trait CommonData
8
{
9
    /**
10
     * Set the item at a given offset
11
     *
12
     * @param string $key
13
     * @param mixed  $value
14
     *
15
     * @return void
16
     */
17
    abstract public function offsetSet($key, $value);
18
19
    /**
20
     * Get an item at a given offset
21
     *
22
     * @param string $key
23
     *
24
     * @return mixed
25
     */
26
    abstract public function offsetGet($key);
27
28
    /**
29
     * Set EID
30
     *
31
     * @param string $id
32
     *
33
     * @return void
34
     */
35 15
    public function setEID(string $id): void
36
    {
37 15
        $this->offsetSet(Option::EID, $id);
38 15
    }
39
40
    /**
41
     * Get EID
42
     *
43
     * @return string|null
44
     */
45 15
    public function getEID(): ?string
46
    {
47 15
        return $this->offsetGet(Option::EID);
48
    }
49
50
    /**
51
     * Get EID
52
     *
53
     * @return bool
54
     */
55 17
    public function hasEID(): bool
56
    {
57 17
        return $this->offsetExists(Option::EID);
0 ignored issues
show
Bug introduced by
It seems like offsetExists() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
58
    }
59
60
    /**
61
     * @param int $orderNumber
62
     *
63
     * @return void
64
     */
65 1
    public function setOrderNumber(int $orderNumber): void
66
    {
67 1
        $this->offsetSet(Option::ORDER_NUMBER, $orderNumber);
68 1
    }
69
70
    /**
71
     * @param string $realOrderId
72
     *
73
     * @return void
74
     */
75 1
    public function setRealOrderId(string $realOrderId): void
76
    {
77 1
        $this->offsetSet(Option::REAL_ORDER_ID, $realOrderId);
78 1
    }
79
80
    /**
81
     * @param string $serviceType
82
     *
83
     * @return void
84
     */
85 2
    public function setServiceType(string $serviceType): void
86
    {
87 2
        $this->offsetSet(Option::SERVICE_TYPE, $serviceType);
88 2
    }
89
90
    /**
91
     * @param array<string> $services
92
     *
93
     * @return void
94
     */
95 1
    public function setServices(array $services): void
96
    {
97
        // TODO: add validation
98
99 1
        $this->offsetSet(Option::SERVICES, implode('+', $services));
100 1
    }
101
102
    /**
103
     * @param string $branchId
104
     *
105
     * @return void
106
     */
107 1
    public function setBranchId(string $branchId): void
108
    {
109 1
        $this->offsetSet(Option::BRANCH_ID, $branchId);
110 1
    }
111
112
    /**
113
     * @param bool $fullErrors
114
     *
115
     * @return void
116
     */
117 1
    public function setReturnFullErrors(bool $fullErrors = true): void
118
    {
119 1
        $this->offsetSet(Option::RETURN_FULL_ERRORS, (int) $fullErrors);
120 1
    }
121
122
    /**
123
     * @param bool $returnTrack
124
     *
125
     * @return void
126
     */
127 1
    public function setReturnTrack(bool $returnTrack = true): void
128
    {
129 1
        $this->offsetSet(Option::RETURN_TRACK, (int) $returnTrack);
130 1
    }
131
132
    /**
133
     * @param bool $returnCarrierId
134
     *
135
     * @return void
136
     */
137 1
    public function setReturnFinalCarrierId(bool $returnCarrierId = true): void
138
    {
139 1
        $this->offsetSet(Option::RETURN_FINAL_CARRIER_ID, (int) $returnCarrierId);
140 1
    }
141
}
142