1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of tenside/core-bundle. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Schiffler <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* This project is provided in good faith and hope to be usable by anyone. |
12
|
|
|
* |
13
|
|
|
* @package tenside/core-bundle |
14
|
|
|
* @author Christian Schiffler <[email protected]> |
15
|
|
|
* @copyright 2015 Christian Schiffler <[email protected]> |
16
|
|
|
* @license https://github.com/tenside/core-bundle/blob/master/LICENSE MIT |
17
|
|
|
* @link https://github.com/tenside/core-bundle |
18
|
|
|
* @filesource |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Tenside\CoreBundle\Util; |
22
|
|
|
|
23
|
|
|
use Tenside\Core\Util\HomePathDeterminator; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* This class provides information about the current installation. |
27
|
|
|
*/ |
28
|
|
|
class InstallationStatusDeterminator |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* The home path determinator. |
32
|
|
|
* |
33
|
|
|
* @var HomePathDeterminator |
34
|
|
|
*/ |
35
|
|
|
private $home; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Local cache flag determining if tenside is properly configured. |
39
|
|
|
* |
40
|
|
|
* @var null|bool |
41
|
|
|
*/ |
42
|
|
|
private $isTensideConfigured; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Local cache flag determining if a composer.json is present. |
46
|
|
|
* |
47
|
|
|
* @var null|bool |
48
|
|
|
*/ |
49
|
|
|
private $isProjectPresent; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Local cache flag determining if the composer project has been installed (vendor present). |
53
|
|
|
* |
54
|
|
|
* @var null|bool |
55
|
|
|
*/ |
56
|
|
|
private $isProjectInstalled; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Create a new instance. |
60
|
|
|
* |
61
|
|
|
* @param HomePathDeterminator $homePathDeterminator The home path determinator. |
62
|
|
|
*/ |
63
|
|
|
public function __construct(HomePathDeterminator $homePathDeterminator) |
64
|
|
|
{ |
65
|
|
|
$this->home = $homePathDeterminator; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Check if a "tenside.json" is present. |
70
|
|
|
* |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
|
|
public function isTensideConfigured() |
74
|
|
|
{ |
75
|
|
|
if (isset($this->isTensideConfigured)) { |
76
|
|
|
return $this->isTensideConfigured; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $this->isTensideConfigured = file_exists( |
80
|
|
|
$this->home->tensideDataDir() . DIRECTORY_SEPARATOR . 'tenside.json' |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Check if a project "composer.json" is present. |
86
|
|
|
* |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
View Code Duplication |
public function isProjectPresent() |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
if (isset($this->isProjectPresent)) { |
92
|
|
|
return $this->isProjectPresent; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $this->isProjectPresent = file_exists($this->home->homeDir() . DIRECTORY_SEPARATOR . 'composer.json'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Check if the vendor directory is present. |
100
|
|
|
* |
101
|
|
|
* @return bool |
102
|
|
|
*/ |
103
|
|
View Code Duplication |
public function isProjectInstalled() |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
if (isset($this->isProjectInstalled)) { |
106
|
|
|
return $this->isProjectInstalled; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $this->isProjectInstalled = is_dir($this->home->homeDir() . DIRECTORY_SEPARATOR . 'vendor'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Flag if everything is completely installed. |
114
|
|
|
* |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
public function isComplete() |
118
|
|
|
{ |
119
|
|
|
return $this->isTensideConfigured() |
120
|
|
|
&& $this->isProjectPresent() |
121
|
|
|
&& $this->isProjectInstalled(); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.