Completed
Pull Request — master (#37)
by Vitaliy
06:49 queued 04:18
created

AbstractAPITest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 1
c 4
b 2
f 1
lcom 1
cbo 2
dl 0
loc 30
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 7 1
1
<?php
2
3
namespace Xsolla\SDK\Tests\Integration\API;
4
5
use Xsolla\SDK\API\XsollaClient;
6
use Xsolla\SDK\Tests\Helper\XsollaClientHelper;
7
8
abstract class AbstractAPITest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * @var XsollaClient
12
     */
13
    protected static $xsollaClient;
14
15
    /**
16
     * @var int
17
     */
18
    protected static $projectId;
19
20
    /**
21
     * @var int
22
     */
23
    protected static $merchantId;
24
25
    /**
26
     * @var string
27
     */
28
    protected static $userId;
29
30
    public static function setUpBeforeClass()
0 ignored issues
show
Coding Style introduced by
setUpBeforeClass 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...
31
    {
32
        static::$projectId = (int) $_SERVER['PROJECT_ID'];
33
        static::$merchantId = (int) $_SERVER['MERCHANT_ID'];
34
        static::$userId = $_SERVER['USER_ID'];
35
        static::$xsollaClient = XsollaClientHelper::getXsollaClient(static::$merchantId, $_SERVER['API_KEY']);
36
    }
37
}
38