Test Failed
Branch master (fdda4e)
by ANTHONIUS
03:39
created

ModuleTrait::buildInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 10
1
<?php
2
3
/*
4
 * This file is part of the EOffice project.
5
 *
6
 * (c) Anthonius Munthi <https://itstoni.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace EOffice\Core\Application;
15
16
use Doctrine\Inflector\Rules\English\InflectorFactory;
17
18
trait ModuleTrait
19
{
20
    protected ?string $baseDir    = null;
21
    protected ?string $moduleName = null;
22
23
    public function getBaseDir(): string
24
    {
25
        if (null === $this->baseDir) {
26
            $this->buildInfo();
27
        }
28
29
        return $this->baseDir;
30
    }
31
32
    public function getName(): string
33
    {
34
        if (null === $this->moduleName) {
35
            $this->buildInfo();
36
        }
37
38
        return $this->moduleName;
39
    }
40
41
    protected function buildInfo()
42
    {
43
        $r = new \ReflectionClass($this);
44
45
        // build className
46
        $class            = str_replace($r->getNamespaceName().'\\', '', $r->getName());
47
        $class            = str_replace('Module', '', $class);
48
        $inflector        = (new InflectorFactory())->build();
49
        $name             = $inflector->tableize($class);
50
        $this->moduleName = $name;
51
52
        // base dir
53
        $this->baseDir = \dirname($r->getFileName());
54
    }
55
}
56