AbstractListCommand::getTableData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 1
Metric Value
c 3
b 2
f 1
dl 0
loc 19
rs 9.4285
cc 2
eloc 11
nc 2
nop 0
1
<?php
2
3
4
abstract class AbstractListCommand 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
    public function fire()
7
    {
8
        $this->table($this->getTableHeaders(), $this->getTableData());
9
    }
10
11
    /**
12
     * @return string
13
     */
14
    abstract protected function getClassName();
15
16
    /**
17
     * @return array
18
     */
19
    protected function getTableData()
20
    {
21
        $classes = (array) ClassInfo::subclassesFor($this->getClassName());
22
23
        unset($classes[$this->getClassName()]);
24
25
        foreach ($classes as $key => $class) {
26
            $classes[$class] = [
27
                $class,
28
                implode("\n", (array) $this->getExtensions($class)),
29
                implode(' => ', (array) $this->getParentClasses($class)),
30
                $this->getModule($class),
31
            ];
32
        }
33
34
        ksort($classes);
35
36
        return $classes;
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    protected function getTableHeaders()
43
    {
44
        return ['ClassName', 'Extensions', 'Extends', 'Module'];
45
    }
46
47
    /**
48
     * @param $className
49
     *
50
     * @return array
51
     */
52
    protected function getExtensions($className)
53
    {
54
        return (array) Config::inst()->get($className, 'extensions', Config::UNINHERITED);
55
    }
56
57
    /**
58
     * @param string $className
59
     *
60
     * @return string
61
     */
62
    protected function getModule($className)
63
    {
64
        $reflection = new \ReflectionClass($className);
65
        $file = $reflection->getFileName();
66
67
        $path = str_replace([BASE_PATH.'/'], '', $file);
68
        $parts = explode(DIRECTORY_SEPARATOR, $path);
69
70
        return (string) array_shift($parts);
71
    }
72
73
    /**
74
     * @param string $className
75
     *
76
     * @return array
77
     */
78
    protected function getParentClasses($className)
79
    {
80
        return ClassInfo::ancestry($className);
81
    }
82
}
83