Passed
Push — master ( 6db8b4...45291c )
by David
01:08
created

AbstractClientTest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
namespace FlexyProject\GitHub\Tests;
3
4
use FlexyProject\GitHub\Client;
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * Class AbstractTest
9
 *
10
 * @package FlexyProject\GitHub\Tests
11
 */
12
abstract class AbstractClientTest extends TestCase
13
{
14
    /** @var Client */
15
    protected $client;
16
17
    /**
18
     * AbstractTest constructor.
19
     *
20
     * @param null   $name
21
     * @param array  $data
22
     * @param string $dataName
23
     */
24
    public function __construct($name = null, array $data = [], $dataName = '')
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $GLOBALS 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...
25
    {
26
        // Create a client object
27
        $this->client = new Client();
28
29
        // Set auth credentials
30
        $this->client->setHttpAuth($GLOBALS['USERNAME'], $GLOBALS['PASSWORD']);
31
32
        parent::__construct($name, $data, $dataName);
33
    }
34
}