These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace MeadSteve\DiceApi\Dice\Factories; |
||
4 | |||
5 | use MeadSteve\DiceApi\BasicDice; |
||
6 | use MeadSteve\DiceApi\Dice; |
||
7 | use MeadSteve\DiceApi\Dice\SteveDice; |
||
8 | use MeadSteve\DiceApi\Dice\UncreatableDiceException; |
||
9 | use MeadSteve\DiceApi\Dice\ZeropointDice; |
||
10 | |||
11 | class SpecialDiceFactory implements DiceFactory |
||
12 | { |
||
13 | /** |
||
14 | * @var callable[] |
||
15 | */ |
||
16 | private $diceTypeCallbacks; |
||
17 | |||
18 | public function __construct() |
||
19 | { |
||
20 | $this->diceTypeCallbacks = [ |
||
0 ignored issues
–
show
|
|||
21 | 'steve' => [$this, 'buildSteveDice'] |
||
22 | ]; |
||
23 | } |
||
24 | |||
25 | |||
26 | public function handlesType(string $type) : bool |
||
27 | { |
||
28 | return array_key_exists( |
||
29 | $this->normaliseType($type), |
||
30 | $this->diceTypeCallbacks |
||
31 | ); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param string $type |
||
36 | * @param int $number |
||
37 | * @return Dice[] |
||
38 | */ |
||
39 | public function buildDice(string $type, int $number) : array |
||
40 | { |
||
41 | $function = $this->diceTypeCallbacks[$this->normaliseType($type)]; |
||
42 | return $function($type, $number); |
||
43 | } |
||
44 | |||
45 | private function buildSteveDice($_type, $diceCount) |
||
46 | { |
||
47 | $newDice = []; |
||
48 | for ($i = 0; $i < $diceCount; $i++) { |
||
49 | $newDice[] = new SteveDice(); |
||
50 | } |
||
51 | return $newDice; |
||
52 | } |
||
53 | |||
54 | private function normaliseType(string $type): string |
||
55 | { |
||
56 | return strtolower($type); |
||
57 | } |
||
58 | } |
||
59 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..