RequireHttpTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 40
loc 40
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testHttp() 4 4 1
A testHttps() 10 10 1
A testHttpCollection() 4 4 1
A testHttpsCollection() 10 10 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 the silex-annotation-provider package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @license       MIT License
8
 * @copyright (c) 2018, Dana Desrosiers <[email protected]>
9
 */
10
11
namespace DDesrosiers\Test\SilexAnnotations\Annotations;
12
13
use DDesrosiers\Test\SilexAnnotations\AnnotationTestBase;
14
use Symfony\Component\HttpFoundation\Request;
15
16 View Code Duplication
class RequireHttpTest extends AnnotationTestBase
0 ignored issues
show
Duplication introduced by
This class 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...
17
{
18
    public function testHttp()
19
    {
20
        $this->assertEndPointStatus(self::GET_METHOD, "/test/requirehttp", self::STATUS_OK);
21
    }
22
23
    /**
24
     * @throws \Exception
25
     */
26
    public function testHttps()
27
    {
28
        // we make the request as https, but it should be redirected to a http request
29
        $this->registerProviders();
30
        $_SERVER['REQUEST_URI'] = '/test/requirehttp';
31
        $request = Request::create('https://test.com/test/requirehttp');
32
        $response = $this->app->handle($request);
33
        $this->assertEquals(301, $response->getStatusCode());
34
        $this->assertTrue($response->isRedirect('http://test.com/test/requirehttp'));
35
    }
36
37
    public function testHttpCollection()
38
    {
39
        $this->assertEndPointStatus(self::GET_METHOD, "/requirehttp/test", self::STATUS_OK);
40
    }
41
42
    /**
43
     * @throws \Exception
44
     */
45
    public function testHttpsCollection()
46
    {
47
        // we make the request as https, but it should be redirected to a http request
48
        $this->registerProviders();
49
        $_SERVER['REQUEST_URI'] = '/requirehttp/test';
50
        $request = Request::create('https://test.com/requirehttp/test');
51
        $response = $this->app->handle($request);
52
        $this->assertEquals(301, $response->getStatusCode());
53
        $this->assertTrue($response->isRedirect('http://test.com/requirehttp/test'));
54
    }
55
}
56