Passed
Push — master ( 254a60...d28541 )
by Andrea
09:09 queued 11s
created

ProjectPath::getVendorPath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

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