Passed
Branch master (608a5d)
by Simon
01:54
created

AnnotateClassInfo   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

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