GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

GbowoFactory   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 75
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 3

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addCustomAdapters() 0 7 2
A setDefaultAdapters() 0 7 1
A validateCustomAdapters() 0 14 4
A throwException() 0 4 1
A createAdapter() 0 10 2
1
<?php
2
3
4
namespace Gbowo;
5
6
use Gbowo\Exception\UnknownAdapterException;
7
use Gbowo\Adapter\Paystack\PaystackAdapter;
8
use Gbowo\Contract\Adapter\AdapterInterface;
9
use Gbowo\Adapter\Amplifypay\AmplifypayAdapter;
10
11
class GbowoFactory
12
{
13
14
    const PAYSTACK = "paystack";
15
16
    const AMPLIFY_PAY = "amplifypay";
17
18
    /**
19
     * @var AdapterInterface[]
20
     */
21
    protected $availableAdapters = [];
22
23 7
    public function __construct(array $types = [])
24
    {
25 7
        $this->setDefaultAdapters();
26 7
        $this->addCustomAdapters($types);
27 5
    }
28
29 7
    protected function addCustomAdapters(array $types)
30
    {
31 7
        if (!empty($types)) {
32 4
            $this->validateCustomAdapters($types);
33 2
            $this->availableAdapters = array_merge($this->availableAdapters, $types);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge($this->availableAdapters, $types) of type array is incompatible with the declared type array<integer,object<Gbo...pter\AdapterInterface>> of property $availableAdapters.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
        }
35 5
    }
36
37
38 7
    protected function setDefaultAdapters()
39
    {
40 7
        $this->availableAdapters = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array(self::PAYSTACK => ...ay\AmplifypayAdapter()) of type array<string,object<Gbow...pay\AmplifypayAdapter>> is incompatible with the declared type array<integer,object<Gbo...pter\AdapterInterface>> of property $availableAdapters.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41 7
            self::PAYSTACK => new PaystackAdapter(),
42 7
            self::AMPLIFY_PAY => new AmplifypayAdapter()
43
        ];
44 7
    }
45
46
    /**
47
     * @param array $types
48
     * @throws \Gbowo\Exception\UnknownAdapterException
49
     */
50 4
    protected function validateCustomAdapters(array $types)
51
    {
52 4
        foreach ($types as $type => $value) {
53 4
            if (array_key_exists($type, $this->availableAdapters)) {
54 1
                throw $this->throwException(
55 1
                    "You cannot override an internal adapter"
56
                );
57
            }
58
59 3
            if (!$value instanceof AdapterInterface) {
60 3
                throw $this->throwException("This is not a valid adapter");
61
            }
62
        }
63 2
    }
64
65 3
    protected function throwException(string $message)
66
    {
67 3
        return new UnknownAdapterException($message);
68
    }
69
70
    /**
71
     * @param string $adapterIdentifier
72
     * @return \Gbowo\Contract\Adapter\AdapterInterface
73
     * @throws \Gbowo\Exception\UnknownAdapterException
74
     */
75 5
    public function createAdapter(string $adapterIdentifier)
76
    {
77 5
        if (!array_key_exists($adapterIdentifier, $this->availableAdapters)) {
78 1
            throw $this->throwException(
79 1
                "Unknown adapter. Did you forget to add this adapter on object initialization ?"
80
            );
81
        }
82
83 4
        return $this->availableAdapters[$adapterIdentifier];
84
    }
85
}
86