Completed
Push — master ( 166881...6b19b1 )
by Andrea
09:19
created

ProjectPath   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 77.42%

Importance

Changes 0
Metric Value
wmc 26
lcom 1
cbo 0
dl 0
loc 126
ccs 48
cts 62
cp 0.7742
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getRootPath() 0 4 1
A getProjectPath() 0 4 1
A getSrcPath() 0 5 1
A getAppPath() 0 5 1
A getVarPath() 0 5 1
A getDocPath() 0 5 1
A getBinPath() 0 14 4
A getVendorBinPath() 0 11 3
A getCachePath() 0 13 4
A getLogsPath() 0 13 4
A getConsole() 0 14 4
1
<?php
2
3
namespace Fi\PannelloAmministrazioneBundle\DependencyInjection;
4
5
class ProjectPath
6
{
7
8
    /**
9
     * La funzione ritorna un array con i path dell'applicazione.
10
     *
11
     * @param $container Container dell'applicazione
12
     *
13
     * @return array Ritorna l'array contenente i path
14
     */
15
    private $container;
16
    private $rootdir;
17
    private $prjdir;
18
19 3
    public function __construct($container)
20
    {
21 3
        $this->container = $container;
22 3
        $rootdir = dirname($this->container->get('kernel')->getRootDir());
23 3
        $this->rootdir = $rootdir;
24 3
        $this->prjdir = $rootdir;
25 3
    }
26
27 1
    public function getRootPath()
28
    {
29 1
        return $this->rootdir;
30
    }
31
32 3
    public function getProjectPath()
33
    {
34 3
        return $this->prjdir;
35
    }
36
37 1
    public function getBinPath()
38
    {
39 1
        $bindir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'bin';
40 1
        if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
41 1
            if (!file_exists($bindir)) {
42
                $bindir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'vendor' .
43
                        DIRECTORY_SEPARATOR . 'bin';
44
            }
45
        }
46 1
        if (!file_exists($bindir)) {
47
            throw new \Exception("Cartella Bin non trovata", -100);
48
        }
49 1
        return $bindir;
50
    }
51
52 1
    public function getVendorBinPath()
53
    {
54 1
        $vendorbindir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin';
55 1
        if (!file_exists($vendorbindir)) {
56 1
            $vendorbindir = $this->getProjectPath() . '/../vendor/bin';
57 1
            if (!file_exists($vendorbindir)) {
58
                throw new \Exception("Cartella Bin in vendor non trovata", -100);
59
            }
60
        }
61 1
        return $vendorbindir;
62
    }
63
64 2
    public function getSrcPath()
65
    {
66 2
        $srcdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'src';
67 2
        return $srcdir;
68
    }
69
70 2
    public function getAppPath()
71
    {
72 2
        $appdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'app';
73 2
        return $appdir;
74
    }
75
76 2
    public function getVarPath()
77
    {
78 2
        $vardir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'var';
79 2
        return $vardir;
80
    }
81
82 1
    public function getDocPath()
83
    {
84 1
        $docdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'doc';
85 1
        return $docdir;
86
    }
87
88 2
    public function getCachePath()
89
    {
90 2
        $cachedir = $this->getAppPath() . DIRECTORY_SEPARATOR . 'cache';
91 2
        if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
92 2
            if (!file_exists($cachedir)) {
93 2
                $cachedir = $this->getVarPath() . DIRECTORY_SEPARATOR . 'cache';
94
            }
95
        }
96 2
        if (!file_exists($cachedir)) {
97
            throw new \Exception("Cache non trovata", -100);
98
        }
99 2
        return $cachedir;
100
    }
101
102
    public function getLogsPath()
103
    {
104
        $logsdir = $this->getAppPath() . DIRECTORY_SEPARATOR . 'logs';
105
        if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
106
            if (!file_exists($logsdir)) {
107
                $logsdir = $this->getVarPath() . DIRECTORY_SEPARATOR . 'logs';
108
            }
109
        }
110
        if (!file_exists($logsdir)) {
111
            throw new \Exception("Logs non trovata", -100);
112
        }
113
        return $logsdir;
114
    }
115
116 1
    public function getConsole()
117
    {
118 1
        $console = $this->getAppPath() . DIRECTORY_SEPARATOR . 'console';
119
        // Questo codice per versioni che usano un symfony 2 o 3
120 1
        if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
121 1
            if (!file_exists($console)) {
122 1
                $console = $this->getBinPath() . DIRECTORY_SEPARATOR . 'console';
123
            }
124
        }
125 1
        if (!file_exists($console)) {
126
            throw new \Exception("Console non trovata", -100);
127
        }
128 1
        return $console;
129
    }
130
}
131