ProjectShouldBeInHomeDirectory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 61
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A start() 0 8 2
A stop() 0 4 1
A reset() 0 4 1
A inHomeDirectory() 0 7 1
1
<?php
2
3
namespace Dock\Project\Decorator;
4
5
use Dock\Docker\Compose\Project;
6
use Dock\IO\UserInteraction;
7
use Dock\Project\ProjectException;
8
use Dock\Project\ProjectManager;
9
10
class ProjectShouldBeInHomeDirectory implements ProjectManager
11
{
12
    /**
13
     * @var ProjectManager
14
     */
15
    private $projectManager;
16
17
    /**
18
     * @var UserInteraction
19
     */
20
    private $userInteraction;
21
22
    /**
23
     * @param ProjectManager  $projectManager
24
     * @param UserInteraction $userInteraction
25
     */
26
    public function __construct(ProjectManager $projectManager, UserInteraction $userInteraction)
27
    {
28
        $this->projectManager = $projectManager;
29
        $this->userInteraction = $userInteraction;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function start(Project $project)
36
    {
37
        if (!$this->inHomeDirectory()) {
38
            throw new ProjectException('The project have to be in your home directly to be able to share it with the Docker VM');
39
        }
40
41
        return $this->projectManager->start($project);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function stop(Project $project)
48
    {
49
        return $this->projectManager->stop($project);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function reset(Project $project, array $containers = [])
56
    {
57
        return $this->projectManager->reset($project, $containers);
58
    }
59
60
    /**
61
     * @return bool
62
     */
63
    private function inHomeDirectory()
64
    {
65
        $home = getenv('HOME');
66
        $pwd = getcwd();
67
68
        return substr($pwd, 0, strlen($home)) === $home;
69
    }
70
}
71