ApiFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 6
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