Passed
Push — add-command-list-modules ( fd1ae6...c98401 )
by Chema
02:58
created

AppModule::fullyQualifiedClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Console\Domain\AllAppModules;
6
7
final class AppModule
8
{
9 2
    public function __construct(
10
        private string $moduleName,
11
        private string $className,
12
        private string $namespace,
13
    ) {
14 2
    }
15
16 2
    public static function fromClass(string $fullyQualifiedClassName): self
17
    {
18 2
        $parts = explode('\\', $fullyQualifiedClassName);
19 2
        $className = array_pop($parts);
20 2
        $moduleName = (string)end($parts);
21 2
        $namespace = implode('\\', $parts);
22
23 2
        return new self(
24 2
            $moduleName,
25 2
            $className,
26 2
            $namespace,
27 2
        );
28
    }
29
30 1
    public function moduleName(): string
31
    {
32 1
        return $this->moduleName;
33
    }
34
35
    /**
36
     * @return class-string
37
     */
38 2
    public function facadeClass(): string
39
    {
40 2
        return sprintf(
41 2
            '%s\\%s',
42 2
            $this->namespace,
43 2
            $this->className,
44 2
        );
45
    }
46
}
47