dvdoug /
BoxPacker
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Box packing (3D bin packing, knapsack problem) |
||
| 4 | * @package BoxPacker |
||
| 5 | * @author Doug Wright |
||
| 6 | */ |
||
| 7 | namespace DVDoug\BoxPacker; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * List of items to be packed, ordered by volume |
||
| 11 | * @author Doug Wright |
||
| 12 | * @package BoxPacker |
||
| 13 | */ |
||
| 14 | class ItemList extends \SplMaxHeap |
||
| 15 | { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Compare elements in order to place them correctly in the heap while sifting up. |
||
| 19 | * |
||
| 20 | * @see \SplMaxHeap::compare() |
||
| 21 | * |
||
| 22 | * @param mixed $itemA |
||
| 23 | * @param mixed $itemB |
||
| 24 | * |
||
| 25 | * @return int |
||
|
0 ignored issues
–
show
|
|||
| 26 | */ |
||
| 27 | 34 | public function compare($itemA, $itemB) |
|
| 28 | { |
||
| 29 | 34 | if ($itemA->getVolume() > $itemB->getVolume()) { |
|
| 30 | 17 | return 1; |
|
| 31 | 34 | } elseif ($itemA->getVolume() < $itemB->getVolume()) { |
|
| 32 | 14 | return -1; |
|
| 33 | } else { |
||
| 34 | 32 | return $itemA->getWeight() - $itemB->getWeight(); |
|
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Get copy of this list as a standard PHP array |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | 24 | public function asArray() |
|
| 43 | { |
||
| 44 | 24 | $return = []; |
|
| 45 | 24 | foreach (clone $this as $item) { |
|
| 46 | 24 | $return[] = $item; |
|
| 47 | } |
||
| 48 | 24 | return $return; |
|
| 49 | } |
||
| 50 | } |
||
| 51 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.