Passed
Pull Request — master (#6)
by Mariano
13:06 queued 09:05
created

Scheme::createHttp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Mcustiel\Phiremock\Client\Utils\Http;
4
5
class Scheme
6
{
7
    public const HTTP = 'http';
8
    public const HTTPS = 'https';
9
10
    /** @var string */
11
    private $scheme;
12
13
    public function __construct(string $scheme)
14
    {
15
        $this->ensureIsValidScheme($scheme);
16
        $this->scheme = $scheme;
17
    }
18
19
    public static function createHttp(): self
20
    {
21
        return new self(self::HTTP);
22
    }
23
24
    public static function createHttps(): self
25
    {
26
        return new self(self::HTTPS);
27
    }
28
29
    public function asString(): string
30
    {
31
        return $this->scheme;
32
    }
33
34
    private function ensureIsValidScheme($scheme)
35
    {
36
        if (preg_match('/^https?$/', $scheme) !== 1) {
37
            throw new \InvalidArgumentException(sprintf('Invalid scheme %s', $scheme));
38
        }
39
    }
40
}
41