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 ( 0890f5...e8483c )
by Cees-Jan
09:20
created

TestCase::rmdir()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 4
nop 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Tools\TestUtilities;
4
5
use FilesystemIterator;
6
use PHPUnit_Framework_TestCase;
7
use React\EventLoop\Factory;
8
use React\EventLoop\LoopInterface;
9
use React\Promise\PromiseInterface;
10
use RecursiveDirectoryIterator;
11
use RecursiveIteratorIterator;
12
use function Clue\React\Block\await;
13
use function Clue\React\Block\awaitAll;
14
use function Clue\React\Block\awaitAny;
15
16
abstract class TestCase extends PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @var string
20
     */
21
    private $baseTmpDir;
22
23
    /**
24
     * @var string
25
     */
26
    private $tmpDir;
27
28
    /**
29
     * @var string
30
     */
31
    private $tmpNamespace;
32
33
    public function setUp()
34
    {
35
        parent::setUp();
36
37
        $this->baseTmpDir = $this->getSysTempDir() .
38
            DIRECTORY_SEPARATOR .
39
            'php-api-clients-tests-' .
40
            uniqid() .
41
            DIRECTORY_SEPARATOR;
42
        $this->tmpDir = $this->baseTmpDir .
43
            uniqid() .
44
            DIRECTORY_SEPARATOR;
45
        ;
46
47
        mkdir($this->tmpDir, 0777, true);
48
        $this->tmpNamespace = uniqid('PACTN');
49
    }
50
51
    protected function getSysTempDir()
52
    {
53
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
54
            return 'C:\\t\\';
55
        }
56
57
        return sys_get_temp_dir();
58
    }
59
60
    public function tearDown()
61
    {
62
        parent::tearDown();
63
        $this->rmdir($this->baseTmpDir);
64
    }
65
66
    protected function rmdir($dir)
67
    {
68
        $directory = new FilesystemIterator($dir);
69
70
        foreach ($directory as $node) {
71
            if (is_dir($node->getPathname())) {
72
                $this->rmdir($node->getPathname());
73
                continue;
74
            }
75
76
            if (is_file($node->getPathname())) {
77
                unlink($node->getPathname());
78
                continue;
79
            }
80
        }
81
82
        rmdir($dir);
83
    }
84
85
    protected function getTmpDir(): string
86
    {
87
        return $this->tmpDir;
88
    }
89
90
    protected function getRandomNameSpace(): string
91
    {
92
        return $this->tmpNamespace;
93
    }
94
95
    protected function getFilesInDirectory(string $path): array
96
    {
97
        $files = [];
98
99
        $directory = new RecursiveDirectoryIterator($path);
100
        $directory = new RecursiveIteratorIterator($directory);
101
102
        foreach ($directory as $node) {
103
            if (!is_file($node->getPathname())) {
104
                continue;
105
            }
106
107
            $files[] = $node->getPathname();
108
        }
109
110
        return $files;
111
    }
112
113
    public function provideTrueFalse(): array
114
    {
115
        return [
116
            [
117
                true,
118
            ],
119
            [
120
                false,
121
            ],
122
        ];
123
    }
124
125
    protected function await(PromiseInterface $promise, LoopInterface $loop = null)
126
    {
127
        if (!($loop instanceof LoopInterface)) {
128
            $loop = Factory::create();
129
        }
130
131
        return await($promise, $loop);
132
    }
133
134
    protected function awaitAll(array $promises, LoopInterface $loop = null)
135
    {
136
        if (!($loop instanceof LoopInterface)) {
137
            $loop = Factory::create();
138
        }
139
140
        return awaitAll($promises, $loop);
141
    }
142
143
    protected function awaitAny(array $promises, LoopInterface $loop = null)
144
    {
145
        if (!($loop instanceof LoopInterface)) {
146
            $loop = Factory::create();
147
        }
148
149
        return awaitAny($promises, $loop);
150
    }
151
}
152