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

PackedBoxListTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 88.24 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 6
dl 30
loc 34
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testVolumeUtilisation() 15 15 1
A testWeightVariance() 15 15 1

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 PackedBoxListTest extends TestCase
15
{
16 View Code Duplication
    function testVolumeUtilisation()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
        $box = new TestBox('Box', 10, 10, 10, 10, 10, 10, 10, 10);
19
        $item = new TestItem('Item', 5, 10, 10, 10, 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...
20
21
        $boxItems = new ItemList();
22
        $boxItems->insert($item);
23
24
        $packedBox = new PackedBox($box, $boxItems, 1, 2, 3, 4, 0, 0, 0);
25
26
        $packedBoxList = new PackedBoxList();
27
        $packedBoxList->insert($packedBox);
28
29
        self::assertEquals(50, $packedBoxList->getVolumeUtilisation());
30
    }
31
32 View Code Duplication
    function testWeightVariance()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
33
    {
34
        $box = new TestBox('Box', 10, 10, 10, 10, 10, 10, 10, 10);
35
        $item = new TestItem('Item', 5, 10, 10, 10, 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...
36
37
        $boxItems = new ItemList();
38
        $boxItems->insert($item);
39
40
        $packedBox = new PackedBox($box, $boxItems, 1, 2, 3, 4, 0, 0, 0);
41
42
        $packedBoxList = new PackedBoxList();
43
        $packedBoxList->insert($packedBox);
44
45
        self::assertEquals(0, $packedBoxList->getWeightVariance());
46
    }
47
}
48