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 — 4.2-to-master ( ed215f )
by E
06:47
created

FileSystem::getAbsolutePath()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 9
nop 2
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiGen\Utils;
4
5
use Nette\Utils\FileSystem as NetteFileSystem;
6
use Nette\Utils\Finder;
7
use RecursiveDirectoryIterator;
8
use SplFileInfo;
9
10
final class FileSystem
11
{
12
    public function normalizePath(string $path): string
13
    {
14
        return str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path);
15
    }
16
17
    public function forceDir(string $path): string
18
    {
19
        @mkdir(dirname($path), 0755, true);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
20
        return $path;
21
    }
22
23
    public function deleteDir(string $path): void
24
    {
25
        NetteFileSystem::delete($path);
26
    }
27
28
    public function purgeDir(string $path): void
29
    {
30
        NetteFileSystem::delete($path);
31
        NetteFileSystem::createDir($path);
32
    }
33
34
    /**
35
     * @param string $path
36
     * @param string[] $baseDirectories
37
     * @return string
38
     */
39
    public function getAbsolutePath(string $path, array $baseDirectories = []): string
40
    {
41
        foreach ($baseDirectories as $directory) {
42
            $fileName = $directory . '/' . $path;
43
            if (is_file($fileName)) {
44
                return $this->normalizePath(realpath($fileName));
45
            }
46
        }
47
48
        if (file_exists($path)) {
49
            $path = realpath($path);
50
        }
51
52
        if (file_exists(getcwd() . $path)) {
53
            $path = getcwd() . $path;
54
        }
55
56
        return $this->normalizePath($path);
57
    }
58
59
    public function isDirEmpty(string $path): bool
60
    {
61
        if (count(glob($path . '/*'))) {
62
            return false;
63
        }
64
65
        return true;
66
    }
67
68
    /**
69
     * @param string[]|string[][] $source
70
     * @param string $destination
71
     */
72
    public function copy(array $source, string $destination): void
73
    {
74
        foreach ($source as $resourceSource => $resourceDestination) {
75
            if (is_file($resourceSource)) {
76
                copy($resourceSource, FileSystem::forceDir($destination  . '/' . $resourceDestination));
77
                continue;
78
            } else {
79
                /** @var RecursiveDirectoryIterator $iterator */
80
                $iterator = Finder::findFiles('*')->from($resourceSource)->getIterator();
81
                foreach ($iterator as $item) {
82
                    /** @var SplFileInfo $item */
83
                    copy($item->getPathname(), FileSystem::forceDir($destination
84
                        . '/' . $resourceDestination
85
                        . '/' . $iterator->getSubPathname()));
86
                }
87
            }
88
        }
89
    }
90
}
91