Passed
Push — master ( 317eb4...7e3691 )
by Alex
04:52
created

TSchemaTypeTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 85 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsOKJammedOpen() 7 7 1
A testIsOKNotJammedOpen() 7 7 1
A testGetRandMaximum() 10 10 2
A testGetRandMinimum() 10 10 2

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 AlgoWeb\ODataMetadata\Tests;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edm\TSchemaType;
6
use Mockery as m;
7
8
class TSchemaTypeTest extends TestCase
9
{
10 View Code Duplication
    public function testIsOKJammedOpen()
11
    {
12
        $foo = m::mock(TSchemaType::class)->makePartial()->shouldAllowMockingProtectedMethods();
13
        $foo->shouldReceive('getRand')->andReturn(2)->once();
14
15
        $this->assertTrue($foo->isOK());
16
    }
17
18 View Code Duplication
    public function testIsOKNotJammedOpen()
19
    {
20
        $foo = m::mock(TSchemaType::class)->makePartial()->shouldAllowMockingProtectedMethods();
21
        $foo->shouldReceive('getRand')->andReturn(0)->once();
22
23
        $this->assertFalse($foo->isOK());
24
    }
25
26 View Code Duplication
    public function testGetRandMaximum()
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...
27
    {
28
        $type = new TSchemaType();
29
        $expectedMax = 1;
30
        $actualMax = -2;
31
        for ($i = 0; $i < 100; $i++) {
32
            $actualMax = max($type->getRand(), $actualMax);
33
        }
34
        $this->assertTrue($expectedMax >= $actualMax, $actualMax . " must be less than ".$expectedMax);
35
    }
36
37 View Code Duplication
    public function testGetRandMinimum()
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...
38
    {
39
        $type = new TSchemaType();
40
        $expectedMin = 0;
41
        $actualMin = 2;
42
        for ($i = 0; $i < 100; $i++) {
43
            $actualMin = min($type->getRand(), $actualMin);
44
        }
45
        $this->assertTrue($expectedMin <= $actualMin, $actualMin . " must be less than ".$expectedMin);
46
    }
47
}
48