1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Moodle component manager. |
5
|
|
|
* |
6
|
|
|
* @author Luke Carrier <[email protected]> |
7
|
|
|
* @copyright 2016 Luke Carrier |
8
|
|
|
* @license GPL-3.0+ |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ComponentManager\PackageRepository; |
12
|
|
|
|
13
|
|
|
use ComponentManager\Component; |
14
|
|
|
use ComponentManager\ComponentSource\GitComponentSource; |
15
|
|
|
use ComponentManager\ComponentSpecification; |
16
|
|
|
use ComponentManager\ComponentVersion; |
17
|
|
|
use Github\Client; |
18
|
|
|
use Github\HttpClient\CachedHttpClient; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Git package repository. |
22
|
|
|
* |
23
|
|
|
* Allows sourcing components from arbitrary Git repositories. |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
class GitPackageRepository extends AbstractCachingPackageRepository |
|
|
|
|
26
|
|
|
implements PackageRepository { |
27
|
|
|
/** |
28
|
|
|
* @override \ComponentManager\PackageRepository\PackageRepository |
29
|
|
|
*/ |
30
|
|
|
public function getId() { |
31
|
|
|
return 'Git'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @override \ComponentManager\PackageRepository\PackageRepository |
36
|
|
|
*/ |
37
|
|
|
public function getName() { |
38
|
|
|
return 'Git package repository'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @override \ComponentManager\PackageRepository\PackageRepository |
43
|
|
|
*/ |
44
|
|
|
public function getComponent(ComponentSpecification $componentSpecification) { |
|
|
|
|
45
|
|
|
return new Component($componentSpecification->getName(), [ |
46
|
|
|
new ComponentVersion(null, null, null, [ |
47
|
|
|
new GitComponentSource($componentSpecification->getExtra('uri'), $componentSpecification->getVersion()) |
|
|
|
|
48
|
|
|
]), |
49
|
|
|
], $this); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @override \ComponentManager\PackageRepository\PackageRepository |
54
|
|
|
*/ |
55
|
|
|
public function satisfiesVersion($versionSpecification, ComponentVersion $version) { |
|
|
|
|
56
|
|
|
return true; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
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.