AmazonUriFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Distribution\Internal;
6
7
use GuzzleHttp\Psr7\Uri;
8
use Psr\Http\Message\UriFactoryInterface;
9
use Psr\Http\Message\UriInterface;
10
11
class AmazonUriFactory implements UriFactoryInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private const ERROR_NOT_AVAILABLE =
17
        'The "aws/aws-sdk-php" package is supplied with the Guzzle PSR-7 ' .
18
        'implementation, but it is not available. Please install the ' .
19
        '"aws/aws-sdk-php" package or use any other implementation of PSR-17 factories.'
20
    ;
21
22
    /**
23
     * AmazonUriFactory constructor.
24
     */
25
    public function __construct()
26
    {
27
        $this->assertAvailable();
28
    }
29
30
    public function createUri(string $uri = ''): UriInterface
31
    {
32
        return new Uri($uri);
33
    }
34
35
    private function assertAvailable(): void
36
    {
37
        if (\class_exists(Uri::class)) {
38
            return;
39
        }
40
41
        throw new \DomainException(self::ERROR_NOT_AVAILABLE);
42
    }
43
}
44