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::getTmpDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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