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

OutputFilePath::withExpectedExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 2
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 1
rs 9.9666
c 0
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\Processors;
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 OutputFilePath
12
{
13 17
    public static function withExpectedExtension(string $filePath, string $expectedExtension): OutputFilePath
14
    {
15 17
        $path = new SplFileInfo(trim($filePath));
16 17
        $extension = $path->getExtension();
17 17
        $directory = realpath($path->getPath());
18 17
        Assert::true($directory !== false, "Directory '{$path->getPath()}' does not exist");
19 16
        Assert::eq(
20
            $extension,
21
            $expectedExtension,
22 16
            "Output file is expected to have extension '.{$expectedExtension}', '.{$extension}' given"
23
        );
24
25 15
        return new OutputFilePath(new SplFileInfo($directory . '/' . $path->getBasename()));
26
    }
27
28 15
    private function __construct(private readonly SplFileInfo $filePath)
29
    {
30
    }
31
32 15
    public function value(): string
33
    {
34 15
        return $this->filePath->getPathname();
35
    }
36
}
37