Passed
Push — master ( 1ba30a...8ac47c )
by Luis
01:05 queued 12s
created

CodebaseDirectory::setDirectory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Parser;
7
8
use SplFileInfo;
9
use Webmozart\Assert\Assert;
0 ignored issues
show
Bug introduced by
The type Webmozart\Assert\Assert was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
final class CodebaseDirectory
12
{
13
    private readonly string $directory;
14
15 40
    public function __construct(string $path)
16
    {
17 40
        $this->directory = $this->getAbsolutePath($path);
0 ignored issues
show
Bug introduced by
The property directory is declared read-only in PhUml\Parser\CodebaseDirectory.
Loading history...
18
    }
19
20 26
    public function absolutePath(): string
21
    {
22 26
        return $this->directory;
23
    }
24
25 40
    private function getAbsolutePath(string $path): string
26
    {
27 40
        Assert::stringNotEmpty(
28
            $path,
29
            'The directory with the code to be scanned cannot be empty'
30
        );
31 40
        $directory = new SplFileInfo($path);
32 40
        if (! $directory->isDir()) {
33 4
            throw InvalidDirectory::notFoundAt($directory);
34
        }
35 36
        return $directory->getRealPath();
36
    }
37
}
38