DirectScriptHandlerTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 23.4 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 11
loc 47
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A synopsis() 0 25 1
A testGetRequest() 11 11 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 Vectorface\SnappyRouterTests\Handler;
4
5
use PHPUnit\Framework\TestCase;
6
use Vectorface\SnappyRouter\Handler\DirectScriptHandler;
7
8
/**
9
 * Tests the DirectScriptHandler class.
10
 * @copyright Copyright (c) 2014, VectorFace, Inc.
11
 * @author Dan Bruce <[email protected]>
12
 */
13
class DirectScriptHandlerTest extends TestCase
14
{
15
    /**
16
     * An overview of how to use the class.
17
     * @test
18
     */
19
    public function synopsis()
20
    {
21
        // the configuration maps a path like /cgi-bin to this folder
22
        $config = array(
23
            DirectScriptHandler::KEY_PATH_MAP => array(
24
                '/cgi-bin' => __DIR__
25
            )
26
        );
27
        $handler = new DirectScriptHandler($config);
28
        $path = '/cgi-bin/test_script.php';
29
        // the file itself exists so we should get back true
30
        $this->assertTrue(
31
            $handler->isAppropriate($path, array(), array(), 'GET')
32
        );
33
        // the test script simply has `echo "Hello world!"`
34
        $expected = 'Hello world!';
35
        $this->assertEquals($expected, $handler->performRoute());
36
37
        // the script is not found so the handler should not be marked as
38
        // appropriate
39
        $path = '/cgi-bin/script_not_found.php';
40
        $this->assertFalse(
41
            $handler->isAppropriate($path, array(), array(), 'GET')
42
        );
43
    }
44
45
    /**
46
     * Tests that the getRequest() method returns null.
47
     */
48 View Code Duplication
    public function testGetRequest()
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...
49
    {
50
        $config = array(
51
            DirectScriptHandler::KEY_PATH_MAP => array(
52
                '/cgi-bin' => __DIR__
53
            )
54
        );
55
        $handler = new DirectScriptHandler($config);
56
        $this->assertTrue($handler->isAppropriate('/cgi-bin/test_script.php', array(), array(), 'GET'));
57
        $this->assertNull($handler->getRequest());
58
    }
59
}
60