Passed
Push — master ( 67a5da...c35f7b )
by Jared
01:13
created

InStoreApi   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 0
Metric Value
wmc 15
lcom 0
cbo 9
dl 0
loc 102
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A device() 0 12 3
A preapproval() 0 12 3
A order() 0 12 3
A refund() 0 12 3
A customer() 0 12 3
1
<?php
2
namespace CultureKings\Afterpay\Factory;
3
4
use CultureKings\Afterpay\Model\InStore\Authorization;
5
use CultureKings\Afterpay\Service;
6
use Doctrine\Common\Annotations\AnnotationRegistry;
7
use GuzzleHttp\Client;
8
use GuzzleHttp\ClientInterface;
9
use GuzzleHttp\Exception\ClientException;
10
use JMS\Serializer\SerializerInterface;
11
12
/**
13
 * Class InStoreApi
14
 * @package CultureKings\Afterpay\Factory
15
 */
16
class InStoreApi
17
{
18
    /**
19
     * @param Authorization            $authorization
20
     * @param ClientInterface|null     $client
21
     * @param SerializerInterface|null $serializer
22
     *
23
     * @return Service\InStore\Device
24
     */
25
    public static function device(
26
        Authorization $authorization,
27
        ClientInterface $client = null,
28
        SerializerInterface $serializer = null
29
    ) {
30
        AnnotationRegistry::registerLoader('class_exists');
31
32
        $afterpayClient = $client ?: new Client([ 'base_uri' => $authorization->getEndpoint() ]);
33
        $afterpaySerializer = $serializer ?: SerializerFactory::getSerializer();
34
35
        return new Service\InStore\Device($authorization, $afterpayClient, $afterpaySerializer);
0 ignored issues
show
Compatibility introduced by
$afterpayClient of type object<GuzzleHttp\ClientInterface> is not a sub-type of object<GuzzleHttp\Client>. It seems like you assume a concrete implementation of the interface GuzzleHttp\ClientInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
36
    }
37
38
    /**
39
     * @param Authorization            $authorization
40
     * @param Client|null              $client
41
     * @param SerializerInterface|null $serializer
42
     *
43
     * @return Service\InStore\PreApproval
44
     */
45
    public static function preapproval(
46
        Authorization $authorization,
47
        Client $client = null,
48
        SerializerInterface $serializer = null
49
    ) {
50
        AnnotationRegistry::registerLoader('class_exists');
51
52
        $afterpayClient = $client ?: new Client([ 'base_uri' => $authorization->getEndpoint() ]);
53
        $afterpaySerializer = $serializer ?: SerializerFactory::getSerializer();
54
55
        return new Service\InStore\PreApproval($authorization, $afterpayClient, $afterpaySerializer);
56
    }
57
58
    /**
59
     * @param Authorization            $authorization
60
     * @param Client|null              $client
61
     * @param SerializerInterface|null $serializer
62
     *
63
     * @return Service\InStore\Order
64
     */
65
    public static function order(
66
        Authorization $authorization,
67
        Client $client = null,
68
        SerializerInterface $serializer = null
69
    ) {
70
        AnnotationRegistry::registerLoader('class_exists');
71
72
        $afterpayClient = $client ?: new Client([ 'base_uri' => $authorization->getEndpoint() ]);
73
        $afterpaySerializer = $serializer ?: SerializerFactory::getSerializer();
74
75
        return new Service\InStore\Order($authorization, $afterpayClient, $afterpaySerializer);
76
    }
77
78
    /**
79
     * @param Authorization            $authorization
80
     * @param Client|null              $client
81
     * @param SerializerInterface|null $serializer
82
     *
83
     * @return Service\InStore\Refund
84
     */
85
    public static function refund(
86
        Authorization $authorization,
87
        Client $client = null,
88
        SerializerInterface $serializer = null
89
    ) {
90
        AnnotationRegistry::registerLoader('class_exists');
91
92
        $afterpayClient = $client ?: new Client([ 'base_uri' => $authorization->getEndpoint() ]);
93
        $afterpaySerializer = $serializer ?: SerializerFactory::getSerializer();
94
95
        return new Service\InStore\Refund($authorization, $afterpayClient, $afterpaySerializer);
96
    }
97
98
    /**
99
     * @param Authorization            $authorization
100
     * @param Client|null              $client
101
     * @param SerializerInterface|null $serializer
102
     *
103
     * @return Service\InStore\Customer
104
     */
105
    public static function customer(
106
        Authorization $authorization,
107
        Client $client = null,
108
        SerializerInterface $serializer = null
109
    ) {
110
        AnnotationRegistry::registerLoader('class_exists');
111
112
        $afterpayClient = $client ?: new Client([ 'base_uri' => $authorization->getEndpoint() ]);
113
        $afterpaySerializer = $serializer ?: SerializerFactory::getSerializer();
114
115
        return new Service\InStore\Customer($authorization, $afterpayClient, $afterpaySerializer);
116
    }
117
}
118