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

AbstractRoster::setRerollCost()   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\Helper\Optionable;
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
8
abstract class AbstractRoster extends Optionable
9
{
10
    const DEFAULT_INDUCEMENT_OPTIONS = [
11
        'discount_bribe' => false,
12
        'discount_halfling_master_chef' => false,
13
        'extra_apothecary' => true,
14
        'igor' => false
15
    ];
16
17
    protected $key;
18
    protected $translation_key;
19
    protected $translation_domain;
20
    protected $player_types;
21
    protected $reroll_cost;
22
    protected $can_have_apothecary;
23
    protected $inducement_options;
24
25
    protected function hydrateWithOptions($options)
26
    {
27
        $this->setKey($options['key'])
28
            ->setTranslationKey($options['translation_key'])
29
            ->setTranslationDomain($options['translation_domain'])
30
            ->setPlayerTypes($options['player_types'])
31
            ->setInducementTypes($options['inducement_options'])
32
            ->setRerollCost($options['reroll_cost'])
33
            ->setCanHaveApothecary($options['can_have_apothecary']);
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    public function getKey(): string
40
    {
41
        return $this->key;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getTranslationKey(): string
48
    {
49
        return $this->translation_key;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getTranslationDomain(): string
56
    {
57
        return $this->translation_domain;
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function getPlayerTypes(): ?array
64
    {
65
        return $this->player_types;
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    public function canHaveApothecary():bool
72
    {
73
        return $this->can_have_apothecary;
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function getCanHaveApothecary():bool
80
    {
81
        return $this->can_have_apothecary;
82
    }
83
84
    /**
85
     * @return int
86
     */
87
    public function getRerollCost():int
88
    {
89
        return $this->reroll_cost;
90
    }
91
92
    /**
93
     * @return array
94
     */
95
    public function getInducementOptions():?array
96
    {
97
        return $this->inducement_options;
98
    }
99
100
    /**
101
     * @param string $key
102
     * @return $this
103
     */
104
    public function setKey(string $key): self
105
    {
106
        $this->key = $key;
107
        return $this;
108
    }
109
110
    /**
111
     * @param string $translation_key
112
     * @return $this
113
     */
114
    public function setTranslationKey(string $translation_key): self
115
    {
116
        $this->translation_key = $translation_key;
117
        return $this;
118
    }
119
120
    /**
121
     * @param string $translation_domain
122
     * @return $this
123
     */
124
    public function setTranslationDomain(string $translation_domain): self
125
    {
126
        $this->translation_domain = $translation_domain;
127
        return $this;
128
    }
129
130
    /**
131
     * @param array $player_types
132
     * @return $this
133
     */
134
    public function setPlayerTypes(array $player_types): self
135
    {
136
        $this->player_types = $player_types;
137
        return $this;
138
    }
139
140
    /**
141
     * @param array $inducement_types
142
     * @return $this
143
     */
144
    public function setInducementTypes(array $inducement_types): self
145
    {
146
        $this->inducement_types = $inducement_types;
0 ignored issues
show
Bug Best Practice introduced by
The property inducement_types does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
147
        return $this;
148
    }
149
150
    /**
151
     * @param int $reroll_cost
152
     * @return $this
153
     */
154
    public function setRerollCost(int $reroll_cost): self
155
    {
156
        $this->reroll_cost = $reroll_cost;
157
        return $this;
158
    }
159
160
    /**
161
     * @param bool $can_have_apothecary
162
     * @return $this
163
     */
164
    public function setCanHaveApothecary(bool $can_have_apothecary): self
165
    {
166
        $this->can_have_apothecary = $can_have_apothecary;
167
        return $this;
168
    }
169
170
    public function __toString(): string
171
    {
172
        return $this->translation_key;
173
    }
174
175
    public function resolveOptions($options)
176
    {
177
        parent::resolveOptions($options);
178
        $this->hydrateWithOptions($options);
179
    }
180
181
    public function configureOptions(OptionsResolver $resolver)
182
    {
183
        $resolver->setDefaults([
184
            'key'                 => null,
185
            'translation_key'     => null,
186
            'translation_domain'  => null,
187
            'player_types'        => [],
188
            'inducement_options'  => [],
189
            'reroll_cost'         => 0,
190
            'can_have_apothecary' => true,
191
        ])
192
            ->setRequired('key')
193
            ->setRequired('translation_key')
194
            ->setRequired('translation_domain')
195
            ->setAllowedTypes('key', ['string'])
196
            ->setAllowedTypes('translation_key', ['string'])
197
            ->setAllowedTypes('translation_domain', ['string'])
198
            ->setAllowedTypes('player_types', ['array'])
199
            ->setAllowedTypes('inducement_options', ['array'])
200
            ->setAllowedTypes('reroll_cost', ['int'])
201
            ->setAllowedTypes('can_have_apothecary', ['bool'])
202
        ;
203
    }
204
}
205