NotFoundTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 40.82 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 20
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A constructor() 0 9 1
A pathProvider() 20 20 1
A createNotFound() 0 7 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
namespace Zenstruck\RedirectBundle\Tests\Model;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @author Kevin Bond <[email protected]>
9
 */
10
class NotFoundTest extends TestCase
11
{
12
    /**
13
     * @dataProvider pathProvider
14
     *
15
     * @test
16
     */
17
    public function constructor($path, $expectedPath)
18
    {
19
        $notFound = $this->createNotFound($path, 'http://foobar.com/baz');
20
21
        $this->assertSame($expectedPath, $notFound->getPath());
22
        $this->assertNull($notFound->getReferer());
23
        $this->assertSame('http://foobar.com/baz', $notFound->getFullUrl());
24
        $this->assertEqualsWithDelta(\time(), $notFound->getTimestamp()->format('U'), 1);
25
    }
26
27 View Code Duplication
    public function pathProvider()
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...
28
    {
29
        return [
30
            ['foo/bar', '/foo/bar'],
31
            ['/foo/bar/', '/foo/bar/'],
32
            ['foo', '/foo'],
33
            ['foo/bar ', '/foo/bar'],
34
            [' foo/bar/', '/foo/bar/'],
35
            ['   /foo', '/foo'],
36
            ['http://www.example.com/foo', '/foo'],
37
            ['http://www.example.com/', '/'],
38
            ['http://www.example.com', '/'],
39
            ['foo/bar?baz=true', '/foo/bar'],
40
            ['http://www.example.com/foo?baz=bar&foo=baz', '/foo'],
41
            ['http://www.example.com/foo?baz=bar&foo=baz#baz', '/foo'],
42
            ['', null],
43
            ['   ', null],
44
            ['/', '/'],
45
        ];
46
    }
47
48
    /**
49
     * @return \Zenstruck\RedirectBundle\Model\NotFound
50
     */
51
    private function createNotFound($path, $fullUrl, $referer = null, \DateTime $timestamp = null)
52
    {
53
        return $this->getMockForAbstractClass(
54
            'Zenstruck\RedirectBundle\Model\NotFound',
55
            [$path, $fullUrl, $referer, $timestamp]
56
        );
57
    }
58
}
59