InstallationStatusDeterminator   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 16
loc 96
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isTensideConfigured() 0 10 2
A isProjectPresent() 8 8 2
A isProjectInstalled() 8 8 2
A isComplete() 0 6 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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