AnnotateClassInfo   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getClassFilePath() 0 3 1
A getModuleName() 0 7 1
A __construct() 0 5 1
1
<?php
2
3
namespace SilverLeague\IDEAnnotator\Helpers;
4
5
use ReflectionClass;
6
use ReflectionException;
7
use SilverStripe\Control\Director;
8
use SilverStripe\Core\Injector\Injector;
9
use SilverStripe\Core\Manifest\ModuleManifest;
10
11
/**
12
 * Class AnnotateClassInfo
13
 * We will need this for phpDocumentor as well.
14
 */
15
class AnnotateClassInfo
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $className = '';
21
22
    /**
23
     * @var ReflectionClass
24
     */
25
    protected $reflector;
26
27
    /**
28
     * AnnotateClassInfo constructor.
29
     *
30
     * @param $className
31
     * @throws ReflectionException
32
     */
33
    public function __construct($className)
34
    {
35
        $this->className = $className;
36
37
        $this->reflector = new ReflectionClass($className);
38
    }
39
40
    /**
41
     * Where module name is a folder in the webroot.
42
     *
43
     * @return string
44
     */
45
    public function getModuleName()
46
    {
47
        /** @var ModuleManifest $moduleManifest */
48
        $moduleManifest = Injector::inst()->createWithArgs(ModuleManifest::class, [Director::baseFolder()]);
49
        $module = $moduleManifest->getModuleByPath($this->reflector->getFileName());
50
51
        return $module->getName();
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getClassFilePath()
58
    {
59
        return $this->reflector->getFileName();
60
    }
61
}
62