Completed
Push — 2.x-dev ( 55a3c1...c10cce )
by Doug
33:44
created

PackerTest   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 578
Duplicated Lines 36.33 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 17
Bugs 4 Features 0
Metric Value
wmc 35
lcom 1
cbo 5
dl 210
loc 578
rs 9
c 17
b 4
f 0

27 Methods

Rating   Name   Duplication   Size   Complexity  
A testPackThreeItemsFitEasilyInSmallerOfTwoBoxes() 23 23 1
A testPackThreeItemsFitEasilyInLargerOfTwoBoxes() 23 23 1
B testPackFiveItemsTwoLargeOneSmallBox() 40 40 1
B testPackFiveItemsTwoLargeOneSmallBoxButThreeAfterRepack() 40 40 1
A testPackThreeItemsOneDoesntFitInAnyBox() 0 18 1
A testPackWithoutBox() 0 13 1
A testIssue1() 0 12 1
A testIssue3() 0 11 1
A testIssue6() 0 14 1
A testIssue9() 10 10 1
A testIssue11() 11 11 1
A testIssue13() 0 12 1
A testIssue14() 0 12 1
A testIssue47A() 9 9 1
A testIssue47B() 9 9 1
A testIssue47C() 9 9 1
A testIssue47D() 9 9 1
B testPackerPacksRotatedBoxesInNewRow() 0 33 1
A testIssue52A() 0 12 1
A testIssue52B() 0 15 1
A testIssue52C() 0 21 1
A testIssue79() 0 16 1
A testCanSetMaxBoxesToWeightBalance() 0 6 1
A testWeightRedistributionActivatesUnderLimit() 13 13 1
A testWeightRedistributionDoesNotActivateOverLimit() 14 14 1
B testCanPackRepresentativeLargerSamples() 0 67 5
B getSamples() 0 66 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Box packing (3D bin packing, knapsack problem)
4
 * @package BoxPacker
5
 * @author Doug Wright
6
 */
