* A version of the packer that swallows internal exceptions.
13
*
14
* @author Doug Wright
15
*/
16
class InfalliblePacker extends Packer
17
{
18
/**
19
* @var ItemList
20
*/
21
protected $unpackedItems;
22
23
/**
24
* InfalliblePacker constructor.
25
*/
26
public function __construct()
27
{
28
$this->unpackedItems = new ItemList();
29
parent::__construct();
30
}
31
32
/**
33
* Return the items that couldn't be packed.
34
*/
35
public function getUnpackedItems(): ItemList
36
{
37
return $this->unpackedItems;
38
}
39
40
/**
41
* {@inheritdoc}
42
*/
43
public function pack(): PackedBoxList
44
{
45
foreach ($this->items as $item) {
46
foreach ($this->boxes as $box) {
47
if ($item->getWeight() <= ($box->getMaxWeight() - $box->getEmptyWeight()) && (new OrientatedItemFactory($box))->hasPossibleOrientationsInEmptyBox($item)) {
In this branch, the function will implicitly return null which is incompatible with the type-hinted return DVDoug\BoxPacker\PackedBoxList. Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type.
Let?s take a look at an example:
interfaceReturnsInt{publicfunctionreturnsIntHinted():int;}classMyClassimplementsReturnsInt{publicfunctionreturnsIntHinted():int{if(foo()){return123;}// here: null is implicitly returned}}
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: