Passed
Pull Request — master (#22)
by Luis
24:40 queued 21:48
created

OutputFilePath::withExpectedExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 2
dl 0
loc 13
ccs 10
cts 10
cp 1
crap 1
rs 9.9666
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Processors;
9
10
use SplFileInfo;
11
use Webmozart\Assert\Assert;
12
13
final class OutputFilePath
14
{
15 17
    public static function withExpectedExtension(string $filePath, string $expectedExtension): OutputFilePath
16
    {
17 17
        $path = new SplFileInfo(trim($filePath));
18 17
        $extension = $path->getExtension();
19 17
        $directory = realpath($path->getPath());
20 17
        Assert::true($directory !== false, "Directory '{$path->getPath()}' does not exist");
21 16
        Assert::eq(
22
            $extension,
23
            $expectedExtension,
24 16
            "Output file is expected to have extension '.{$expectedExtension}', '.{$extension}' given"
25
        );
26
27 15
        return new OutputFilePath(new SplFileInfo($directory . '/' . $path->getBasename()));
28
    }
29
30 15
    private function __construct(private readonly SplFileInfo $filePath)
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 30 at column 50
Loading history...
31
    {
32
    }
33
34 15
    public function value(): string
35
    {
36 15
        return $this->filePath->getPathname();
37
    }
38
}
39