7
8
namespace DVDoug\BoxPacker;
9
10
use DVDoug\BoxPacker\Test\TestBox;
11
use DVDoug\BoxPacker\Test\TestItem;
12
use PHPUnit\Framework\TestCase;
13
14
class PackerTest extends TestCase
15
{
16 View Code Duplication
    public function testPackThreeItemsFitEasilyInSmallerOfTwoBoxes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
    {
18
19
        $box1 = new TestBox('Le petite box', 300, 300, 10, 10, 296, 296, 8, 1000);
20
        $box2 = new TestBox('Le grande box', 3000, 3000, 100, 100, 2960, 2960, 80, 10000);
21
22
        $item1 = new TestItem('Item 1', 250, 250, 2, 200, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23
        $item2 = new TestItem('Item 2', 250, 250, 2, 200, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
        $item3 = new TestItem('Item 3', 250, 250, 2, 200, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
25
26
        $packer = new Packer();
27
        $packer->addBox($box1);
28
        $packer->addBox($box2);
29
        $packer->addItem($item1);
30
        $packer->addItem($item2);
31
        $packer->addItem($item3);
32
        $packedBoxes = $packer->pack();
33
34
        self::assertEquals(1, $packedBoxes->count());
35
        self::assertEquals(3, $packedBoxes->top()->getItems()->count());
36
        self::assertEquals($box1, $packedBoxes->top()->getBox());
37
        self::assertEquals(610, $packedBoxes->top()->getWeight());
38
    }
39
40 View Code Duplication
    public function testPackThreeItemsFitEasilyInLargerOfTwoBoxes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
43
        $box1 = new TestBox('Le petite box', 300, 300, 10, 10, 296, 296, 8, 1000);
44
        $box2 = new TestBox('Le grande box', 3000, 3000, 100, 100, 2960, 2960, 80, 10000);
45
46
        $item1 = new TestItem('Item 1', 2500, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
        $item2 = new TestItem('Item 2', 2500, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
        $item3 = new TestItem('Item 3', 2500, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
50
        $packer = new Packer();
51
        $packer->addBox($box1);
52
        $packer->addBox($box2);
53
        $packer->addItem($item1);
54
        $packer->addItem($item2);
55
        $packer->addItem($item3);
56
        $packedBoxes = $packer->pack();
57
58
        self::assertEquals(1, $packedBoxes->count());
59
        self::assertEquals(3, $packedBoxes->top()->getItems()->count());
60
        self::assertEquals($box2, $packedBoxes->top()->getBox());
61
        self::assertEquals(6100, $packedBoxes->top()->getWeight());
62
    }
63
64 View Code Duplication
    public function testPackFiveItemsTwoLargeOneSmallBox()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
67
        $box1 = new TestBox('Le petite box', 600, 600, 10, 10, 596, 596, 8, 1000);
68
        $box2 = new TestBox('Le grande box', 3000, 3000, 50, 100, 2960, 2960, 40, 10000);
69
70
        $item1 = new TestItem('Item 1', 2500, 2500, 20, 500, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
        $item2 = new TestItem('Item 2', 550, 550, 2, 500, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
72
        $item3 = new TestItem('Item 3', 2500, 2500, 20, 500, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
73
        $item4 = new TestItem('Item 4', 2500, 2500, 20, 500, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74
        $item5 = new TestItem('Item 5', 2500, 2500, 20, 500, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
75
76
        $packer = new Packer();
77
        $packer->addBox($box1);
78
        $packer->addBox($box2);
79
        $packer->addItem($item1);
80
        $packer->addItem($item2);
81
        $packer->addItem($item3);
82
        $packer->addItem($item4);
83
        $packer->addItem($item5);
84
        $packedBoxes = $packer->pack();
85
86
        self::assertEquals(3, $packedBoxes->count());
87
88
        self::assertEquals(2, $packedBoxes->top()->getItems()->count());
89
        self::assertEquals($box2, $packedBoxes->top()->getBox());
90
        self::assertEquals(1100, $packedBoxes->top()->getWeight());
91
92
        $packedBoxes->extract();
93
94
        self::assertEquals(2, $packedBoxes->top()->getItems()->count());
95
        self::assertEquals($box2, $packedBoxes->top()->getBox());
96
        self::assertEquals(1100, $packedBoxes->top()->getWeight());
97
98
        $packedBoxes->extract();
99
100
        self::assertEquals(1, $packedBoxes->top()->getItems()->count());
101
        self::assertEquals($box1, $packedBoxes->top()->getBox());
102
        self::assertEquals(510, $packedBoxes->top()->getWeight());
103
    }
104
105 View Code Duplication
    public function testPackFiveItemsTwoLargeOneSmallBoxButThreeAfterRepack()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
    {
107
108
        $box1 = new TestBox('Le petite box', 600, 600, 10, 10, 596, 596, 8, 1000);
109
        $box2 = new TestBox('Le grande box', 3000, 3000, 50, 100, 2960, 2960, 40, 10000);
110
111
        $item1 = new TestItem('Item 1', 2500, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
112
        $item2 = new TestItem('Item 2', 550, 550, 2, 200, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
113
        $item3 = new TestItem('Item 3', 2500, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
114
        $item4 = new TestItem('Item 4', 2500, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
115
        $item5 = new TestItem('Item 5', 2500, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
116
117
        $packer = new Packer();
118
        $packer->addBox($box1);
119
        $packer->addBox($box2);
120
        $packer->addItem($item1);
121
        $packer->addItem($item2);
122
        $packer->addItem($item3);
123
        $packer->addItem($item4);
124
        $packer->addItem($item5);
125
        $packedBoxes = $packer->pack();
126
127
        self::assertEquals(3, $packedBoxes->count());
128
129
        self::assertEquals(2, $packedBoxes->top()->getItems()->count());
130
        self::assertEquals($box2, $packedBoxes->top()->getBox());
131
        self::assertEquals(4100, $packedBoxes->top()->getWeight());
132
133
        $packedBoxes->extract();
134
135
        self::assertEquals(2, $packedBoxes->top()->getItems()->count());
136
        self::assertEquals($box2, $packedBoxes->top()->getBox());
137
        self::assertEquals(2300, $packedBoxes->top()->getWeight());
138
139
        $packedBoxes->extract();
140
141
        self::assertEquals(1, $packedBoxes->top()->getItems()->count());
142
        self::assertEquals($box2, $packedBoxes->top()->getBox());
143
        self::assertEquals(2100, $packedBoxes->top()->getWeight());
144
    }
145
146
    /**
147
     * @expectedException \DVDoug\BoxPacker\ItemTooLargeException
148
     */
149
    public function testPackThreeItemsOneDoesntFitInAnyBox()
150
    {
151
152
        $box1 = new TestBox('Le petite box', 300, 300, 10, 10, 296, 296, 8, 1000);
153
        $box2 = new TestBox('Le grande box', 3000, 3000, 100, 100, 2960, 2960, 80, 10000);
154
155
        $item1 = new TestItem('Item 1', 2500, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
156
        $item2 = new TestItem('Item 2', 25000, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
157
        $item3 = new TestItem('Item 3', 2500, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
158
159
        $packer = new Packer();
160
        $packer->addBox($box1);
161
        $packer->addBox($box2);
162
        $packer->addItem($item1);
163
        $packer->addItem($item2);
164
        $packer->addItem($item3);
165
        $packedBoxes = $packer->pack();
0 ignored issues
show
Unused Code introduced by
$packedBoxes is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
166
    }
167
168
    /**
169
     * @expectedException \DVDoug\BoxPacker\ItemTooLargeException
170
     */
171
    public function testPackWithoutBox()
172
    {
173
174
        $item1 = new TestItem('Item 1', 2500, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
175
        $item2 = new TestItem('Item 2', 25000, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
176
        $item3 = new TestItem('Item 3', 2500, 2500, 20, 2000, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
177
178
        $packer = new Packer();
179
        $packer->addItem($item1);
180
        $packer->addItem($item2);
181
        $packer->addItem($item3);
182
        $packedBoxes = $packer->pack();
0 ignored issues
show
Unused Code introduced by
$packedBoxes is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
183
    }
184
185
    public function testIssue1()
186
    {
187
188
        $packer = new Packer();
189
        $packer->addBox(new TestBox('Le petite box', 292, 336, 60, 10, 292, 336, 60, 9000));
190
        $packer->addBox(new TestBox('Le grande box', 421, 548, 335, 100, 421, 548, 335, 10000));
191
        $packer->addItem(new TestItem('Item 1', 226, 200, 40, 440, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
192
        $packer->addItem(new TestItem('Item 2', 200, 200, 155, 1660, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
193
        $packedBoxes = $packer->pack();
194
195
        self::assertEquals(1, $packedBoxes->count());
196
    }
197
198
    public function testIssue3()
199
    {
200
201
        $packer = new Packer();
202
        $packer->addBox(new TestBox('OW Box 1', 51, 33, 33, 0.6, 51, 33, 33, 0.6));
203
        $packer->addBox(new TestBox('OW Box 2', 50, 40, 40, 0.95, 50, 40, 40, 0.95));
204
        $packer->addItem(new TestItem('Product', 28, 19, 9, 0, true), 6);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
205
        $packedBoxes = $packer->pack();
206
207
        self::assertEquals(1, $packedBoxes->count());
208
    }
209
210
    public function testIssue6()
211
    {
212
213
        $packer = new Packer();
214
        $packer->addBox(new TestBox('Package 22', 675, 360, 210, 2, 670, 355, 204, 1000));
215
        $packer->addBox(new TestBox('Package 2', 330, 130, 102, 2, 335, 135, 107, 1000));
216
        $packer->addItem(new TestItem('Item 3', 355.6, 335.28, 127, 1.5, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
217
        $packer->addItem(new TestItem('Item 7', 330.2, 127, 101.6, 1, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
218
        $packer->addItem(new TestItem('Item 7', 330.2, 127, 101.6, 1, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
219
        $packedBoxes = $packer->pack();
220
221
        self::assertEquals(1, $packedBoxes->count());
222
223
    }
224
225 View Code Duplication
    public function testIssue9()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
226
    {
227
        $packer = new Packer();
228
        $packer->addBox(new TestBox('24x24x24Box', 24, 24, 24, 24, 24, 24, 24, 100));
229
230
        $packer->addItem(new TestItem('6x6x6Item', 6, 6, 6, 1, true), 64);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
231
        $packedBoxes = $packer->pack();
232
233
        self::assertEquals(1, $packedBoxes->count());
234
    }
235
236 View Code Duplication
    public function testIssue11()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
237
    {
238
        $packer = new Packer();
239
        $packer->addBox(new TestBox('4x4x4Box', 4, 4, 4, 4, 4, 4, 4, 100));
240
241
        $packer->addItem(new TestItem('BigItem', 2, 2, 4, 1, true), 2);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
242
        $packer->addItem(new TestItem('SmallItem', 1, 1, 1, 1, true), 32);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
243
        $packedBoxes = $packer->pack();
244
245
        self::assertEquals(1, $packedBoxes->count());
246
    }
247
248
    public function testIssue13()
249
    {
250
        $packer = new Packer();
251
        $packer->addBox(new TestBox('Le petite box', 12, 12, 12, 10, 10, 10, 10, 1000));
252
253
        $packer->addItem(new TestItem('Item 1', 5, 3, 2, 2, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
254
        $packer->addItem(new TestItem('Item 2', 5, 3, 2, 2, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
255
        $packer->addItem(new TestItem('Item 3', 3, 3, 3, 3, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
256
        $packedBoxes = $packer->pack();
257
258
        self::assertEquals(1, $packedBoxes->count());
259
    }
260
261
    public function testIssue14()
262
    {
263
        $packer = new Packer();
264
        $packer->addBox(new TestBox('29x1x23Box', 29, 1, 23, 0, 29, 1, 23, 100));
265
        $packer->addItem(new TestItem('13x1x10Item', 13, 1, 10, 1, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
266
        $packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
267
        $packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
268
        $packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
269
        $packedBoxes = $packer->pack();
270
271
        self::assertEquals(1, $packedBoxes->count());
272
    }
273
274 View Code Duplication
    public function testIssue47A()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
275
    {
276
        $packer = new Packer();
277
        $packer->addBox(new TestBox('165x225x25Box', 165, 225, 25, 0, 165, 225, 25, 100));
278
        $packer->addItem(new TestItem('20x69x20Item', 20, 69, 20, 0, true), 23);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
279
        $packedBoxes = $packer->pack();
280
281
        self::assertEquals(1, $packedBoxes->count());
282
    }
283
284 View Code Duplication
    public function testIssue47B()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
285
    {
286
        $packer = new Packer();
287
        $packer->addBox(new TestBox('165x225x25Box', 165, 225, 25, 0, 165, 225, 25, 100));
288
        $packer->addItem(new TestItem('20x69x20Item', 69, 20, 20, 0, true), 23);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
289
        $packedBoxes = $packer->pack();
290
291
        self::assertEquals(1, $packedBoxes->count());
292
    }
293
294 View Code Duplication
    public function testIssue47C()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
295
    {
296
        $packer = new Packer();
297
        $packer->addBox(new TestBox('Box', 11.75, 23.6875, 3, 0, 11.75, 23.6875, 3, 70));
298
        $packer->addItem(new TestItem('Item', 3.75, 6.5, 3, 0, true), 9);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
299
        $packedBoxes = $packer->pack();
300
301
        self::assertEquals(1, $packedBoxes->count());
302
    }
303
304 View Code Duplication
    public function testIssue47D()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
305
    {
306
        $packer = new Packer();
307
        $packer->addBox(new TestBox('Box', 11.75, 23.6875, 3, 0, 11.75, 23.6875, 3, 70));
308
        $packer->addItem(new TestItem('Item', 6.5, 3.75, 3, 0, true), 9);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
309
        $packedBoxes = $packer->pack();
310
311
        self::assertEquals(1, $packedBoxes->count());
312
    }
313
314
    public function testPackerPacksRotatedBoxesInNewRow()
315
    {
316
        $packer = new Packer();
317
        $packer->addItem(new TestItem('30x10x30item', 30, 10, 30, 0, true), 9);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
318
319
        //Box can hold 7 items in a row and then is completely full, so 9 items won't fit
320
        $packer->addBox(new TestBox('30x70x30InternalBox', 30, 70, 30, 0, 30, 70, 30, 0, 1000));
0 ignored issues
show
Unused Code introduced by
The call to TestBox::__construct() has too many arguments starting with 1000.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
321
        $packedBoxes = $packer->pack();
322
        self::assertEquals(2, $packedBoxes->count());
323
324
        //Box can hold 7 items in a row, plus two more rotated, making 9 items
325
        // with a 10x10x30 hole in the corner.
326
        //
327
        // Overhead view:
328
        //
329
        // +--+--++
330
        // ++++++++
331
        // ||||||||
332
        // ++++++++
333
        //
334
        $packer = new Packer();
335
        $packer->addItem(new TestItem('30x10x30item', 30, 10, 30, 0, true), 9);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
336
        $packer->addBox(new TestBox('40x70x30InternalBox', 40, 70, 30, 0, 40, 70, 30, 0, 1000));
0 ignored issues
show
Unused Code introduced by
The call to TestBox::__construct() has too many arguments starting with 1000.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
337
        $packedBoxes = $packer->pack();
338
        self::assertEquals(1, $packedBoxes->count());
339
340
        // Make sure that it doesn't try to fit in a 10th item
341
        $packer = new Packer();
342
        $packer->addItem(new TestItem('30x10x30item', 30, 10, 30, 0, true), 10);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
343
        $packer->addBox(new TestBox('40x70x30InternalBox', 40, 70, 30, 0, 40, 70, 30, 0, 1000));
0 ignored issues
show
Unused Code introduced by
The call to TestBox::__construct() has too many arguments starting with 1000.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
344
        $packedBoxes = $packer->pack();
345
        self::assertEquals(2, $packedBoxes->count());
346
    }
347
348
    public function testIssue52A()
349
    {
350
        $packer = new Packer();
351
        $packer->addBox(new TestBox('Box', 100, 50, 50, 0, 100, 50, 50, 5000));
352
        $packer->addItem(new TestItem('Item', 15, 13, 8, 407, true), 2);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
353
        $packedBoxes = $packer->pack();
354
355
        self::assertEquals(1, $packedBoxes->count());
356
        self::assertEquals(26, $packedBoxes->top()->getUsedWidth());
357
        self::assertEquals(15, $packedBoxes->top()->getUsedLength());
358
        self::assertEquals(8, $packedBoxes->top()->getUsedDepth());
359
    }
360
361
    public function testIssue52B()
362
    {
363
        $packer = new Packer();
364
        $packer->addBox(new TestBox('Box',370,375,60,140,364,374,40,3000));
365
        $packer->addItem(new TestItem('Item 1',220,310,12,679, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
366
        $packer->addItem(new TestItem('Item 2',210,297,11,648, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
367
        $packer->addItem(new TestItem('Item 3',210,297,5,187, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
368
        $packer->addItem(new TestItem('Item 4',148,210,32,880, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
369
        $packedBoxes = $packer->pack();
370
371
        self::assertEquals(1, $packedBoxes->count());
372
        self::assertEquals(310, $packedBoxes->top()->getUsedWidth());
373
        self::assertEquals(368, $packedBoxes->top()->getUsedLength());
374
        self::assertEquals(32, $packedBoxes->top()->getUsedDepth());
375
    }
376
377
    public function testIssue52C()
378
    {
379
        $packer = new Packer();
380
        $packer->addBox(new TestBox('Box',230,300,240,160,230,300,240,15000));
381
        $packer->addItem(new TestItem('Item 1',210,297,4,213, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
382
        $packer->addItem(new TestItem('Item 2',80,285,70,199, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
383
        $packer->addItem(new TestItem('Item 3',80,285,70,199, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
384
        $packedBoxes = $packer->pack();
385
386
        self::assertEquals(2, $packedBoxes->count());
387
        $box1 = $packedBoxes->extract();
388
        $box2 = $packedBoxes->extract();
389
390
        self::assertEquals(160, $box1->getUsedWidth());
391
        self::assertEquals(285, $box1->getUsedLength());
392
        self::assertEquals(70, $box1->getUsedDepth());
393
394
        self::assertEquals(210, $box2->getUsedWidth());
395
        self::assertEquals(297, $box2->getUsedLength());
396
        self::assertEquals(4, $box2->getUsedDepth());
397
    }
398
399
    public function testIssue79()
400
    {
401
        $packer = new Packer();
402
        $packer->addBox(new TestBox('Bundle', 75, 15, 15, 0, 75, 15, 15, 30));
403
        $packer->addItem(new TestItem('Item 1', 14, 12, 2, 2, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
404
        $packer->addItem(new TestItem('Item 2', 14, 12, 2, 2, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
405
        $packer->addItem(new TestItem('Item 3', 14, 12, 2, 2, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
406
        $packer->addItem(new TestItem('Item 4', 14, 12, 2, 2, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
407
        $packer->addItem(new TestItem('Item 5', 14, 12, 2, 2, true));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
408
        $packedBoxes = $packer->pack();
409
        $box = $packedBoxes->extract();
410
411
        self::assertEquals(60, $box->getUsedWidth());
412
        self::assertEquals(14, $box->getUsedLength());
413
        self::assertEquals(2, $box->getUsedDepth());
414
    }
415
416
    public function testCanSetMaxBoxesToWeightBalance()
417
    {
418
        $packer = new Packer();
419
        $packer->setMaxBoxesToBalanceWeight(3);
420
        self::assertEquals(3, $packer->getMaxBoxesToBalanceWeight());
421
    }
422
423 View Code Duplication
    public function testWeightRedistributionActivatesUnderLimit()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
424
    {
425
        $packer = new Packer();
426
        $packer->addBox(new TestBox('Box', 1, 1, 3, 0, 1, 1, 3, 3));
427
        $packer->addItem(new TestItem('Item', 1, 1, 1, 1, false), 4);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
428
        $packedBoxes = $packer->pack();
429
430
        $box1 = $packedBoxes->extract();
431
        $box2 = $packedBoxes->extract();
432
433
        self::assertEquals(2, $box1->getItems()->count());
434
        self::assertEquals(2, $box2->getItems()->count());
435
    }
436
437 View Code Duplication
    public function testWeightRedistributionDoesNotActivateOverLimit()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
438
    {
439
        $packer = new Packer();
440
        $packer->addBox(new TestBox('Box', 1, 1, 3, 0, 1, 1, 3, 3));
441
        $packer->addItem(new TestItem('Item', 1, 1, 1, 1, false), 4);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
442
        $packer->setMaxBoxesToBalanceWeight(1);
443
        $packedBoxes = $packer->pack();
444
445
        $box1 = $packedBoxes->extract();
446
        $box2 = $packedBoxes->extract();
447
448
        self::assertEquals(3, $box1->getItems()->count());
449
        self::assertEquals(1, $box2->getItems()->count());
450
    }
451
452
    /**
453
     * @dataProvider getSamples
454
     * @coversNothing
455
     */
456
    public function testCanPackRepresentativeLargerSamples(
457
        $test,
0 ignored issues
show
Unused Code introduced by
The parameter $test is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
458
        $boxes,
459
        $items,
460
        $expectedBoxes2D,
461
        $expectedBoxes3D,
462
        $expectedWeightVariance2D,
463
        $expectedWeightVariance3D
464
    ) {
465
        $expectedItemCount = 0;
466
467
        $packer2D = new Packer();
468
        $packer3D = new Packer();
469
470
        foreach ($boxes as $box) {
471
            $packer2D->addBox($box);
472
            $packer3D->addBox($box);
473
        }
474
        foreach ($items as $item) {
475
            $expectedItemCount += $item['qty'];
476
477
            $packer2D->addItem(
478
                new TestItem(
479
                    $item['name'],
480
                    $item['width'],
481
                    $item['length'],
482
                    $item['depth'],
483
                    $item['weight'],
484
                    true
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
485
                ),
486
                $item['qty']
487
            );
488
489
            $packer3D->addItem(
490
                new TestItem(
491
                    $item['name'],
492
                    $item['width'],
493
                    $item['length'],
494
                    $item['depth'],
495
                    $item['weight'],
496
                    false
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
497
                ),
498
                $item['qty']
499
            );
500
        }
501
        $packedBoxes2D = $packer2D->pack();
502
        $packedBoxes3D = $packer3D->pack();
503
504
        $packedItemCount2D = 0;
505
        foreach (clone $packedBoxes2D as $packedBox) {
506
            $packedItemCount2D += $packedBox->getItems()->count();
507
        }
508
509
        $packedItemCount3D = 0;
510
        foreach (clone $packedBoxes3D as $packedBox) {
511
            $packedItemCount3D += $packedBox->getItems()->count();
512
        }
513
514
515
        self::assertEquals($expectedBoxes2D, $packedBoxes2D->count());
516
        self::assertEquals($expectedItemCount, $packedItemCount2D);
517
        self::assertEquals($expectedWeightVariance2D, (int)$packedBoxes2D->getWeightVariance());
518
519
        self::assertEquals($expectedBoxes3D, $packedBoxes3D->count());
520
        self::assertEquals($expectedItemCount, $packedItemCount3D);
521
        self::assertEquals($expectedWeightVariance3D, (int)$packedBoxes3D->getWeightVariance());
522
    }
523
524
    public function getSamples()
525
    {
526
        $expected = ['2D' => [], '3D' => []];
527
528
        $expected2DData = fopen(__DIR__ . '/data/expected.csv', 'r');
529
        while ($data = fgetcsv($expected2DData)) {
530
            $expected['2D'][$data[0]] = array('boxes' => $data[1], 'weightVariance' => $data[2]);
531
            $expected['3D'][$data[0]] = array('boxes' => $data[3], 'weightVariance' => $data[4]);
532
        }
533
        fclose($expected2DData);
534
535
        $boxes = [];
536
        $boxData = fopen(__DIR__ . '/data/boxes.csv', 'r');
537
        while ($data = fgetcsv($boxData)) {
538
            $boxes[] = new TestBox(
539
                $data[0],
540
                $data[1],
541
                $data[2],
542
                $data[3],
543
                $data[4],
544
                $data[5],
545
                $data[6],
546
                $data[7],
547
                $data[8]
548
            );
549
        }
550
        fclose($boxData);
551
552
        $tests = [];
553
        $itemData = fopen(__DIR__ . '/data/items.csv', 'r');
554
        while ($data = fgetcsv($itemData)) {
555
556
            if (isset($tests[$data[0]])) {
557
                $tests[$data[0]]['items'][] = array(
558
                    'qty' => $data[1],
559
                    'name' => $data[2],
560
                    'width' => $data[3],
561
                    'length' => $data[4],
562
                    'depth' => $data[5],
563
                    'weight' => $data[6]
564
                );
565
            } else {
566
                $tests[$data[0]] = array(
567
                    'test' => $data[0],
568
                    'boxes' => $boxes,
569
                    'items' => array(
570
                        array(
571
                            'qty' => $data[1],
572
                            'name' => $data[2],
573
                            'width' => $data[3],
574
                            'length' => $data[4],
575
                            'depth' => $data[5],
576
                            'weight' => $data[6]
577
                        )
578
                    ),
579
                    'expected2D' => $expected['2D'][$data[0]]['boxes'],
580
                    'expected3D' => $expected['3D'][$data[0]]['boxes'],
581
                    'weightVariance2D' => $expected['2D'][$data[0]]['weightVariance'],
582
                    'weightVariance3D' => $expected['3D'][$data[0]]['weightVariance']
583
                );
584
            }
585
        }
586
        fclose($itemData);
587
588
        return $tests;
589
    }
590
591
}
592