BuildJobEvent   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A addBuildJob() 0 13 1
1
<?php
2
3
namespace TheAentMachine\AentGitLabCI\Event;
4
5
use Safe\Exceptions\FilesystemException;
6
use TheAentMachine\Aent\Event\CI\AbstractCIBuildJobEvent;
7
use TheAentMachine\Aent\Payload\CI\CINewImageReplyPayload;
8
use TheAentMachine\AentGitLabCI\Context\BaseGitLabCIContext;
9
use TheAentMachine\AentGitLabCI\Exception\GitLabCIFileException;
10
use TheAentMachine\AentGitLabCI\Exception\JobException;
11
use TheAentMachine\AentGitLabCI\GitLabCI\GitLabCIFile;
12
use TheAentMachine\AentGitLabCI\GitLabCI\Job\BuildDockerfileJob;
13
use TheAentMachine\Exception\MissingEnvironmentVariableException;
14
15
final class BuildJobEvent extends AbstractCIBuildJobEvent
16
{
17
    /**
18
     * @param string $serviceName
19
     * @param string $dockerfileName
20
     * @return CINewImageReplyPayload
21
     * @throws FilesystemException
22
     * @throws GitLabCIFileException
23
     * @throws JobException
24
     * @throws MissingEnvironmentVariableException
25
     */
26
    protected function addBuildJob(string $serviceName, string $dockerfileName): CINewImageReplyPayload
27
    {
28
        $this->prompt->printAltBlock("GitLab: adding build job...");
29
        $context = BaseGitLabCIContext::fromMetadata();
30
        $job = new BuildDockerfileJob(
31
            $serviceName,
32
            $dockerfileName,
33
            $context
34
        );
35
        $file = new GitLabCIFile();
36
        $file->findOrCreate();
37
        $file->addBuild($job);
38
        return new CINewImageReplyPayload($job->getDockerImageName());
39
    }
40
}
41