Uri   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A __construct() 0 15 4
1
<?php
2
3
namespace CHStudio\Raven\Http\Factory;
4
5
use InvalidArgumentException;
6
use Stringable;
7
8
class Uri implements Stringable
9
{
10
    private readonly string $uri;
11
12 15
    public function __construct(mixed $value)
13
    {
14 15
        if (\is_array($value)) {
15 4
            if (!isset($value['base'])) {
16 1
                throw new InvalidArgumentException(
17 1
                    'If you want to build an URI from an array, use the schema: [ base => string, ?parameters => [string => mixed]'
18 1
                );
19
            }
20
21 3
            $parameters = $value['parameters'] ?? [];
22 3
            $value = str_replace(array_keys($parameters), $parameters, (string) $value['base']);
23 11
        } elseif (!\is_string($value)) {
24 4
            throw new InvalidArgumentException('$value must be a string or an array.');
25
        }
26 10
        $this->uri = $value;
0 ignored issues
show
Bug introduced by
The property uri is declared read-only in CHStudio\Raven\Http\Factory\Uri.
Loading history...
27
    }
28
29 10
    public function __toString(): string
30
    {
31 10
        return $this->uri;
32
    }
33
}
34