Passed
Push — master ( a32b7c...9671df )
by Andy
02:16
created

BooleanFormatterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 50 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 24
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testTruthyValues() 11 11 1
A testFalseyValues() 13 13 1
A configProvider() 0 13 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
namespace Palmtree\Csv\Test\Formatter;
4
5
use Palmtree\Csv\Formatter\BooleanFormatter;
6
use PHPUnit\Framework\TestCase;
7
8
class BooleanFormatterTest extends TestCase
9
{
10
    /**
11
     * @dataProvider configProvider
12
     */
13 View Code Duplication
    public function testTruthyValues($binaries)
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...
14
    {
15
        $formatter = new BooleanFormatter();
16
        $formatter->setBinaries($binaries);
17
18
        $this->assertTrue($formatter->format('true'));
19
        $this->assertTrue($formatter->format('enabled'));
20
        $this->assertTrue($formatter->format('1'));
21
        $this->assertTrue($formatter->format('on'));
22
        $this->assertFalse($formatter->format('foo'));
23
    }
24
25
    /**
26
     * @dataProvider configProvider
27
     */
28 View Code Duplication
    public function testFalseyValues($binaries)
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...
29
    {
30
        $formatter = new BooleanFormatter();
31
        $formatter->setNullable(true);
32
        $formatter->setBinaries($binaries);
33
34
        $this->assertFalse($formatter->format('false'));
35
        $this->assertFalse($formatter->format('disabled'));
36
        $this->assertFalse($formatter->format('0'));
37
        $this->assertFalse($formatter->format('off'));
38
39
        $this->assertNull($formatter->format('bar'));
40
    }
41
42
    public function configProvider()
43
    {
44
        return [
45
            [
46
                [
47
                    'true'    => 'false',
48
                    'enabled' => 'disabled',
49
                    '1'       => '0',
50
                    'on'      => 'off',
51
                ],
52
            ],
53
        ];
54
    }
55
}
56