GitTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 95
Duplicated Lines 44.21 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 42
loc 95
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGitStackShallowCloneCommand() 0 11 1
A testGitStackShallowCloneCommandWithDifferentDepth() 0 11 1
A _before() 0 8 1
A testGitStackRun() 0 9 1
A testGitStackCommands() 21 21 2
A testGitStackCommandsWithTagMessage() 21 21 2

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
use AspectMock\Test as test;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, test.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
5
class GitTest extends \Codeception\TestCase\Test
6
{
7
    /**
8
     * @var \AspectMock\Proxy\ClassProxy
9
     */
10
    protected $git;
11
12
    protected function _before()
13
    {
14
        $this->git = test::double('Robo\Task\Vcs\GitStack', [
15
            'executeCommand' => new \AspectMock\Proxy\Anything(),
16
            'output' => new \Symfony\Component\Console\Output\NullOutput(),
17
            'logger' => new \Psr\Log\NullLogger(),
18
        ]);
19
    }
20
21
    // tests
22
    public function testGitStackRun()
23
    {
24
        (new \Robo\Task\Vcs\GitStack('git'))->stopOnFail()->add('-A')->pull()->run();
25
        $this->git->verifyInvoked('executeCommand', ['git add -A']);
26
        $this->git->verifyInvoked('executeCommand', ['git pull']);
27
28
        (new \Robo\Task\Vcs\GitStack('git'))->add('-A')->pull()->run();
29
        $this->git->verifyInvoked('executeCommand', ['git add -A && git pull']);
30
    }
31
32 View Code Duplication
    public function testGitStackCommands()
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...
33
    {
34
        $linuxCmd = "git clone http://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m 'changed' && git push && git tag 0.6.0 && git push origin 0.6.0";
35
36
        $winCmd = 'git clone http://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m "changed" && git push && git tag 0.6.0 && git push origin 0.6.0';
37
38
        $cmd = stripos(PHP_OS, 'WIN') === 0 ? $winCmd : $linuxCmd;
39
40
        $this->assertEquals(
41
            $cmd,
42
            (new \Robo\Task\Vcs\GitStack())
43
                ->cloneRepo('http://github.com/consolidation-org/Robo')
44
                ->pull()
45
                ->add('-A')
46
                ->commit('changed')
47
                ->push()
48
                ->tag('0.6.0')
49
                ->push('origin', '0.6.0')
50
                ->getCommand()
51
        );
52
    }
53
54 View Code Duplication
    public function testGitStackCommandsWithTagMessage()
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...
55
    {
56
        $linuxCmd = "git clone http://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m 'changed' && git push && git tag -m 'message' 0.6.0 && git push origin 0.6.0";
57
58
        $winCmd = 'git clone http://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m "changed" && git push && git tag -m \'message\' 0.6.0 && git push origin 0.6.0';
59
60
        $cmd = stripos(PHP_OS, 'WIN') === 0 ? $winCmd : $linuxCmd;
61
62
        $this->assertEquals(
63
            $cmd,
64
            (new \Robo\Task\Vcs\GitStack())
65
                ->cloneRepo('http://github.com/consolidation-org/Robo')
66
                ->pull()
67
                ->add('-A')
68
                ->commit('changed')
69
                ->push()
70
                ->tag('0.6.0', 'message')
71
                ->push('origin', '0.6.0')
72
                ->getCommand()
73
        );
74
    }
75
76
    public function testGitStackShallowCloneCommand()
77
    {
78
        $cmd = 'git clone --depth 1 http://github.com/consolidation-org/Robo ./deployment-path';
79
80
        $this->assertEquals(
81
            $cmd,
82
            (new \Robo\Task\Vcs\GitStack())
83
                ->cloneShallow('http://github.com/consolidation-org/Robo', './deployment-path')
84
                ->getCommand()
85
        );
86
    }
87
88
    public function testGitStackShallowCloneCommandWithDifferentDepth()
89
    {
90
        $cmd = 'git clone --depth 3 http://github.com/consolidation-org/Robo . --branch feature';
91
92
        $this->assertEquals(
93
            $cmd,
94
            (new \Robo\Task\Vcs\GitStack())
95
                ->cloneShallow('http://github.com/consolidation-org/Robo', '.', 'feature', 3)
96
                ->getCommand()
97
        );
98
    }
99
}
100