GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( da7651...84ea09 )
by Leandro
03:32
created

DomainTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testDomain() 0 19 4
A domainProvider() 0 9 1
1
<?php
2
namespace LosDomainTest;
3
4
use LosDomain\Domain;
5
use PHPUnit\Framework\TestCase;
6
7
class DomainTest extends TestCase
8
{
9
    /**
10
     * @param $httpHost
11
     * @param $serverName
12
     * @param $serverPort
13
     *
14
     * @dataProvider domainProvider
15
     */
16
    public function testDomain($httpHost, $serverName, $serverPort, $expected)
1 ignored issue
show
Coding Style introduced by
testDomain 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...
17
    {
18
        unset($_SERVER['HTTP_HOST']);
19
        unset($_SERVER['SERVER_NAME']);
20
        unset($_SERVER['SERVER_PORT']);
21
        if (! empty($httpHost)) {
22
            $_SERVER['HTTP_HOST'] = $httpHost;
23
        }
24
        if (! empty($serverName)) {
25
            $_SERVER['SERVER_NAME'] = $serverName;
26
        }
27
        if (! empty($serverPort)) {
28
            $_SERVER['SERVER_PORT'] = $serverPort;
29
        }
30
        $domain = new Domain();
31
        $this->assertSame($expected, $domain->toString());
32
        $this->assertSame($expected, $domain->domain());
33
        $this->assertSame($expected, (string)$domain);
34
    }
35
36
    public function domainProvider()
37
    {
38
        return [
39
            'simple domain' => [ 'abc.com', 'abc.com', '', 'abc.com' ],
40
            'domain with port' => [ 'abc.com:8080', 'abc.com', 8080, 'abc.com' ],
41
            'only server_name' => [ '', 'abc.com', 80, 'abc.com' ],
42
            'no domain' => [ '', '', '', Domain::DEFAULT_DOMAIN ],
43
        ];
44
    }
45
}
46