ApiKeyTest::getResponse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 5

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
/*
3
 *   This file is part of the Vultr PHP library.
4
 *
5
 *   (c) Albert Leitato <[email protected]>
6
 *
7
 *   For the full copyright and license information, please view the LICENSE
8
 *   file that was distributed with this source code.
9
 */
10
namespace Vultr\Tests\Unit;
11
12
use Vultr\Api\Auth;
13
use Vultr\Tests\TestCase;
14
15 View Code Duplication
class ApiKeyTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    public function testGetKeyInformation()
18
    {
19
        $mock = $this->getRequest();
20
        $auth = new Auth($mock);
21
        $info = $auth->getKeyInformation();
22
        $this->assertInstanceOf('Vultr\Entity\Auth', $info);
23
        $this->assertEquals($info, new \Vultr\Entity\Auth($this->getResponse(true)));
0 ignored issues
show
Documentation introduced by
$this->getResponse(true) is of type string, but the function expects a object<stdClass>|array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
        $this->assertEquals($info->email, '[email protected]');
25
    }
26
27
    /**
28
     * Sample response.
29
     *
30
     * @return string
31
     **/
32
    protected function getResponse($decode = false)
33
    {
34
        $response = '{
35
                        "acls": [
36
                            "subscriptions",
37
                            "billing",
38
                            "support",
39
                            "provisioning"
40
                        ],
41
                        "email": "[email protected]",
42
                        "name": "Example Account"
43
                    }';
44
        if ($decode) {
45
            return \json_decode($response);
46
        }
47
48
        return $response;
49
    }
50
}
51