ProjectShouldBeInHomeDirectory::start()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 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