Completed
Push — master ( 4025c4...856f8c )
by Nikita
02:41
created

IndexTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 34.78 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 16
loc 46
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testAll() 16 36 6

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
namespace Taisiya\PropelBundle\Database;
4
5
use Taisiya\PropelBundle\Database\Exception\InvalidArgumentException;
6
use Taisiya\PropelBundle\Database\TestDatabase\FirstTestTable\IdColumn;
7
use Taisiya\PropelBundle\Database\TestDatabase\FirstTestTable\TestIndex;
8
use Taisiya\PropelBundle\PHPUnitTestCase;
9
10
class IndexTest extends PHPUnitTestCase
11
{
12
    /**
13
     * @covers Index::addColumn
14
     * @covers Index::addColumnIfNotExists
15
     * @covers Index::getColumns
16
     * @covers Index::findIndexColumnByName
17
     * @covers Index::removeColumn
18
     */
19
    public function testAll()
20
    {
21
        $index = new TestIndex();
22
23 View Code Duplication
        for ($i = 0; $i < 2; $i++) {
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...
24
            try {
25
                $index->addColumn(new IdColumn());
26
            } catch (InvalidArgumentException $e) {
27
                $this->assertGreaterThan(0, $i);
28
            }
29
            $this->assertCount(1, $index->getColumns());
30
            $this->assertInstanceOf(IdColumn::class, $index->getColumns()[0]->getColumn());
31
            $this->assertNull($index->findIndexColumnByName(IdColumn::getName())->getSize());
32
        }
33
34
        for ($i = 0; $i < 2; $i++) {
35
            try {
36
                $index->removeColumn(IdColumn::getName());
37
            } catch (InvalidArgumentException $e) {
38
                $this->assertGreaterThan(0, $i);
39
            }
40
            $this->assertCount(0, $index->getColumns());
41
        }
42
43 View Code Duplication
        for ($i = 0; $i < 2; $i++) {
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...
44
            $index->addColumnIfNotExists(new IdColumn(), 255);
45
            $this->assertCount(1, $index->getColumns());
46
            $this->assertInstanceOf(IdColumn::class, $index->getColumns()[0]->getColumn());
47
            $this->assertSame(255, $index->findIndexColumnByName(IdColumn::getName())->getSize());
48
        }
49
50
        $index->addColumnIfNotExists(new IdColumn(), 32);
51
        $this->assertCount(1, $index->getColumns());
52
        $this->assertInstanceOf(IdColumn::class, $index->getColumns()[0]->getColumn());
53
        $this->assertSame(32, $index->findIndexColumnByName(IdColumn::getName())->getSize());
54
    }
55
}
56