Completed
Push — master ( 5c5133...4bc4b0 )
by Marcin
02:40
created

ApiTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 59.38 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 7
dl 57
loc 96
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testGetClient() 0 4 1
A testGetCommune() 0 4 1
A testNotFound() 0 4 1
A testNtsConvert_one() 11 11 1
A testNtsConvert_two() 11 11 1
A testSearchCommune() 7 7 1
A testSearchDistrict() 7 7 1
A testSearchKrsEntity() 7 7 1
A testSearchKrsEntityType() 7 7 1
A testSearchProvince() 7 7 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
 * MOJEPANSTWO-API
4
 *
5
 * Copyright © 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 */
14
15
16
namespace mrcnpdlk\MojePanstwo;
17
18
19
use mrcnpdlk\MojePanstwo\Model\Address\Commune;
20
use mrcnpdlk\MojePanstwo\Model\Address\District;
21
use mrcnpdlk\MojePanstwo\Model\Address\Nts;
22
use mrcnpdlk\MojePanstwo\Model\Address\Province;
23
use mrcnpdlk\MojePanstwo\Model\KrsEntity;
24
use mrcnpdlk\MojePanstwo\Model\KrsEntityType;
25
use mrcnpdlk\MojePanstwo\Model\SearchResponse;
26
27
class ApiTest extends TestCase
28
{
29
    /**
30
     * @var \mrcnpdlk\MojePanstwo\Api
31
     */
32
    private $oApi;
33
34
    public function setUp()
35
    {
36
        parent::setUp(); // TODO: Change the autogenerated stub
37
        $oClient    = new \mrcnpdlk\MojePanstwo\Client();
38
        $this->oApi = Api::create($oClient);
39
    }
40
41
    public function testGetClient()
42
    {
43
        $this->assertInstanceOf(Client::class, $this->oApi->getClient());
44
    }
45
46
    public function testGetCommune()
47
    {
48
        $this->assertInstanceOf(Commune::class, $this->oApi->getCommune(1));
49
    }
50
51
    /**
52
     * @expectedException \mrcnpdlk\MojePanstwo\Exception
53
     */
54
    public function testNotFound()
55
    {
56
        $res = $this->oApi->getProvince(111111);
0 ignored issues
show
Unused Code introduced by
$res 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...
57
    }
58
59 View Code Duplication
    public function testNtsConvert_one()
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...
60
    {
61
        $oNts = new Nts('1234567891');
62
        $this->assertEquals('1', $oNts->region_id);
63
        $this->assertEquals('23', $oNts->teryt_wojewodztwo_id);
64
        $this->assertEquals('45', $oNts->podregion_id);
65
        $this->assertEquals('67', $oNts->teryt_powiat_id);
66
        $this->assertEquals('89', $oNts->teryt_gmina_id);
67
        $this->assertEquals('1', $oNts->teryt_gmina_typ_id);
68
        $this->assertEquals(2367891, $oNts->teryt_terc_id);
69
    }
70
71 View Code Duplication
    public function testNtsConvert_two()
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...
72
    {
73
        $oNts = new Nts('11234567891');
74
        $this->assertEquals('1', $oNts->region_id);
75
        $this->assertEquals('23', $oNts->teryt_wojewodztwo_id);
76
        $this->assertEquals('45', $oNts->podregion_id);
77
        $this->assertEquals('67', $oNts->teryt_powiat_id);
78
        $this->assertEquals('89', $oNts->teryt_gmina_id);
79
        $this->assertEquals('1', $oNts->teryt_gmina_typ_id);
80
        $this->assertEquals(2367891, $oNts->teryt_terc_id);
81
    }
82
83 View Code Duplication
    public function testSearchCommune()
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...
84
    {
85
        $res = $this->oApi->searchCommune()->limit(1)->get();
86
        $this->assertInstanceOf(SearchResponse::class, $res);
87
        $this->assertEquals(1, count($res->items));
88
        $this->assertInstanceOf(Commune::class, $res->items[0]->data);
89
    }
90
91 View Code Duplication
    public function testSearchDistrict()
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...
92
    {
93
        $res = $this->oApi->searchDistrict()->limit(1)->get();
94
        $this->assertInstanceOf(SearchResponse::class, $res);
95
        $this->assertEquals(1, count($res->items));
96
        $this->assertInstanceOf(District::class, $res->items[0]->data);
97
    }
98
99 View Code Duplication
    public function testSearchKrsEntity()
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...
100
    {
101
        $res = $this->oApi->searchKrsEntity()->limit(1)->get();
102
        $this->assertInstanceOf(SearchResponse::class, $res);
103
        $this->assertEquals(1, count($res->items));
104
        $this->assertInstanceOf(KrsEntity::class, $res->items[0]->data);
105
    }
106
107 View Code Duplication
    public function testSearchKrsEntityType()
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...
108
    {
109
        $res = $this->oApi->searchKrsEntityType()->limit(1)->get();
110
        $this->assertInstanceOf(SearchResponse::class, $res);
111
        $this->assertEquals(1, count($res->items));
112
        $this->assertInstanceOf(KrsEntityType::class, $res->items[0]->data);
113
    }
114
115 View Code Duplication
    public function testSearchProvince()
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...
116
    {
117
        $res = $this->oApi->searchProvince()->limit(1)->get();
118
        $this->assertInstanceOf(SearchResponse::class, $res);
119
        $this->assertEquals(1, count($res->items));
120
        $this->assertInstanceOf(Province::class, $res->items[0]->data);
121
    }
122
}
123