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.
Completed
Push — master ( 9c694b...de5cf8 )
by Lanre
9s
created

GbowoFactory::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 9.6666
c 0
b 0
f 0
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
27 7
        if (!empty($types)) {
28 4
            $this->validateCustomAdapters($types);
29 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...
30
        }
31 5
    }
32
33 7
    protected function setDefaultAdapters()
34
    {
35 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...
36 7
            self::PAYSTACK => new PaystackAdapter(),
37 7
            self::AMPLIFY_PAY => new AmplifypayAdapter()
38
        ];
39 7
    }
40
41
    /**
42
     * @param array $types
43
     * @throws \Gbowo\Exception\UnknownAdapterException
44
     */
45 4
    protected function validateCustomAdapters(array $types)
46
    {
47 4
        foreach ($types as $type => $value) {
48 4
            if (array_key_exists($type, $this->availableAdapters)) {
49 1
                throw $this->throwException(
50 1
                    "You cannot override an internal adapter"
51
                );
52
            }
53
54 3
            if (!$value instanceof AdapterInterface) {
55 3
                throw $this->throwException("This is not a valid adapter");
56
            }
57
        }
58 2
    }
59
60 3
    protected function throwException(string $message)
61
    {
62 3
        return new UnknownAdapterException($message);
63
    }
64
65
    /**
66
     * @param string $adapterIdentifier
67
     * @return \Gbowo\Contract\Adapter\AdapterInterface
68
     * @throws \Gbowo\Exception\UnknownAdapterException
69
     */
70 5
    public function createAdapter(string $adapterIdentifier)
71
    {
72 5
        if (!array_key_exists($adapterIdentifier, $this->availableAdapters)) {
73 1
            throw $this->throwException(
74 1
                "Unknown adapter. Did you forget to add this adapter on object initialization ?"
75
            );
76
        }
77
78 4
        return $this->availableAdapters[$adapterIdentifier];
79
    }
80
}
81