Completed
Push — develop ( cfc9ab...e7bb49 )
by Stéphane
02:08
created

Expression   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 31.88 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 1
dl 22
loc 69
rs 10

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 the beebot package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @copyright Bee4 2016
8
 * @author    Stephane HULARD <[email protected]>
9
 */
10
11
namespace Bee4\RobotsTxt\Test\Units;
12
13
use mageekguy\atoum;
14
use Bee4\RobotsTxt\Expression as SUT;
15
16
/**
17
 * Expression unit test
18
 */
19
class Expression extends atoum
20
{
21
    public function patternDataProvider()
22
    {
23
        return [
24
            ['/page-1.html', '\/page\-1\.html.*'],
25
            ['/page-1.html$', '\/page\-1\.html'],
26
            ['/page*/dossier.html', '\/page.*\/dossier\.html.*'],
27
            ['/page*/dossier.html$', '\/page.*\/dossier\.html'],
28
            ['/page+1$', '\/page\+1'],
29
            ['/page+1?query=toto$', '\/page\+1\?query\=toto'],
30
            ['/page+1?query[0]=foo&query[1]=bar$', '\/page\+1\?query\[0\]\=foo&query\[1\]\=bar'],
31
        ];
32
    }
33
34
    /**
35
     * @dataProvider patternDataProvider
36
     */
37
    public function testPattern($exp, $pattern)
38
    {
39
        $this
40
            ->given($sut = new SUT($exp))
41
            ->then
42
                ->string($sut->getRaw())
43
                    ->isEqualTo($exp)
44
                ->castToString($sut)
45
                    ->isEqualTo($pattern);
46
    }
47
48
    public function containsDataProvider()
49
    {
50
        return [
51
            ['/page-1', '/page-1/dossier.html', true],
52
            ['/page-1$', '/page-1/dossier.html', false],
53
            ['/page*', '/page-1/dossier.html', true],
54
            ['/page*', '/page*/dossier.html', true],
55
        ];
56
    }
57
58
    /**
59
     * @dataProvider containsDataProvider
60
     */
61
    public function testContains($exp, $exp2, $contains)
62
    {
63
        $this
64
            ->given(
65
                $sut = new SUT($exp),
66
                $sut2 = new SUT($exp2)
67
            )
68
            ->then
69
                ->boolean($sut->contains($sut2))
70
                    ->isEqualTo($contains);
71
    }
72
73
    /**
74
     * @dataProvider containsDataProvider
75
     */
76
    public function testContained($exp, $exp2, $contained)
77
    {
78
        $this
79
            ->given(
80
                $sut = new SUT($exp),
81
                $sut2 = new SUT($exp2)
82
            )
83
            ->then
84
                ->boolean($sut2->contained($sut))
85
                    ->isEqualTo($contained);
86
    }
87
}
88