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

RulebookTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 94
Duplicated Lines 53.19 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 8
dl 50
loc 94
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A tearDown() 0 4 1
A testExecute() 11 11 1
A testExecuteClassNotFound() 10 10 1
A testExecuteInvalidClass() 14 14 1
A testExecuteValidRule() 15 15 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\Config;
13
use CaptainHook\App\Console\IO\NullIO;
14
use CaptainHook\App\Git\CommitMessage;
15
use CaptainHook\App\Git\DummyRepo;
16
use CaptainHook\App\Git\Repository;
17
18
class RulebookTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @var \CaptainHook\App\Git\DummyRepo
22
     */
23
    private $repo;
24
25
    /**
26
     * Setup dummy repo.
27
     */
28
    public function setUp()
29
    {
30
        $this->repo = new DummyRepo();
31
        $this->repo->setup();
32
    }
33
34
    /**
35
     * Cleanup dummy repo.
36
     */
37
    public function tearDown()
38
    {
39
        $this->repo->cleanup();
40
    }
41
42
    /**
43
     * Tests Rulebook::execute
44
     */
45 View Code Duplication
    public function testExecute()
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...
46
    {
47
        $io     = new NullIO();
48
        $config = new Config(HMU_PATH_FILES . '/captainhook.json');
49
        $action = new Config\Action('php', '\\CaptainHook\\App\\Hook\\Message\\Beams');
50
        $repo   = new Repository($this->repo->getPath());
51
        $repo->setCommitMsg(new CommitMessage('Foo bar baz'));
52
53
        $standard = new Beams();
54
        $standard->execute($config, $io, $repo, $action);
55
    }
56
57
    /**
58
     * Tests Rulebook::execute
59
     *
60
     * @expectedException \Exception
61
     */
62 View Code Duplication
    public function testExecuteClassNotFound()
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
        $io     = new NullIO();
65
        $config = new Config(HMU_PATH_FILES . '/captainhook.json');
66
        $action = new Config\Action('php', '\\CaptainHook\\App\\Hook\\Message\\Rulebook', ['\\CaptainHook\\App\\Foo']);
67
        $repo   = new Repository($this->repo->getPath());
68
69
        $standard = new Rulebook();
70
        $standard->execute($config, $io, $repo, $action);
71
    }
72
73
    /**
74
     * Tests Rulebook::execute
75
     *
76
     * @expectedException \Exception
77
     */
78 View Code Duplication
    public function testExecuteInvalidClass()
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...
79
    {
80
        $io     = new NullIO();
81
        $config = new Config(HMU_PATH_FILES . '/captainhook.json');
82
        $action = new Config\Action(
83
            'php',
84
            '\\CaptainHook\\App\\Hook\\Message\\Rulebook',
85
            ['\\CaptainHook\\App\\Hook\\Message\\Validator']
86
        );
87
        $repo   = new Repository($this->repo->getPath());
88
89
        $standard = new Rulebook();
90
        $standard->execute($config, $io, $repo, $action);
91
    }
92
93
    /**
94
     * Tests Rulebook::execute
95
     */
96 View Code Duplication
    public function testExecuteValidRule()
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...
97
    {
98
        $io     = new NullIO();
99
        $config = new Config(HMU_PATH_FILES . '/captainhook.json');
100
        $action = new Config\Action(
101
            'php',
102
            '\\CaptainHook\\App\\Hook\\Message\\Rulebook',
103
            ['\\CaptainHook\\App\\Hook\\Message\\Validator\\Rule\\CapitalizeSubject']
104
        );
105
        $repo   = new Repository($this->repo->getPath());
106
        $repo->setCommitMsg(new CommitMessage('Foo bar baz'));
107
108
        $standard = new Rulebook();
109
        $standard->execute($config, $io, $repo, $action);
110
    }
111
}
112