Passed
Push — master ( 4b4fd9...80e73c )
by Andrea
12:12
created

ProjectPath::getCachePath()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.016

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 6
nop 0
dl 0
loc 12
ccs 9
cts 10
cp 0.9
crap 4.016
rs 9.2
c 0
b 0
f 0
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 4
    public function __construct($container)
20
    {
21 4
        $this->container = $container;
22 4
        $rootdir = dirname($this->container->get('kernel')->getRootDir());
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
23 4
        $this->rootdir = $rootdir;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
24 4
        $this->prjdir = $rootdir;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
25 4
    }
26
27 3
    public function getRootPath()
28
    {
29 3
        return $this->rootdir;
30
    }
31
32 3
    public function getProjectPath()
33
    {
34 3
        return $this->prjdir;
35
    }
36
37
    public function getBinPath()
38
    {
39
        $bindir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'bin';
40
        if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
41
            if (!file_exists($bindir)) {
42
                $bindir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'vendor' .
43
                        DIRECTORY_SEPARATOR . 'bin';
44
            }
45
        }
46
        if (!file_exists($bindir)) {
47
            throw new \Exception("Cartella Bin non trovata", -100);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Cartella Bin non trovata does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
48
        }
49
        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);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Cartella Bin in vendor non trovata does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
59
            }
60 1
        }
61 1
        return $vendorbindir;
62
    }
63
64 3
    public function getSrcPath()
65
    {
66 3
        $srcdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'src';
67 3
        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 2
    public function getDocPath()
83
    {
84 2
        $docdir = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'doc';
85 2
        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 2
            }
95 2
        }
96 2
        if (!file_exists($cachedir)) {
97
            throw new \Exception("Cache non trovata", -100);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Cache non trovata does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
98
        }
99 2
        return $cachedir;
100
    }
101
102 1
    public function getLogsPath()
103
    {
104 1
        $logsdir = $this->getAppPath() . DIRECTORY_SEPARATOR . 'logs';
105 1
        if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
106 1
            if (!file_exists($logsdir)) {
107 1
                $logsdir = $this->getVarPath() . DIRECTORY_SEPARATOR . 'logs';
108 1
            }
109 1
        }
110 1
        if (!file_exists($logsdir)) {
111
            throw new \Exception("Logs non trovata", -100);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Logs non trovata does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
112
        }
113 1
        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
                $console = $this->getBinPath() . DIRECTORY_SEPARATOR . 'console';
123
            }
124 1
        }
125 1
        if (!file_exists($console)) {
126
            throw new \Exception("Console non trovata", -100);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Console non trovata does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
127
        }
128 1
        return $console;
129
    }
130
}
131