StreamException::invalidClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace FakeSocket;
5
6
use FakeSocket\StreamWrapper;
7
use InvalidArgumentException;
8
9
final class StreamException extends InvalidArgumentException
10
{
11
    public const INVALID_CLASS = 1;
12
    public const INVALID_DATA_SOURCE = 2;
13
    public const INVALID_PORT = 3;
14
15 1
    public static function invalidClass(string $spec): StreamException
16
    {
17 1
        $interface = StreamWrapper::class;
18
19 1
        return new static(
20 1
            "Stream class `{$spec}` must implement `{$interface}`",
21 1
            self::INVALID_CLASS
22
        );
23
    }
24
25 1
    public static function invalidDataSource(): StreamException
26
    {
27 1
        return new static(
28 1
            'Host or path are required',
29 1
            self::INVALID_DATA_SOURCE
30
        );
31
    }
32
33 3
    public static function invalidPortRange(int $minPort, int $maxPort): StreamException
34
    {
35 3
        return new static(
36 3
            "Port Number must be in the Range from {$minPort} to {$maxPort}",
37 3
            self::INVALID_PORT
38
        );
39
    }
40
}
41