CorePackageVersions::forTemplate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 19
rs 9.9
1
<?php
2
3
namespace BiffBangPow\SSMonitor\Client\Module;
4
5
use BiffBangPow\SSMonitor\Client\Core\ClientCommon;
6
use BiffBangPow\SSMonitor\Client\Core\ClientInterface;
7
use SilverStripe\Core\Config\Configurable;
8
use SilverStripe\Core\Injector\Injector;
9
use SilverStripe\Core\Manifest\VersionProvider;
10
use SilverStripe\ORM\ArrayList;
11
use SilverStripe\View\ArrayData;
12
use SilverStripe\View\HTML;
13
use SilverStripe\View\SSViewer;
14
15
class CorePackageVersions implements ClientInterface
16
{
17
    use ClientCommon;
18
    use Configurable;
19
20
    private string $clientName = 'corepackages';
0 ignored issues
show
introduced by
The private property $clientName is not used, and could be removed.
Loading history...
21
22
    private static $client_title = 'Core software packages';
0 ignored issues
show
introduced by
The private property $client_title is not used, and could be removed.
Loading history...
23
24
    private static $included_modules;
0 ignored issues
show
introduced by
The private property $included_modules is not used, and could be removed.
Loading history...
25
26
    public function getResult()
27
    {
28
        $modules = $this->config()->get('included_modules');
29
30
        /**
31
         * @var VersionProvider $versionProvider
32
         */
33
        $versionProvider = Injector::inst()->create(VersionProvider::class);
34
        $packages = $versionProvider->getModuleVersionFromComposer($modules);
35
36
        return [
37
            $this->getClientName() => $packages
38
        ];
39
40
    }
41
42
    /**
43
     *
44
     * @return \SilverStripe\ORM\FieldType\DBHTMLText
45
     * @throws \Exception
46
     */
47
    public function forTemplate()
48
    {
49
        $data = $this->getResult();
50
        $versions = ArrayList::create();
51
52
        foreach ($data[$this->getClientName()] as $packageName => $version) {
53
            $versions->push([
54
                'PackageName' => $packageName,
55
                'PackageVersion' => $version
56
            ]);
57
        }
58
59
        $viewer = new SSViewer('BiffBangPow/SSMonitor/Client/Module/CorePackageVersions');
60
        $html = $viewer->process(ArrayData::create([
61
            'Title' => $this->getClientTitle(),
62
            'Packages' => $versions
63
        ]));
64
65
        return $html;
66
    }
67
68
}
69