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

AbstractAPITest::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 13

Duplication

Lines 8
Ratio 44.44 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 8
loc 18
rs 9.4285
cc 2
eloc 13
nc 2
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A AbstractAPITest::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