Passed
Push — master ( 15770c...ea0752 )
by Petr
08:09
created

Factory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 23
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A getForSchema() 0 15 6
1
<?php
2
3
namespace kalanis\RemoteRequest\Connection\Params;
4
5
6
use kalanis\RemoteRequest\Interfaces\IRRTranslations;
7
use kalanis\RemoteRequest\Interfaces\ISchema;
8
use kalanis\RemoteRequest\RequestException;
9
10
11
/**
12
 * Class Factory
13
 * @package kalanis\RemoteRequest\Connection\Params
14
 * Factory for getting a correct connection scheme
15
 * Define known schemes for access remote resource via php internal calls
16
 * @link https://www.php.net/manual/en/wrappers.php
17
 */
18
class Factory
19
{
20
    /**
21
     * @param IRRTranslations $lang
22
     * @param string $schema
23
     * @throws RequestException
24
     * @return AParams
25
     */
26 2
    public static function getForSchema(IRRTranslations $lang, string $schema): AParams
27
    {
28
        switch ($schema) {
29 2
            case ISchema::SCHEMA_FILE:
30 1
                return new File();
31 2
            case ISchema::SCHEMA_PHP:
32 1
                return new Php();
33 2
            case ISchema::SCHEMA_TCP:
34 1
                return new Tcp();
35 2
            case ISchema::SCHEMA_UDP:
36 1
                return new Udp();
37 2
            case ISchema::SCHEMA_SSL:
38 1
                return new Ssl();
39
            default:
40 1
                throw new RequestException($lang->rrSchemaUnknownPacketWrapper());
41
        }
42
    }
43
}
44