GetOptionTraitTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 48.48 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 16
loc 33
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetOptionWillReturnTheOption() 8 8 1
A testGetOptionWillReturnADefaultValueIfTheValueDoesNotExist() 0 5 1
A testRequireOptionWillReturnAnOptionIfItExists() 8 8 1
A testRequireOptionWillThrowAnExceptionIfTheOptionDoesNotExist() 0 6 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
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Test\Unit\Helper;
15
16
use Graze\DataFile\Test\Helper\FakeGetOption;
17
use Graze\DataFile\Test\TestCase;
18
use InvalidArgumentException;
19
20
class GetOptionTraitTest extends TestCase
21
{
22 View Code Duplication
    public function testGetOptionWillReturnTheOption()
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...
23
    {
24
        $fake = new FakeGetOption();
25
        $fake->setOptions([
26
            'name' => 'value',
27
        ]);
28
        static::assertEquals('value', $fake->checkGetOption('name'));
29
    }
30
31
    public function testGetOptionWillReturnADefaultValueIfTheValueDoesNotExist()
32
    {
33
        $fake = new FakeGetOption();
34
        static::assertEquals('default', $fake->checkGetOption('name', 'default'));
35
    }
36
37 View Code Duplication
    public function testRequireOptionWillReturnAnOptionIfItExists()
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
        $fake = new FakeGetOption();
40
        $fake->setOptions([
41
            'name' => 'value',
42
        ]);
43
        static::assertEquals('value', $fake->checkRequireOption('name'));
44
    }
45
46
    public function testRequireOptionWillThrowAnExceptionIfTheOptionDoesNotExist()
47
    {
48
        $fake = new FakeGetOption();
49
        $this->expectException(InvalidArgumentException::class);
50
        $fake->checkRequireOption('name');
51
    }
52
}
53