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 (#178)
by joseph
127:53 queued 124:55
created

FileFactory::setProjectRootDirectory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\Factory;
4
5
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\CreatorInterface;
6
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\File;
7
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
8
use EdmondsCommerce\DoctrineStaticMeta\Config;
9
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;
10
11
class FileFactory
12
{
13
    /**
14
     * @var NamespaceHelper
15
     */
16
    protected $namespaceHelper;
17
    /**
18
     * @var Config
19
     */
20
    protected $config;
21
22
    /**
23
     * @var string
24
     */
25
    private $projectRootNamespace;
26
27
    /**
28
     * @var string
29
     */
30
    private $projectRootDirectory;
31
32
    public function __construct(NamespaceHelper $namespaceHelper, Config $config)
33
    {
34
        $this->namespaceHelper      = $namespaceHelper;
35
        $this->projectRootNamespace = $this->namespaceHelper->getProjectRootNamespaceFromComposerJson();
36
        $this->projectRootDirectory = $config::getProjectRootDirectory();
37
    }
38
39
    public function setProjectRootNamespace(string $projectRootNamespace): self
40
    {
41
        $this->projectRootNamespace = $projectRootNamespace;
42
43
        return $this;
44
    }
45
46
    /**
47
     * Create a new file object from an existing file path
48
     *
49
     * @param string $path
50
     *
51
     * @return File
52
     * @throws DoctrineStaticMetaException
53
     */
54
    public function createFromExistingPath(string $path): File
55
    {
56
        $file = new File($path);
57
        if (false === $file->exists()) {
58
            throw new DoctrineStaticMetaException('File does not exist at ' . $path);
59
        }
60
61
        return $file;
62
    }
63
64
    /**
65
     * Create a new file object that should not already exist at the specified path
66
     *
67
     * @param string $path
68
     *
69
     * @return File
70
     * @throws DoctrineStaticMetaException
71
     */
72
    public function createFromNonExistantPath(string $path): File
73
    {
74
        $file = new File($path);
75
        if (true === $file->exists()) {
76
            throw new DoctrineStaticMetaException('File exists at ' . $path);
77
        }
78
79
        return $file;
80
    }
81
82
    /**
83
     * Create a new file object from a fully qualified name, may or may not exist
84
     *
85
     * @param string $fqn
86
     * @param string $srcOrTestSubFolder
87
     *
88
     * @return File
89
     * @throws DoctrineStaticMetaException
90
     */
91
    public function createFromFqn(string $fqn, $srcOrTestSubFolder = CreatorInterface::SRC_FOLDER): File
92
    {
93
        list($className, , $subDirectories) = $this->namespaceHelper->parseFullyQualifiedName(
94
            $fqn,
95
            $srcOrTestSubFolder,
96
            $this->projectRootNamespace
97
        );
98
        $path = $this->projectRootDirectory
99
                . '/' . implode('/', $subDirectories) . '/' . $className . '.php';
100
101
        return new File($path);
102
    }
103
104
    /**
105
     * @param string $projectRootDirectory
106
     *
107
     * @return FileFactory
108
     */
109
    public function setProjectRootDirectory(string $projectRootDirectory): FileFactory
110
    {
111
        $this->projectRootDirectory = $projectRootDirectory;
112
113
        return $this;
114
    }
115
}
116