Completed
Push — master ( 4de1a8...34f279 )
by WEBEWEB
02:53
created

CURLFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 9
dl 0
loc 47
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getInstance() 0 35 9
1
<?php
2
3
/**
4
 * This file is part of the curl-library package.
5
 *
6
 * (c) 2017 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\CURL\Factory;
13
14
use WBW\Library\Core\Exception\IO\InvalidHTTPMethodException;
15
use WBW\Library\Core\IO\HTTPInterface;
16
use WBW\Library\CURL\Configuration\CURLConfiguration;
17
use WBW\Library\CURL\Request\CURLDeleteRequest;
18
use WBW\Library\CURL\Request\CURLGetRequest;
19
use WBW\Library\CURL\Request\CURLHeadRequest;
20
use WBW\Library\CURL\Request\CURLOptionsRequest;
21
use WBW\Library\CURL\Request\CURLPatchRequest;
22
use WBW\Library\CURL\Request\CURLPostRequest;
23
use WBW\Library\CURL\Request\CURLPutRequest;
24
use WBW\Library\CURL\Request\CURLRequestInterface;
25
26
/**
27
 * cURL factory.
28
 *
29
 * @author webeweb <https://github.com/webeweb/>
30
 * @package WBW\Library\CURL\Factory
31
 */
32
class CURLFactory implements HTTPInterface {
33
34
    /**
35
     * Get an instance.
36
     *
37
     * @param string $method The method.
38
     * @param CURLConfiguration $configuration The configuration.
39
     * @return CURLRequestInterface Returns this cURL request.
40
     * @throws InvalidHTTPMethodException Throws an invalid HTTP method exception if the method is not implemented.
41
     */
42
    public static function getInstance($method, CURLConfiguration $configuration = null, $resourcePath = null) {
43
44
        // Check the configuration.
45
        if (null === $configuration) {
46
            $configuration = new CURLConfiguration();
47
        }
48
49
        // Switch into $method.
50
        switch ($method) {
51
52
            case self::HTTP_METHOD_DELETE:
53
                return new CURLDeleteRequest($configuration, $resourcePath);
54
55
            case self::HTTP_METHOD_GET:
56
                return new CURLGetRequest($configuration, $resourcePath);
57
58
            case self::HTTP_METHOD_HEAD:
59
                return new CURLHeadRequest($configuration, $resourcePath);
60
61
            case self::HTTP_METHOD_OPTIONS:
62
                return new CURLOptionsRequest($configuration, $resourcePath);
63
64
            case self::HTTP_METHOD_PATCH:
65
                return new CURLPatchRequest($configuration, $resourcePath);
66
67
            case self::HTTP_METHOD_POST:
68
                return new CURLPostRequest($configuration, $resourcePath);
69
70
            case self::HTTP_METHOD_PUT:
71
                return new CURLPutRequest($configuration, $resourcePath);
72
73
            default:
74
                throw new InvalidHTTPMethodException($method);
75
        }
76
    }
77
78
}
79