ImportApp::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Module\Import;
6
7
use ReflectionClass;
8
9
use function assert;
10
use function dirname;
11
use function is_dir;
12
use function sprintf;
13
14
final class ImportApp
15
{
16
    /** @var non-empty-string */
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
17
    public string $appDir;
18
19
    /**
20
     * @param non-empty-string $host
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
21
     * @param non-empty-string $appName
22
     * @param non-empty-string $context
23
     */
24
    public function __construct(
25
        public string $host,
26
        public string $appName,
27
        public string $context,
28
    ) {
29
        /** @var class-string $appModuleClass */
30
        $appModuleClass = sprintf('%s\\Module\\AppModule', $this->appName);
31
        $appModuleClassName = (string) (new ReflectionClass($appModuleClass))->getFileName();
32
        $appDir = dirname($appModuleClassName, 3);
33
        assert(is_dir($appDir));
34
        assert($appDir !== '');
35
        $this->appDir = $appDir;
36
    }
37
}
38