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 ( f51b4f...d5d186 )
by Cees-Jan
10:52
created

TestCase   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 67
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A tearDown() 0 5 1
B rmdir() 0 21 5
A getTmpDir() 0 4 1
A getRandomNameSpace() 0 4 1
A hydrate() 0 8 1
1
<?php
2
declare(strict_types=1);
3
4
namespace ApiClients\Tools\ResourceTestUtilities;
5
6
use GeneratedHydrator\Configuration;
7
use Phake;
8
use ApiClients\Foundation\Transport\Client;
9
use ApiClients\Foundation\Transport\Hydrator;
10
11
abstract class TestCase extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var string
15
     */
16
    private $tmpDir;
17
18
    /**
19
     * @var string
20
     */
21
    private $tmpNamespace;
22
23
    public function setUp()
24
    {
25
        parent::setUp();
26
        $this->tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('api-clients-tests-') . DIRECTORY_SEPARATOR;
27
        mkdir($this->tmpDir, 0777, true);
28
        $this->tmpNamespace = Configuration::DEFAULT_GENERATED_CLASS_NAMESPACE . uniqid('ApiClientsTestNamespace');
29
    }
30
31
    public function tearDown()
32
    {
33
        parent::tearDown();
34
        $this->rmdir($this->tmpDir);
35
    }
36
37
    protected function rmdir($dir)
38
    {
39
        $directory = dir($dir);
40
        while (false !== ($entry = $directory->read())) {
41
            if (in_array($entry, ['.', '..'])) {
42
                continue;
43
            }
44
45
            if (is_dir($dir . $entry)) {
46
                $this->rmdir($dir . $entry . DIRECTORY_SEPARATOR);
47
                continue;
48
            }
49
50
            if (is_file($dir . $entry)) {
51
                unlink($dir . $entry);
52
                continue;
53
            }
54
        }
55
        $directory->close();
56
        rmdir($dir);
57
    }
58
59
    protected function getTmpDir(): string
60
    {
61
        return $this->tmpDir;
62
    }
63
64
    protected function getRandomNameSpace(): string
65
    {
66
        return $this->tmpNamespace;
67
    }
68
69
    public function hydrate($class, $json, $namespace)
70
    {
71
        return (new Hydrator(Phake::mock(Client::class), [
0 ignored issues
show
Documentation introduced by
\Phake::mock(\ApiClients...ransport\Client::class) is of type object<Phake_IMock>, but the function expects a object<ApiClients\Foundation\Transport\Client>.

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...
72
            'resource_namespace' => $namespace,
73
            'resource_hydrator_cache_dir' => $this->getTmpDir(),
74
            'resource_hydrator_namespace' => $this->getRandomNameSpace(),
75
        ]))->hydrateFQCN($class, $json);
76
    }
77
}
78