RequestFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 39
ccs 12
cts 12
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __call() 0 15 3
1
<?php
2
3
namespace CommerceGuys\AuthNet;
4
5
use GuzzleHttp\Client;
6
7
/**
8
 * @method CreateTransactionRequest createTransactionRequest()
9
 */
10
class RequestFactory
11
{
12
    /**
13
     * @var \CommerceGuys\AuthNet\Configuration
14
     */
15
    protected $configuration;
16
17
    /**
18
     * @var \GuzzleHttp\Client
19
     */
20
    protected $client;
21
22
    /**
23
     * BaseRequest constructor.
24
     *
25
     * @param \CommerceGuys\AuthNet\Configuration $configuration
26
     * @param \GuzzleHttp\Client $client
27
     */
28 19
    public function __construct(Configuration $configuration, Client $client)
29
    {
30 19
        $this->configuration = $configuration;
31 19
        $this->client = $client;
32 19
    }
33
34 11
    public function __call($name, $args = null)
35
    {
36
37 11
        $class = '\\' . (new \ReflectionClass($this))->getNamespaceName() . '\\' . ucfirst($name);
38 11
        if (!class_exists($class)) {
39 1
            throw new \InvalidArgumentException("Request $name does not exist");
40
        }
41
42 10
        if (!(new \ReflectionClass($class))->implementsInterface(ApiRequestInterface::class)) {
43 1
            throw new \InvalidArgumentException("Request $name is not a valid request");
44
        }
45
46 9
        $instance = new $class($this->configuration, $this->client);
47
48 9
        return $instance;
49
    }
50
}
51