BaseGitLabCIContext::fromMetadata()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TheAentMachine\AentGitLabCI\Context;
4
5
use TheAentMachine\Aent\Context\Context;
6
use TheAentMachine\AentGitLabCI\Exception\JobException;
7
use TheAentMachine\AentGitLabCI\GitLabCI\Job\Model\BranchesModel;
8
use TheAentMachine\Aenthill\Aenthill;
9
10
final class BaseGitLabCIContext extends Context
11
{
12
    /** @var string */
13
    private $registryDomainName;
14
15
    /** @var string */
16
    private $projectGroup;
17
18
    /** @var string */
19
    private $projectName;
20
21
    /** @var BranchesModel */
22
    private $branchesModel;
23
24
    /**
25
     * BaseGitLabCIContext constructor.
26
     */
27
    public function __construct()
28
    {
29
        $context = Context::fromMetadata();
30
        parent::__construct($context->getEnvironmentType(), $context->getEnvironmentName());
31
        $this->registryDomainName = Aenthill::metadata('REGISTRY_DOMAIN_NAME');
32
        $this->projectGroup = Aenthill::metadata('PROJECT_GROUP');
33
        $this->projectName = Aenthill::metadata('PROJECT_NAME');
34
    }
35
36
    /**
37
     * @return void
38
     */
39
    public function toMetadata(): void
40
    {
41
        parent::toMetadata();
42
        Aenthill::update([
43
            'REGISTRY_DOMAIN_NAME' => $this->registryDomainName,
44
            'PROJECT_GROUP' => $this->projectGroup,
45
            'PROJECT_NAME' => $this->projectName,
46
        ]);
47
        $this->branchesModel->toMetadata();
48
    }
49
50
    /**
51
     * @return self
52
     * @throws JobException
53
     */
54
    public static function fromMetadata(): self
55
    {
56
        $self = new self();
57
        $self->registryDomainName = Aenthill::metadata('REGISTRY_DOMAIN_NAME');
58
        $self->projectGroup = Aenthill::metadata('PROJECT_GROUP');
59
        $self->projectName = Aenthill::metadata('PROJECT_NAME');
60
        $self->branchesModel = BranchesModel::fromMetadata();
61
        return $self;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getRegistryDomainName(): string
68
    {
69
        return $this->registryDomainName;
70
    }
71
72
    /**
73
     * @param string $registryDomainName
74
     * @return void
75
     */
76
    public function setRegistryDomainName(string $registryDomainName): void
77
    {
78
        $this->registryDomainName = $registryDomainName;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getProjectGroup(): string
85
    {
86
        return $this->projectGroup;
87
    }
88
89
    /**
90
     * @param string $projectGroup
91
     * @return void
92
     */
93
    public function setProjectGroup(string $projectGroup): void
94
    {
95
        $this->projectGroup = $projectGroup;
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    public function getProjectName(): string
102
    {
103
        return $this->projectName;
104
    }
105
106
    /**
107
     * @param string $projectName
108
     * @return void
109
     */
110
    public function setProjectName(string $projectName): void
111
    {
112
        $this->projectName = $projectName;
113
    }
114
115
    /**
116
     * @return BranchesModel
117
     */
118
    public function getBranchesModel(): BranchesModel
119
    {
120
        return $this->branchesModel;
121
    }
122
123
    /**
124
     * @param BranchesModel $branchesModel
125
     * @return void
126
     */
127
    public function setBranchesModel(BranchesModel $branchesModel): void
128
    {
129
        $this->branchesModel = $branchesModel;
130
    }
131
}
132