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

Factory::getForSchema()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 13
nc 6
nop 2
dl 0
loc 15
ccs 12
cts 12
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
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