This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the SlotMachine library. |
||
5 | * |
||
6 | * (c) Adam Elsodaney <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace SlotMachine; |
||
13 | |||
14 | /** |
||
15 | * A slot will hold the reel of cards and retrieve a card from it. |
||
16 | * |
||
17 | * @author Adam Elsodaney <[email protected]> |
||
18 | */ |
||
19 | class Slot implements SlotInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $name; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $keys; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $reel; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $nested = array(); |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $aliases = array(); |
||
45 | |||
46 | /** |
||
47 | * @var integer |
||
48 | */ |
||
49 | protected $undefinedCardResolution = UndefinedCardResolution::NO_CARD_FOUND_EXCEPTION; |
||
50 | |||
51 | /** |
||
52 | * @param array |
||
53 | */ |
||
54 | public function __construct(array $data) |
||
55 | { |
||
56 | $this->name = $data['name']; |
||
57 | $this->keys = $data['keys']; |
||
58 | $this->reel = $data['reel']; |
||
59 | $this->aliases = array_replace($this->aliases, isset($data['reel']['aliases']) ? $data['reel']['aliases'] : array()); |
||
60 | $this->nested = array_key_exists('nested', $data) ? $data['nested'] : array(); |
||
61 | $this->undefinedCardResolution = array_key_exists('undefined_card', $data) |
||
62 | ? $data['undefined_card'] |
||
63 | : UndefinedCardResolution::NO_CARD_FOUND_EXCEPTION; |
||
64 | } |
||
65 | |||
66 | public function getUcr() |
||
67 | { |
||
68 | return $this->undefinedCardResolution; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Get a value of a card by its index. |
||
73 | * If the card does not exist, resolve based on the slot's resolve_undefined setting. |
||
74 | * |
||
75 | * @param integer $index |
||
76 | * @return mixed |
||
77 | * @throws SlotMachine\Exception\NoCardFoundException if the key does not exist and |
||
78 | * the undefinedCardResolution property is set to NO_CARD_FOUND_EXCEPTION. |
||
79 | */ |
||
80 | public function getCard($index = 0, $failOnNoCardFound = false) |
||
81 | { |
||
82 | if (!array_key_exists($index, $this->reel['cards'])) { |
||
83 | if ($failOnNoCardFound) { |
||
84 | throw new Exception\NoCardFoundException(sprintf( |
||
85 | "Cannot resolve a card value for the '%s' slot. (Perhaps you need to set a '_default' alias for the slot or the card of index 0 is missing from the slot's assigned reel?)", |
||
86 | $this->name |
||
87 | )); |
||
88 | } |
||
89 | switch ($this->undefinedCardResolution) { |
||
90 | case UndefinedCardResolution::NO_CARD_FOUND_EXCEPTION: |
||
91 | default: |
||
92 | throw new Exception\NoCardFoundException(sprintf( |
||
93 | "Card of index %d was not found in the slot `%s`.", $index, $this->name |
||
94 | )); |
||
95 | |||
96 | case UndefinedCardResolution::DEFAULT_CARD: |
||
0 ignored issues
–
show
|
|||
97 | return $this->getDefaultCard(); |
||
98 | |||
99 | case UndefinedCardResolution::FALLBACK_CARD: |
||
100 | return $this->getFallbackCard(); |
||
101 | |||
102 | case UndefinedCardResolution::BLANK_CARD: |
||
103 | return ''; |
||
104 | |||
105 | // End Switch |
||
106 | } |
||
107 | } |
||
108 | return $this->reel['cards'][$index]; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Get a card from the reel by an alias. |
||
113 | * |
||
114 | * @param string $alias |
||
115 | * @return mixed |
||
116 | */ |
||
117 | public function getCardByAlias($alias) |
||
118 | { |
||
119 | if (!array_key_exists($alias, $this->aliases)) { |
||
120 | throw new Exception\NoSuchAliasException(sprintf('Alias "%s" has not been assigned to any cards.', $alias)); |
||
121 | } |
||
122 | |||
123 | return $this->getCard($this->aliases[$alias]); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * @return string |
||
128 | */ |
||
129 | public function getDefaultCard() |
||
130 | { |
||
131 | try { |
||
132 | return $this->getCardByAlias('_default'); |
||
133 | } catch (Exception\NoSuchAliasException $e) { |
||
134 | return $this->getCard(0, true); |
||
135 | } |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @return string |
||
140 | */ |
||
141 | public function getFallbackCard() |
||
142 | { |
||
143 | try { |
||
144 | return $this->getCardByAlias('_fallback'); |
||
145 | } catch (Exception\NoSuchAliasException $e) { |
||
146 | return $this->getCard(); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @return integer|null |
||
152 | */ |
||
153 | public function getDefaultIndex() |
||
154 | { |
||
155 | return array_key_exists('_default', $this->aliases) ? $this->aliases['_default'] : null; |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @return integer|null |
||
160 | */ |
||
161 | public function getFallbackIndex() |
||
162 | { |
||
163 | return array_key_exists('_fallback', $this->aliases) ? $this->aliases['_fallback'] : null; |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @return integer |
||
168 | */ |
||
169 | public function getResolvableIndex() |
||
170 | { |
||
171 | if (array_key_exists('_default', $this->aliases)) { |
||
172 | return $this->aliases['_default']; |
||
173 | } elseif (array_key_exists('_fallback', $this->aliases)) { |
||
174 | return $this->aliases['_fallback']; |
||
175 | } |
||
176 | |||
177 | return 0; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * @return array |
||
182 | */ |
||
183 | public function getNested() |
||
184 | { |
||
185 | return $this->nested; |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * @return string |
||
190 | */ |
||
191 | public function getKey() |
||
192 | { |
||
193 | return $this->keys[0]; |
||
194 | } |
||
195 | |||
196 | /** |
||
197 | * @return array |
||
198 | */ |
||
199 | public function getKeys() |
||
200 | { |
||
201 | return $this->keys; |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * @return string |
||
206 | */ |
||
207 | public function __toString() |
||
208 | { |
||
209 | try { |
||
210 | return $this->getCard(); |
||
211 | } catch (Exception\NoCardFoundException $e) { |
||
212 | return ""; |
||
213 | } |
||
214 | } |
||
215 | } |
||
216 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.