Completed
Push — master ( 8f5cc3...69c507 )
by Martijn van
02:32
created

ListInstalledModulesCommand::getRootComposerFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
4
class ListInstalledModulesCommand extends SilverstripeCommand
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
    /**
7
     * @var string
8
     */
9
    protected $name = 'list:modules';
10
11
    /**
12
     * @var string
13
     */
14
    protected $description = 'List all installed modules';
15
16
    public function fire()
17
    {
18
19
        $this->table($this->getTableHeaders(), $this->getTableData());
20
    }
21
22
    protected function getTableHeaders()
23
    {
24
        return ['Module', 'Version'];
25
    }
26
27
    protected function getTableData()
28
    {
29
        return $this->getInstalledModules();
30
    }
31
32
    /**
33
     * @param string $file
34
     * @return mixed
35
     */
36
    protected function parseComposerFile($file)
37
    {
38
        return json_decode(file_get_contents($file));
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    protected function getRootComposerFile()
45
    {
46
        return BASE_PATH . '/vendor/composer/installed.json';
47
    }
48
49
    protected function getInstalledModules()
50
    {
51
        $content = $this->parseComposerFile($this->getRootComposerFile());
52
53
        $rows = [];
54
55
        foreach($content as $module) {
56
            $rows[] = [$module->name, $module->version];
57
        }
58
59
        return $rows;
60
    }
61
}
62