Completed
Branch develop (69883f)
by Benjamin
04:05
created

AbstractRoster::setTranslationKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Obblm\Core\Helper\Rule\Roster;
4
5
use Obblm\Core\Contracts\RosterInterface;
6
use Obblm\Core\Helper\Optionable;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
abstract class AbstractRoster extends Optionable implements RosterInterface
10
{
11
    const DEFAULT_INDUCEMENT_OPTIONS = [
12
        'discount_bribe' => false,
13
        'discount_halfling_master_chef' => false,
14
        'extra_apothecary' => true,
15
        'igor' => false
16
    ];
17
18
    protected $key;
19
    protected $name;
20
    protected $translationDomain;
21
    protected $playerTypes;
22
    protected $rerollCost;
23
    protected $canHaveApothecary;
24
    protected $inducementOptions;
25
26
    protected function hydrateWithOptions()
27
    {
28
        $this->setKey($this->options['key'])
29
            ->setName($this->options['name'])
30
            ->setTranslationDomain($this->options['translation_domain'])
31
            ->setPlayerTypes($this->options['player_types'])
32
            ->setInducementTypes($this->options['inducement_options'])
33
            ->setRerollCost($this->options['reroll_cost'])
34
            ->setCanHaveApothecary($this->options['can_have_apothecary']);
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getKey(): string
41
    {
42
        return $this->key;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getName(): string
49
    {
50
        return $this->name;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getTranslationDomain(): string
57
    {
58
        return $this->translationDomain;
59
    }
60
61
    /**
62
     * @return array
63
     */
64
    public function getPlayerTypes(): ?array
65
    {
66
        return $this->playerTypes;
67
    }
68
69
    /**
70
     * @return bool
71
     */
72
    public function canHaveApothecary():bool
73
    {
74
        return $this->canHaveApothecary;
75
    }
76
77
    /**
78
     * @return bool
79
     */
80
    public function getCanHaveApothecary():bool
81
    {
82
        return $this->canHaveApothecary;
83
    }
84
85
    /**
86
     * @return int
87
     */
88
    public function getRerollCost():int
89
    {
90
        return $this->rerollCost;
91
    }
92
93
    /**
94
     * @return array
95
     */
96
    public function getInducementOptions():?array
97
    {
98
        return $this->inducementOptions;
99
    }
100
101
    /**
102
     * @param string $key
103
     * @return $this
104
     */
105
    public function setKey(string $key): self
106
    {
107
        $this->key = $key;
108
        return $this;
109
    }
110
111
    /**
112
     * @param string $name
113
     * @return $this
114
     */
115
    public function setName(string $name): self
116
    {
117
        $this->name = $name;
118
        return $this;
119
    }
120
121
    /**
122
     * @param string $translationDomain
123
     * @return $this
124
     */
125
    public function setTranslationDomain(string $translationDomain): self
126
    {
127
        $this->translationDomain = $translationDomain;
128
        return $this;
129
    }
130
131
    /**
132
     * @param array $playerTypes
133
     * @return $this
134
     */
135
    public function setPlayerTypes(array $playerTypes): self
136
    {
137
        $this->playerTypes = $playerTypes;
138
        return $this;
139
    }
140
141
    /**
142
     * @param array $inducementTypes
143
     * @return $this
144
     */
145
    public function setInducementTypes(array $inducementTypes): self
146
    {
147
        $this->inducementTypes = $inducementTypes;
0 ignored issues
show
Bug Best Practice introduced by
The property inducementTypes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
148
        return $this;
149
    }
150
151
    /**
152
     * @param int $rerollCost
153
     * @return $this
154
     */
155
    public function setRerollCost(int $rerollCost): self
156
    {
157
        $this->rerollCost = $rerollCost;
158
        return $this;
159
    }
160
161
    /**
162
     * @param bool $canHaveApothecary
163
     * @return $this
164
     */
165
    public function setCanHaveApothecary(bool $canHaveApothecary): self
166
    {
167
        $this->canHaveApothecary = $canHaveApothecary;
168
        return $this;
169
    }
170
171
    public function __toString(): string
172
    {
173
        return $this->translationKey;
0 ignored issues
show
Bug introduced by
The property translationKey does not exist on Obblm\Core\Helper\Rule\Roster\AbstractRoster. Did you mean translationDomain?
Loading history...
174
    }
175
176
    public function resolveOptions($options):void
177
    {
178
        parent::resolveOptions($options);
179
        $this->hydrateWithOptions($options);
0 ignored issues
show
Unused Code introduced by
The call to Obblm\Core\Helper\Rule\R...r::hydrateWithOptions() has too many arguments starting with $options. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

179
        $this->/** @scrutinizer ignore-call */ 
180
               hydrateWithOptions($options);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
180
    }
181
182
    public function configureOptions(OptionsResolver $resolver):void
183
    {
184
        $resolver->setDefaults([
185
            'key'                 => null,
186
            'name'                => null,
187
            'translation_domain'  => null,
188
            'player_types'        => [],
189
            'inducement_options'  => [],
190
            'reroll_cost'         => 0,
191
            'can_have_apothecary' => true,
192
        ])
193
            ->setRequired('key')
194
            ->setRequired('name')
195
            ->setRequired('translation_domain')
196
            ->setAllowedTypes('key', ['string'])
197
            ->setAllowedTypes('name', ['string'])
198
            ->setAllowedTypes('translation_domain', ['string'])
199
            ->setAllowedTypes('player_types', ['array'])
200
            ->setAllowedTypes('inducement_options', ['array'])
201
            ->setAllowedTypes('reroll_cost', ['int'])
202
            ->setAllowedTypes('can_have_apothecary', ['bool'])
203
        ;
204
    }
205
}
206