Passed
Pull Request — master (#407)
by Kirill
05:21
created

AmazonUriFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 38
rs 10
c 1
b 0
f 1
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assertAvailable() 0 7 2
A createUri() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of Spiral Framework package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Distribution\Internal;
13
14
use GuzzleHttp\Psr7\Uri;
15
use Psr\Http\Message\UriFactoryInterface;
16
use Psr\Http\Message\UriInterface;
17
18
class AmazonUriFactory implements UriFactoryInterface
19
{
20
    /**
21
     * @var string
22
     */
23
    private const ERROR_NOT_AVAILABLE =
24
        'The "aws/aws-sdk-php" package is supplied with the Guzzle PSR-7 ' .
25
        'implementation, but it is not available. Please install the ' .
26
        '"aws/aws-sdk-php" package or use any other implementation of PSR-17 factories.'
27
    ;
28
29
    /**
30
     * AmazonUriFactory constructor.
31
     */
32
    public function __construct()
33
    {
34
        $this->assertAvailable();
35
    }
36
37
    /**
38
     * @param string $uri
39
     * @return UriInterface
40
     */
41
    public function createUri(string $uri = ''): UriInterface
42
    {
43
        return new Uri($uri);
44
    }
45
46
    /**
47
     * @return void
48
     */
49
    private function assertAvailable(): void
50
    {
51
        if (\class_exists(Uri::class)) {
52
            return;
53
        }
54
55
        throw new \DomainException(self::ERROR_NOT_AVAILABLE);
56
    }
57
}
58