1 | <?php |
||
16 | class Dijkstra { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $points = array(); |
||
21 | |||
22 | /** |
||
23 | * Dijkstra constructor. |
||
24 | * |
||
25 | * @param Closure|null $function Anonymous function to create relations. |
||
26 | */ |
||
27 | public function __construct($function = null) |
||
33 | |||
34 | /** |
||
35 | * Method executes sent function and add result to $points parameter. |
||
36 | * |
||
37 | * @param Closure $function Anonymous function to create relations. |
||
38 | * @return Dijkstra $this Reference to the same object. |
||
39 | * @throws Exception Method throws exception when $function argument isn't a Closure object. |
||
40 | */ |
||
41 | public function add($function) |
||
65 | |||
66 | /** |
||
67 | * Method search unvisited points in neighborhood of sent point. |
||
68 | * |
||
69 | * @param integer[] $visited Array of visited points' ids. |
||
70 | * @param integer $point Point id. |
||
71 | * @return boolean True when exists unvisited point in neighborhood or false otherwise. |
||
72 | */ |
||
73 | private function existsUnvisitedInNeighborhood($visited, $point) |
||
83 | |||
84 | private function findPointWithUncheckedRelation($unvisited, $visited, $startPoint = null) |
||
102 | |||
103 | /** |
||
104 | * Method generates path for given Point object or point id. |
||
105 | * |
||
106 | * @param Point|integer $point Point object or point identification number. |
||
107 | * @return Path[] Array of Path objects. |
||
108 | * @throws Exception Throws exception when sent point not isset in object's $point array. |
||
109 | */ |
||
110 | public function generate($point) |
||
158 | |||
159 | /** |
||
160 | * Method generates paths for all defined points. |
||
161 | * |
||
162 | * @return Path[][] Two-dimensional array of Path objects. |
||
163 | * @throws Exception Method throws exception when generate() method throws exception. |
||
164 | */ |
||
165 | public function generateAll() |
||
175 | |||
176 | /** |
||
177 | * Method try to find minimal relation to another point from given point. |
||
178 | * |
||
179 | * @param integer[] $unvisited Array of unvisited points' ids. |
||
180 | * @param Path[] $paths Array of generated Path objects. |
||
181 | * @param integer $point Point integer identifier. |
||
182 | * @return Dijkstra\Relation|null Method returns Relation object or null when minimal relation wasn't found. |
||
183 | */ |
||
184 | private function getMinimalRelation($unvisited, $paths, $point) |
||
203 | |||
204 | /** |
||
205 | * Method updates existing Path object or create new if it's possible. |
||
206 | * |
||
207 | * @param Path[] &$paths Array of generated Path[] objects. Given by reference. |
||
208 | * @param integer $point Integer point identifier. |
||
209 | */ |
||
210 | public function updatePaths(&$paths, $point) |
||
224 | } |
||
225 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.