ConfigBuilder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setBuildContext() 0 5 1
A setAsyncMode() 0 5 1
A build() 0 24 3
1
<?php
2
3
namespace App\Satis;
4
5
use App\Satis\Exceptions\PackageBuildFailedException;
6
7
/**
8
 * @author Lukas Homza <[email protected]>
9
 */
10
class ConfigBuilder {
11
    const PRIVATE_REPOSITORY = 1;
12
    const PUBLIC_REPOSITORY = 2;
13
14
    /** @var \App\Satis\ConfigPersister $configPersister */
15
    protected $configPersister;
16
17
    /** @var BuildContext $buildContext */
18
    protected $buildContext;
19
20
    /** @var bool $asyncMode */
21
    protected $asyncMode = true;
22
23
	/**
24
     * ConfigBuilder constructor.
25
     * @param \App\Satis\ConfigPersister $configPersister
26
     */
27
    public function __construct(ConfigPersister $configPersister) {
28
        $this->configPersister = $configPersister;
29
    }
30
31
    /**
32
     * @param BuildContext $buildContext
33
     * @return ConfigBuilder
34
     */
35
    public function setBuildContext(BuildContext $buildContext) {
36
        $this->buildContext = $buildContext;
37
38
        return $this;
39
    }
40
41
    /**
42
     * @param boolean $asyncMode
43
     * @return ConfigManager
44
     */
45
    public function setAsyncMode($asyncMode) {
46
        $this->asyncMode = $asyncMode;
47
48
        return $this;
49
    }
50
51
	/**
52
     * @return bool|null
53
     * @throws \App\Satis\Exceptions\PackageBuildFailedException
54
     */
55
    public function build() {
56
        $this->configPersister->lock($this->buildContext->getItemId());
57
58
        $command = new BuildCommand(
59
            $this->buildContext->getConfigFile(),
60
            config('satis.build_directory') . DIRECTORY_SEPARATOR . $this->buildContext->getBuildDirectory(),
61
            config('satis.proxy')
62
        );
63
64
        $command->setItem($this->buildContext->getItemName());
65
66
        $output = null;
67
        try {
68
            $output = $command->withCd(base_path())->run($this->asyncMode);
69
        } catch(PackageBuildFailedException $e) {
70
            $output = $e->getMessage();
71
        } finally {
72
            if($this->asyncMode === false) {
73
                $this->configPersister->unlock($this->buildContext->getItemId());
74
            }
75
        }
76
77
        return $output;
78
    }
79
}
80