Factory::getProtocol()   B
last analyzed

Complexity

Conditions 8
Paths 8

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 15
nc 8
nop 2
dl 0
loc 25
ccs 14
cts 14
cp 1
crap 8
rs 8.4444
c 1
b 0
f 0
1
<?php
2
3
namespace kalanis\RemoteRequest\Protocols;
4
5
6
use kalanis\RemoteRequest;
7
8
9
/**
10
 * Class Factory
11
 * @package kalanis\RemoteRequest\Protocols
12
 * Factory to select correct layer for protocol
13
 */
14
class Factory
15
{
16
    /**
17
     * @param string $schema
18
     * @param RemoteRequest\Interfaces\IRRTranslations $lang
19
     * @throws RemoteRequest\RequestException
20
     * @return AProtocol
21
     */
22 2
    public static function getProtocol(string $schema, RemoteRequest\Interfaces\IRRTranslations $lang): AProtocol
23
    {
24
        switch ($schema) {
25 2
            case 'tcp':
26 2
            case 'file':
27 1
                return new Tcp();
28 2
            case 'udp':
29 1
                return new Udp();
30 2
            case 'fsp':
31 1
                return new Fsp();
32 2
            case 'http':
33 2
            case 'https':
34 1
                return new Http();
35
//            case 'http2':
36
//                return new Http2();
37
//            case 'http3':
38
//                return new Http3();
39 2
            case 'webdav':
40 1
                return new WebDAV();
41
//            case 'smb':
42
//                return new Samba();
43
//            case 'git':
44
//                return new Git();
45
            default:
46 1
                throw new RemoteRequest\RequestException($lang->rrSchemaUnknownResponse($schema));
47
        }
48
    }
49
}
50