Completed
Push — 2.x-dev ( 5f5b4d...48a1b4 )
by Doug
61:10 queued 51:42
created

TestConstrainedTestItem   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
lcom 1
cbo 2
dl 0
loc 25
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Box packing (3D bin packing, knapsack problem).
4
 *
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