LocalProject   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 26
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getProjectBasePath() 0 13 3
A getComposeConfigPath() 0 4 1
A getCurrentRelativePath() 0 4 1
1
<?php
2
3
namespace Dock\Cli\IO;
4
5
use Dock\Docker\Compose\Project;
6
7
class LocalProject implements Project
8
{
9
    public function getProjectBasePath()
10
    {
11
        $baseDir = getcwd();
12
13
        do {
14
            if (is_file($baseDir.self::CONFIG_FILE)) {
15
                return $baseDir;
16
            }
17
            $baseDir = dirname($baseDir);
18
        } while ($baseDir !== '/');
19
20
        throw new \Exception('Did not find `docker-compose.yml` in any parent directories.');
21
    }
22
23
    public function getComposeConfigPath()
24
    {
25
        return $this->getProjectBasePath().self::CONFIG_FILE;
26
    }
27
28
    public function getCurrentRelativePath()
29
    {
30
        return substr(getcwd(), strlen($this->getProjectBasePath()) + 1);
31
    }
32
}
33