Completed
Pull Request — master (#117)
by Simone
02:36
created

RulerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 55.32 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 4
dl 26
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B test() 26 26 1
A setUp() 0 4 1
A testCantGetRuleWithoutRecource() 0 4 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
/**
4
 * This file is part of sensorario/resources repository
5
 *
6
 * (c) Simone Gentili <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sensorario\Resources\Test\Resources;
13
14
use Sensorario\Resources\Resource;
15
use Sensorario\Resources\Rulers\Ruler;
16
use Sensorario\Resources\Configurator;
17
use Sensorario\Resources\Container;
18
19
class RulerTest extends \PHPUnit_Framework_TestCase
20
{
21
    /**
22
     * @expectedException \Sensorario\Resources\Exceptions\InvalidCustomValidatorException
23
     * @expectedExceptionMessage Oops! `custom-validator` custom validator is not available. Only email is.
24
     */
25 View Code Duplication
    public function test()
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...
26
    {
27
        $configurator = new Configurator(
28
            'foo',
29
            new Container([
30
                'resources' => [
31
                    'foo' => [
32
                        'constraints' => [
33
                            'allowed' => [
34
                                'property_name',
35
                            ],
36
                            'rules' => [
37
                                'property_name' => [
38
                                    'custom-validator' => 'foo',
39
                                ]
40
                            ]
41
                        ],
42
                    ],
43
                ]
44
            ])
45
        );
46
47
        Resource::box([
48
            'property_name' => '42',
49
        ], $configurator);
50
    }
51
52
    public function setUp()
53
    {
54
        $this->ruler = new Ruler();
0 ignored issues
show
Bug introduced by
The property ruler does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
55
    }
56
57
    /**
58
     * @expectedException \Sensorario\Resources\Exceptions\UndefinedResourceException
59
     * @expectedExceptionMessage Oops! Cant get rule without resource
60
     */
61
    public function testCantGetRuleWithoutRecource()
62
    {
63
        $this->ruler->getRuleFromResource();
64
    }
65
}
66