ComposerLoaderExtensionStub   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstalledConstraint() 0 11 4
A getRepository() 0 12 1
A onAfterBuild() 0 2 1
1
<?php
2
3
namespace BringYourOwnIdeas\UpdateChecker\Tests\Stubs;
4
5
use BringYourOwnIdeas\UpdateChecker\Extensions\ComposerLoaderExtension;
6
use Composer\Package\Package;
7
use Composer\Repository\ArrayRepository;
8
use Composer\Repository\BaseRepository;
9
use SilverStripe\Dev\TestOnly;
10
11
/**
12
 * A partially stubbed version of the {@link ComposerLoaderExtension} extension which doesn't rely on Composer
13
 */
14
class ComposerLoaderExtensionStub extends ComposerLoaderExtension implements TestOnly
15
{
16
    protected function getRepository()
17
    {
18
        $vendorModule = new Package('silverstripe/framework', '4.1.1.0', '4.1.1');
19
        $vendorModule->setType('silverstripe-vendormodule');
20
21
        $silverstripeModule = new Package('silverstripe-themes/simple', '2.1.0.1', '2.1.0');
22
        $silverstripeModule->setType('silverstripe-module');
23
24
        $generalPackage = new Package('something/unrelated', '1.2.3.4', '1.2.3');
25
        $generalPackage->setType('package');
26
27
        return new ArrayRepository([$vendorModule, $silverstripeModule, $generalPackage]);
28
    }
29
30
    protected function getInstalledConstraint(BaseRepository $repository, $packageName)
31
    {
32
        switch ($packageName) {
33
            case 'silverstripe/framework':
34
                return '4.1.1';
35
            case 'silverstripe-themes/simple':
36
                return '~2.1.0';
37
            case 'something/unrelated':
38
                return '^1.0';
39
            default:
40
                return '';
41
        }
42
    }
43
44
    public function onAfterBuild()
45
    {
46
        // noop - don't load local Composer repository
47
    }
48
}
49