Completed
Push — master ( 5dec74...738f49 )
by Tobias
10:01
created

ServerRequestTest::createSubject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Tests\Nyholm\Psr7\Integration;
4
5
use Http\Psr7Test\ServerRequestIntegrationTest;
6
use Nyholm\Psr7\Factory\ServerRequestFactory;
7
8
class ServerRequestTest extends ServerRequestIntegrationTest
9
{
10
    public function createSubject()
0 ignored issues
show
Coding Style introduced by
createSubject uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
11
    {
12
        $_SERVER['REQUEST_METHOD'] = 'GET';
13
14
        return (new ServerRequestFactory())->createServerRequestFromArray($_SERVER);
15
    }
16
}
17