ApiFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 22
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
1
<?php
2
namespace Katapoka\Ahgora;
3
4
use InvalidArgumentException;
5
use Katapoka\Ahgora\Contracts\IHttpClient;
6
7
class ApiFactory
8
{
9
    /**
10
     * Tries to instantiate an API class compatible.
11
     *
12
     * @param IHttpClient $httpCLient
13
     * @param string      $type
14
     *
15
     * @throws InvalidArgumentException
16
     *
17
     * @return \Katapoka\Ahgora\AbstractApi
18
     */
19
    public static function create(IHttpClient $httpCLient, $type)
20
    {
21
        $className = sprintf('%s\\%sApi', __NAMESPACE__, $type);
22
        if (class_exists($className)) {
23
            return new $className($httpCLient);
24
        }
25
26
        throw new InvalidArgumentException("Api type `{$type}` not found.");
27
    }
28
}
29