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
Pull Request — master (#153)
by joseph
22:07
created

CopyPhpstormMeta::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
ccs 0
cts 11
cp 0
crap 12
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\PostProcessor;
4
5
class CopyPhpstormMeta
6
{
7
    /**
8
     * @var string
9
     */
10
    private $pathToProjectRoot;
11
12
13
    public function run(): void
14
    {
15
        $targetDir   = $this->getTargetDir();
16
        $sourceFiles = $this->getSourceFiles();
17
        foreach ($sourceFiles as $sourceFilePath) {
18
            $sourceFilename = basename($sourceFilePath);
19
            $targetFilePath = $targetDir . '/' . $sourceFilename;
20
            if (file_exists($targetFilePath)) {
21
                unlink($targetFilePath);
22
            }
23
            copy($sourceFilePath, $targetFilePath);
24
        }
25
    }
26
27
    private function getTargetDir()
28
    {
29
        if (null === $this->pathToProjectRoot) {
30
            throw new \RuntimeException('You must set the project root path before running this process');
31
        }
32
        $targetDir = $this->pathToProjectRoot . '/.phpstorm.meta.php';
33
        if (!is_dir($targetDir) && mkdir($targetDir, 0777, true) && !is_dir($targetDir)) {
34
            throw new \RuntimeException('Failed making targetDir ' . $targetDir);
35
        }
36
37
        return realpath($targetDir);
38
    }
39
40
    private function getSourceFiles(): array
41
    {
42
        return glob(__DIR__ . '/../../../.phpstorm.meta.php/*.php');
43
    }
44
45
    /**
46
     * @param string $pathToProjectRoot
47
     *
48
     * @return self
49
     */
50
    public function setPathToProjectRoot(string $pathToProjectRoot): self
51
    {
52
        $this->pathToProjectRoot = $pathToProjectRoot;
53
54
        return $this;
55
    }
56
}
57