ProjectPath::getLogsPath()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Cdf\PannelloAmministrazioneBundle\Utils;
4
5
use Exception;
6
7
class ProjectPath
8
{
9
10
    private string $rootdir;
11
    private string $projectdir;
12
    private string $cacheDir;
13
    private string $logsDir;
14
15 3
    public function setRootDir(string $projectDir): void
16
    {
17 3
        $this->projectdir = $projectDir;
18 3
        $this->rootdir = $projectDir;
19
    }
20
21 3
    public function setCacheDir(string $cacheDir): void
22
    {
23 3
        $this->cacheDir = $cacheDir;
24
    }
25
26 3
    public function setLogsDir(string $logsDir): void
27
    {
28 3
        $this->logsDir = $logsDir;
29
    }
30
31 1
    public function getRootPath(): string
32
    {
33 1
        return $this->rootdir;
34
    }
35
36 3
    public function getProjectPath(): string
37
    {
38 3
        return $this->projectdir;
39
    }
40
41 1
    public function getBinPath(): string
42
    {
43 1
        $bindir = $this->getProjectPath() . '/bin';
44 1
        if (!file_exists($bindir)) {
45 1
            $bindir = realpath($this->getProjectPath() . '/../bin');
46
        }
47 1
        if ($bindir === false || !file_exists($bindir)) {
48
            throw new Exception('Cartella Bin non trovata', -100);
49
        }
50
51 1
        return $bindir;
52
    }
53
54 1
    public function getVendorBinPath(): string
55
    {
56 1
        $vendorbindir = $this->getVendorPath() . DIRECTORY_SEPARATOR . 'bin';
57 1
        return $vendorbindir;
58
    }
59
60 1
    public function getVendorPath(): string
61
    {
62 1
        $vendorbindir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'vendor';
63 1
        if (!file_exists($vendorbindir)) {
64 1
            $vendorbindir = dirname($this->getProjectPath()) . DIRECTORY_SEPARATOR . 'vendor';
65 1
            if (!file_exists($vendorbindir)) {
66
                throw new Exception('Cartella vendor non trovata', -100);
67
            }
68
        }
69
70 1
        return $vendorbindir;
71
    }
72
73 2
    public function getSrcPath(): string
74
    {
75 2
        $srcdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'src';
76
77 2
        return $srcdir;
78
    }
79
80 1
    public function getPublicPath(): string
81
    {
82 1
        $publicdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'public';
83
84 1
        return $publicdir;
85
    }
86
87 1
    public function getTemplatePath(): string
88
    {
89 1
        $srcdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'templates';
90 1
        $path = realpath($srcdir);
91 1
        if ($path === false) {
92
            throw new Exception('Cartella templates non trovata', -150);
93
        }
94 1
        return $path;
95
    }
96
97 1
    public function getVarPath(): string
98
    {
99 1
        $vardir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'var';
100 1
        $path = realpath($vardir);
101 1
        if ($path === false) {
102
            throw new Exception('Cartella var non trovata', -160);
103
        }
104
105 1
        return $path;
106
    }
107
108 1
    public function getDocPath(): string
109
    {
110 1
        $docdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'doc';
111 1
        $path = realpath($docdir);
112 1
        if ($path === false) {
113
            throw new Exception('Cartella doc non trovata', -160);
114
        }
115 1
        return $path;
116
    }
117
118 1
    public function getCachePath(): string
119
    {
120 1
        $cachedir = $this->cacheDir;
121 1
        if (!file_exists($cachedir)) {
122
            throw new Exception('Cache non trovata', -100);
123
        }
124
125 1
        return $cachedir;
126
    }
127
128 1
    public function getLogsPath(): string
129
    {
130 1
        $logsdir = $this->logsDir;
131 1
        if (!file_exists($logsdir)) {
132
            throw new Exception('Logs non trovata', -100);
133
        }
134
135 1
        return $logsdir;
136
    }
137
138 1
    public function getConsole(): string
139
    {
140 1
        $console = $this->getBinPath() . '/console';
141
        // Questo codice per versioni che usano un symfony 2 o 3
142 1
        if (!file_exists($console)) {
143
            throw new Exception('Console non trovata', -100);
144
        }
145
146 1
        return $console;
147
    }
148
149 1
    public function getConsoleExecute(): string
150
    {
151 1
        $console = $this->getConsole();
152 1
        if (\Fi\OsBundle\DependencyInjection\OsFunctions::isWindows()) {
153
            $console = \Fi\OsBundle\DependencyInjection\OsFunctions::getPHPExecutableFromPath() . " " . $console;
154
        }
155
156 1
        return $console;
157
    }
158
}
159