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 ( 9e4218...09e05d )
by Cees-Jan
04:46
created

TestCase   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 56.25%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 67
ccs 18
cts 32
cp 0.5625
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 ApiClients\Foundation\Hydrator\Factory;
7
use ApiClients\Foundation\Hydrator\Options;
8
use GeneratedHydrator\Configuration;
9
10
abstract class TestCase extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var string
14
     */
15
    private $tmpDir;
16
17
    /**
18
     * @var string
19
     */
20
    private $tmpNamespace;
21
22 6
    public function setUp()
23
    {
24 6
        parent::setUp();
25 6
        $this->tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('api-clients-tests-') . DIRECTORY_SEPARATOR;
26 6
        mkdir($this->tmpDir, 0777, true);
27 6
        $this->tmpNamespace = Configuration::DEFAULT_GENERATED_CLASS_NAMESPACE . uniqid('ApiClientsTestNamespace');
28 6
    }
29
30 6
    public function tearDown()
31
    {
32 6
        parent::tearDown();
33 6
        $this->rmdir($this->tmpDir);
34 6
    }
35
36 6
    protected function rmdir($dir)
37
    {
38 6
        $directory = dir($dir);
39 6
        while (false !== ($entry = $directory->read())) {
40 6
            if (in_array($entry, ['.', '..'])) {
41 6
                continue;
42
            }
43
44
            if (is_dir($dir . $entry)) {
45
                $this->rmdir($dir . $entry . DIRECTORY_SEPARATOR);
46
                continue;
47
            }
48
49
            if (is_file($dir . $entry)) {
50
                unlink($dir . $entry);
51
                continue;
52
            }
53
        }
54 6
        $directory->close();
55 6
        rmdir($dir);
56 6
    }
57
58
    protected function getTmpDir(): string
59
    {
60
        return $this->tmpDir;
61
    }
62
63
    protected function getRandomNameSpace(): string
64
    {
65
        return $this->tmpNamespace;
66
    }
67
68
    public function hydrate($class, $json, $namespace)
69
    {
70
        return Factory::create([
71
            Options::NAMESPACE => $namespace,
72
            Options::RESOURCE_CACHE_DIR => $this->getTmpDir(),
73
            Options::RESOURCE_NAMESPACE => $this->getRandomNameSpace(),
74
        ])->hydrateFQCN($class, $json);
75
    }
76
}
77