Completed
Branch develop (598d0f)
by Benjamin
03:23
created

AbstractInducement::setKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Obblm\Core\Helper\Rule\Inducement;
4
5
abstract class AbstractInducement
6
{
7
    /** @var string */
8
    protected $key;
9
10
    /** @var int */
11
    protected $value;
12
13
    /** @var int */
14
    protected $discount_value;
15
16
    /** @var string */
17
    protected $translation_key;
18
19
    /** @var string */
20
    protected $translation_domain;
21
22
    /** @var string */
23
    protected $translation_type;
24
25
    /** @var InducementType */
26
    protected $type;
27
28
    /** @var int */
29
    protected $max;
30
31
    /** @var array */
32
    protected $rosters = null;
33
34
    /**
35
     * Inducement constructor.
36
     * @param array $options
37
     */
38
    public function __construct(array $options = [])
39
    {
40
        $this->hydrateWithOptions($options);
41
    }
42
43
    protected function hydrateWithOptions($options)
44
    {
45
        $this->translation_type = $options['translation_type'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options['translation_type'] ?? false can also be of type false. However, the property $translation_type is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
46
        $this->type = $options['type'] ?? null;
47
        $this->key = $options['key'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options['key'] ?? false can also be of type false. However, the property $key is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
48
        $this->value = $options['value'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options['value'] ?? false can also be of type false. However, the property $value is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
49
        $this->discount_value = $options['discount_value'] ?? $this->value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options['discount_value'] ?? $this->value can also be of type false. However, the property $discount_value is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
50
        $this->translation_key = $options['translation_key'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options['translation_key'] ?? false can also be of type false. However, the property $translation_key is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
51
        $this->translation_domain = $options['translation_domain'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options['translation_domain'] ?? false can also be of type false. However, the property $translation_domain is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
52
        $this->max = $options['max'] ?? false;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options['max'] ?? false can also be of type false. However, the property $max is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
53
        $this->rosters = $options['rosters'] ?? [];
54
    }
55
56
    /**
57
     * @return InducementType
58
     */
59
    public function getType(): ?InducementType
60
    {
61
        return $this->type;
62
    }
63
64
    public function isMultiple(): bool
65
    {
66
        return false;
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getKey(): string
73
    {
74
        return $this->key;
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function getTypeKey(): string
81
    {
82
        return $this->getType()->getKey();
83
    }
84
85
    /**
86
     * @return int
87
     */
88
    public function getDiscountValue(): int
89
    {
90
        return $this->discount_value;
91
    }
92
93
    /**
94
     * @return int
95
     */
96
    public function getValue(): int
97
    {
98
        return $this->value;
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function getTranslationType(): string
105
    {
106
        return $this->translation_type;
107
    }
108
109
    /**
110
     * @return string
111
     */
112
    public function getTranslationKey(): string
113
    {
114
        return $this->translation_key;
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function getTranslationDomain(): string
121
    {
122
        return $this->translation_domain;
123
    }
124
125
    /**
126
     * @return int
127
     */
128
    public function getMax(): int
129
    {
130
        return $this->max;
131
    }
132
133
    /**
134
     * @return array
135
     */
136
    public function getRosters(): ?array
137
    {
138
        return $this->rosters;
139
    }
140
141
    /**
142
     * @param string $key
143
     */
144
    public function setKey(string $key): void
145
    {
146
        $this->key = $key;
147
    }
148
149
    /**
150
     * @param int $value
151
     */
152
    public function setValue(int $value): void
153
    {
154
        $this->value = $value;
155
    }
156
157
    /**
158
     * @param string $translation_key
159
     */
160
    public function setTranslationKey(string $translation_key): void
161
    {
162
        $this->translation_key = $translation_key;
163
    }
164
165
    /**
166
     * @param string $translation_domain
167
     */
168
    public function setTranslationDomain(string $translation_domain): void
169
    {
170
        $this->translation_domain = $translation_domain;
171
    }
172
173
    /**
174
     * @param string $translation_type
175
     */
176
    public function setTranslationType(string $translation_type): void
177
    {
178
        $this->translation_type = $translation_type;
179
    }
180
181
    /**
182
     * @param InducementType|array $type
183
     */
184
    public function setType($type): void
185
    {
186
        $this->type = $type;
0 ignored issues
show
Documentation Bug introduced by
It seems like $type can also be of type array. However, the property $type is declared as type Obblm\Core\Helper\Rule\Inducement\InducementType. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
187
    }
188
189
    /**
190
     * @param int $max
191
     */
192
    public function setMax(int $max): void
193
    {
194
        $this->max = $max;
195
    }
196
197
    /**
198
     * @param array $rosters
199
     */
200
    public function setRosters(array $rosters): void
201
    {
202
        $this->rosters = $rosters;
203
    }
204
205
    public function __toString(): string
206
    {
207
        return $this->translation_key;
208
    }
209
}
210