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 ( 09e05d...809eaf )
by Cees-Jan
02:59
created

TestCase   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 73
ccs 21
cts 35
cp 0.6
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 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
9
abstract class TestCase extends \PHPUnit_Framework_TestCase
10
{
11
    const DEFAULT_GENERATED_CLASS_NAMESPACE = 'GHGC_%s';
12
13
    /**
14
     * @var string
15
     */
16
    private $tmpDir;
17
18
    /**
19
     * @var string
20
     */
21
    private $tmpNamespace;
22
23 6
    public function setUp()
24
    {
25 6
        parent::setUp();
26 6
        $crc32 = crc32(get_class($this));
27 6
        $this->tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('act-' . $crc32, true) . DIRECTORY_SEPARATOR;
28 6
        mkdir($this->tmpDir, 0777, true);
29 6
        $this->tmpNamespace = sprintf(
30 6
            static::DEFAULT_GENERATED_CLASS_NAMESPACE,
31 6
            crc32(uniqid((string)$crc32, true))
32
        );
33 6
    }
34
35 6
    public function tearDown()
36
    {
37 6
        parent::tearDown();
38 6
        $this->rmdir($this->tmpDir);
39 6
    }
40
41 6
    protected function rmdir($dir)
42
    {
43 6
        $directory = dir($dir);
44 6
        while (false !== ($entry = $directory->read())) {
45 6
            if (in_array($entry, ['.', '..'])) {
46 6
                continue;
47
            }
48
49
            if (is_dir($dir . $entry)) {
50
                $this->rmdir($dir . $entry . DIRECTORY_SEPARATOR);
51
                continue;
52
            }
53
54
            if (is_file($dir . $entry)) {
55
                unlink($dir . $entry);
56
                continue;
57
            }
58
        }
59 6
        $directory->close();
60 6
        rmdir($dir);
61 6
    }
62
63
    protected function getTmpDir(): string
64
    {
65
        return $this->tmpDir;
66
    }
67
68
    protected function getRandomNameSpace(): string
69
    {
70
        return $this->tmpNamespace;
71
    }
72
73
    public function hydrate($class, $json, $namespace)
74
    {
75
        return Factory::create([
76
            Options::NAMESPACE => $namespace,
77
            Options::RESOURCE_CACHE_DIR => $this->getTmpDir(),
78
            Options::RESOURCE_NAMESPACE => $this->getRandomNameSpace(),
79
        ])->hydrateFQCN($class, $json);
80
    }
81
}
82