1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JiraRestApi\Provider\Silex2; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
6
|
|
|
use GuzzleHttp\RequestOptions; |
7
|
|
|
use JiraRestApi\Configuration\ArrayConfiguration; |
8
|
|
|
use Pimple\Container; |
9
|
|
|
use Silex\Application; |
10
|
|
|
use Pimple\ServiceProviderInterface; |
11
|
|
|
|
12
|
|
|
class JiraRestApiProvider implements ServiceProviderInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param Container $app |
16
|
|
|
*/ |
17
|
|
|
public function register(Container $app) |
18
|
|
|
{ |
19
|
|
|
$app['jira.config'] = []; |
20
|
|
|
|
21
|
|
View Code Duplication |
$app['jira.rest.transport'] = function () use ($app) { |
|
|
|
|
22
|
|
|
$cfg = $app['jira.rest.configuration']; |
23
|
|
|
|
24
|
|
|
return new Client([ |
25
|
|
|
'base_uri' => $cfg->getJiraHost(), |
26
|
|
|
RequestOptions::AUTH => [$cfg->getJiraUser(), $cfg->getJiraPassword()] |
27
|
|
|
]); |
28
|
|
|
}; |
29
|
|
|
|
30
|
|
|
$app['jira.rest.configuration'] = function() use ($app) { |
31
|
|
|
return new ArrayConfiguration($app['jira.config']); |
32
|
|
|
}; |
33
|
|
|
|
34
|
|
View Code Duplication |
$app['jira.rest.service.builder'] = $app->protect(function($serviceName) use ($app) { |
|
|
|
|
35
|
|
|
if(class_exists($serviceName)) { |
36
|
|
|
return new $serviceName($app['jira.rest.configuration'], $app['jira.rest.transport'], $app['logger']); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
throw new \Exception('Service ' . $serviceName .' not found'); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
$app['jira.rest.issue'] = function() use ($app) { |
43
|
|
|
$className = '\JiraRestApi\Issue\IssueService'; |
44
|
|
|
return $app['jira.rest.service.builder']($className); |
45
|
|
|
}; |
46
|
|
|
|
47
|
|
|
$app['jira.rest.issuetype'] = function() use ($app) { |
48
|
|
|
$className = '\JiraRestApi\Issue\IssueTypeService'; |
49
|
|
|
return $app['jira.rest.service.builder']($className); |
50
|
|
|
}; |
51
|
|
|
|
52
|
|
|
$app['jira.rest.project'] = function() use ($app) { |
53
|
|
|
$className = '\JiraRestApi\Project\ProjectService'; |
54
|
|
|
return $app['jira.rest.service.builder']($className); |
55
|
|
|
}; |
56
|
|
|
|
57
|
|
|
$app['jira.rest.webhook'] = function() use ($app) { |
58
|
|
|
$className = '\JiraRestApi\Webhook\WebhookService'; |
59
|
|
|
return $app['jira.rest.service.builder']($className); |
60
|
|
|
}; |
61
|
|
|
} |
62
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.