Factory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1.0005

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 13
ccs 11
cts 12
cp 0.9167
rs 9.9
cc 1
nc 1
nop 4
crap 1.0005
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpIso\Descriptor;
6
7
use PhpIso\Descriptor;
8
9
class Factory
10
{
11
    /**
12
     * @param array<int, int> $bytes
13
     */
14 19
    public static function create(int $type, string $stdId = '', int $version = 0, ?array $bytes = null): Descriptor
15
    {
16 19
        return match ($type) {
17 2
            Type::BOOT_RECORD_DESC => new Boot($stdId, $version, $bytes),
18 17
            Type::PRIMARY_VOLUME_DESC => new PrimaryVolume($stdId, $version, $bytes),
19 10
            Type::SUPPLEMENTARY_VOLUME_DESC => new SupplementaryVolume($stdId, $version, $bytes),
20
            Type::PARTITION_VOLUME_DESC => new Partition($stdId, $version, $bytes),
21 17
            Type::TERMINATOR_DESC => new Terminator($stdId, $version, $bytes),
22 10
            Type::UDF_BEA_VOLUME_DESC => new UdfBeaDescriptor($stdId, $version, $bytes),
23 8
            Type::UDF_NSR2_VOLUME_DESC => new UdfNsr2Descriptor($stdId, $version, $bytes),
24 2
            Type::UDF_NSR3_VOLUME_DESC => new UdfNsr3Descriptor($stdId, $version, $bytes),
25 10
            Type::UDF_TEA_VOLUME_DESC => new UdfTeaDescriptor($stdId, $version, $bytes),
26 19
            default => throw new Exception('Invalid descriptor type received: ' . $type),
27 19
        };
28
    }
29
}
30