-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathBuildFactory.php
More file actions
110 lines (88 loc) · 2.8 KB
/
BuildFactory.php
File metadata and controls
110 lines (88 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
declare(strict_types=1);
namespace PHPCensor;
use PHPCensor\Model\Build;
use PHPCensor\Model\Project;
use PHPCensor\Common\Application\ConfigurationInterface;
/**
* BuildFactory - Takes in a generic Build and returns a type-specific Build model.
*
* @package PHP Censor
* @subpackage Application
*
* @author Dan Cryer <dan@block8.co.uk>
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class BuildFactory
{
private ConfigurationInterface $configuration;
private StoreRegistry $storeRegistry;
public function __construct(
ConfigurationInterface $configuration,
StoreRegistry $storeRegistry
) {
$this->configuration = $configuration;
$this->storeRegistry = $storeRegistry;
}
/**
* @throws Common\Exception\RuntimeException
* @throws Exception\HttpException
*/
public function getBuildById(int $buildId): ?Build
{
/** @var Build $build */
$build = $this->storeRegistry->get('Build')->getById($buildId);
if (!$build) {
return null;
}
return $this->getBuild($build);
}
/**
* Takes a generic build and returns a type-specific build model.
*
* @throws Exception\HttpException
*/
public function getBuild(Build $build): Build
{
$project = $build->getProject();
if (!empty($project)) {
switch ($project->getType()) {
case Project::TYPE_LOCAL:
$type = 'LocalBuild';
break;
case Project::TYPE_GIT:
$type = 'GitBuild';
break;
case Project::TYPE_GITHUB:
$type = 'GithubBuild';
break;
case Project::TYPE_BITBUCKET:
$type = 'BitbucketBuild';
break;
case Project::TYPE_GITLAB:
$type = 'GitlabBuild';
break;
case Project::TYPE_GOGS:
$type = 'GogsBuild';
break;
case Project::TYPE_HG:
$type = 'HgBuild';
break;
case Project::TYPE_BITBUCKET_HG:
$type = 'BitbucketHgBuild';
break;
case Project::TYPE_BITBUCKET_SERVER:
$type = 'BitbucketServerBuild';
break;
case Project::TYPE_SVN:
$type = 'SvnBuild';
break;
default:
return $build;
}
$class = '\\PHPCensor\\Model\\Build\\' . $type;
$build = new $class($this->configuration, $this->storeRegistry, $build->getDataArray());
}
return $build;
}
}