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\Dice; |
||
6 | |||
7 | class SpecialDiceFactory implements DiceFactory |
||
8 | { |
||
9 | /** |
||
10 | * @var callable[] |
||
11 | */ |
||
12 | private $diceTypeMappings; |
||
13 | |||
14 | public function __construct() |
||
15 | { |
||
16 | $this->diceTypeMappings = [ |
||
0 ignored issues
–
show
|
|||
17 | 'steve' => function () { |
||
18 | return new Dice\SteveDice(); |
||
19 | }, |
||
20 | 'fate' => function () { |
||
21 | return new Dice\FateDice(); |
||
22 | }, |
||
23 | ]; |
||
24 | } |
||
25 | |||
26 | |||
27 | public function handlesType(string $type) : bool |
||
28 | { |
||
29 | return array_key_exists( |
||
30 | $this->normaliseType($type), |
||
31 | $this->diceTypeMappings |
||
32 | ); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param string $type |
||
37 | * @param int $number |
||
38 | * @return Dice[] |
||
39 | */ |
||
40 | public function buildDice(string $type, int $number) : array |
||
41 | { |
||
42 | $diceConstructor = $this->diceTypeMappings[$this->normaliseType($type)]; |
||
43 | return $this->buildNDice($number, $diceConstructor); |
||
44 | } |
||
45 | |||
46 | private function normaliseType(string $type): string |
||
47 | { |
||
48 | return strtolower($type); |
||
49 | } |
||
50 | |||
51 | private function buildNDice($diceCount, callable $constructorFunction) |
||
52 | { |
||
53 | $newDice = []; |
||
54 | for ($i = 0; $i < $diceCount; $i++) { |
||
55 | $newDice[] = $constructorFunction(); |
||
56 | } |
||
57 | return $newDice; |
||
58 | } |
||
59 | } |
||
60 |
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..