Passed
Push — master ( 813fe9...62056b )
by Sebastian
06:01
created

ValidatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 44.64 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 4
dl 25
loc 56
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testValidOnEmptyRuleList() 0 9 1
A testSetRulesValid() 9 9 1
A testSetRulesInvalid() 7 7 1
A testAddRuleInvalid() 9 9 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 CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace CaptainHook\App\Hook\Message;
11
12
use CaptainHook\App\Git\CommitMessage;
13
use CaptainHook\App\Hook\Message\Validator\Rule\CapitalizeSubject;
14
use CaptainHook\App\Hook\Message\Validator\Rule\MsgNotEmpty;
15
16
class ValidatorTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * Tests Validator::validate
20
     */
21
    public function testValidOnEmptyRuleList()
22
    {
23
        $msg = new CommitMessage('Foo');
24
        $v   = new Validator();
25
26
        $v->validate($msg);
27
        $this->assertTrue(true);
28
29
    }
30
31
    /**
32
     * Tests Validator::setRules
33
     */
34 View Code Duplication
    public function testSetRulesValid()
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...
35
    {
36
        $msg = new CommitMessage('Foo');
37
        $v   = new Validator();
38
        $v->setRules([new MsgNotEmpty()]);
39
40
        $v->validate($msg);
41
        $this->assertTrue(true);
42
    }
43
44
    /**
45
     * Tests Validator::setRules
46
     *
47
     * @expectedException \Exception
48
     */
49 View Code Duplication
    public function testSetRulesInvalid()
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...
50
    {
51
        $msg = new CommitMessage('');
52
        $v   = new Validator();
53
        $v->setRules([new MsgNotEmpty()]);
54
        $v->validate($msg);
55
    }
56
57
    /**
58
     * Tests Validator::setRules
59
     *
60
     * @expectedException \Exception
61
     */
62 View Code Duplication
    public function testAddRuleInvalid()
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...
63
    {
64
        $msg = new CommitMessage('foo bar baz');
65
        $v   = new Validator();
66
        $v->setRules([new MsgNotEmpty()]);
67
        $v->addRule(new CapitalizeSubject());
68
69
        $v->validate($msg);
70
    }
71
}
72