BreadcrumbTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 18.46 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 2
dl 12
loc 65
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testEmpty() 0 9 2
A testGet() 0 8 1
B testAdd() 12 24 3

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
/*
4
 * This file is part of the Tadcka package.
5
 *
6
 * (c) Tadas Gliaubicas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tadcka\Component\Breadcrumbs\Tests;
13
14
use Tadcka\Component\Breadcrumbs\Breadcrumb;
15
16
/**
17
 * @author Tadas Gliaubicas <[email protected]>
18
 *
19
 * @since 10/30/14 11:29 PM
20
 */
21
class BreadcrumbTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var Breadcrumb
25
     */
26
    private $breadcrumb;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function setUp()
32
    {
33
        $this->breadcrumb = new Breadcrumb();
34
    }
35
36
    /**
37
     * Test empty breadcrumb.
38
     */
39
    public function testEmpty()
40
    {
41
        $count = 0;
42
        foreach ($this->breadcrumb as $item) {
43
            $count++;
44
        }
45
46
        $this->assertEquals(0, $count);
47
    }
48
49
    /**
50
     * Test breadcrumb add method.
51
     */
52
    public function testAdd()
53
    {
54
        $this->breadcrumb->add('title_0', 'url_0');
55
        $this->breadcrumb->add('title_1', 'url_1');
56
        $this->breadcrumb->add('title_2', 'url_2');
57
58
        $count = 0;
59 View Code Duplication
        foreach ($this->breadcrumb as $key => $item) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
60
            $count++;
61
62
            $this->assertEquals('title_' . $key, $item['title']);
63
            $this->assertEquals('url_' . $key, $item['url']);
64
        }
65
66
        $this->assertEquals(3, $count);
67
68
        // Double iterator.
69 View Code Duplication
        foreach ($this->breadcrumb as $key => $item) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
70
            $count++;
71
72
            $this->assertEquals('title_' . $key, $item['title']);
73
            $this->assertEquals('url_' . $key, $item['url']);
74
        }
75
    }
76
77
    public function testGet()
78
    {
79
        $this->breadcrumb->add('title_0', 'url_0');
80
        $this->breadcrumb->add('title_1', 'url_1');
81
82
        $this->assertEquals($this->breadcrumb->get(0), ['title' => 'title_0', 'url' => 'url_0']);
83
        $this->assertEquals($this->breadcrumb->get(1), ['title' => 'title_1', 'url' => 'url_1']);
84
    }
85
}
86