Completed
Push — 1.x-dev ( 423a53...2f7d84 )
by Doug
48:23 queued 46:55
created

TestConstrainedTestItem::canBePackedInBox()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
/**
3
 * Box packing (3D bin packing, knapsack problem)
4
 * @package BoxPacker
5
 * @author Doug Wright
6
 */
7
8
namespace DVDoug\BoxPacker\Test;
9
10
use DVDoug\BoxPacker\Box;
11
use DVDoug\BoxPacker\ConstrainedItem;
12
use DVDoug\BoxPacker\ItemList;
13
14
class TestConstrainedTestItem extends TestItem implements ConstrainedItem
15
{
16
    /**
17
     * @var int
18
     */
19
    public static $limit = 3;
20
21
    /**
22
     * @param ItemList $alreadyPackedItems
23
     * @param TestBox  $box
24
     *
25
     * @return bool
26
     */
27
    public function canBePackedInBox(ItemList $alreadyPackedItems, Box $box)
28
    {
29
        $alreadyPackedType = array_filter(
30
            $alreadyPackedItems->asArray(),
31
            function(TestItem $item) {
32
                return $item->getDescription() === $this->getDescription();
33
            }
34
        );
35
36
        return count($alreadyPackedType) + 1 <= static::$limit;
37
    }
38
}
39
40