Completed
Pull Request — master (#3)
by Aymen
02:03
created

InstapushClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A configure() 0 9 1
A create() 0 7 1
1
<?php
2
/**
3
 * This file is part of the fnayou/instapush-php project.
4
 *
5
 * Copyright (c) 2017. Aymen FNAYOU <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fnayou\InstapushPHP;
12
13
use Fnayou\InstapushPHP\Transformer\ModelTransformer;
14
use Fnayou\InstapushPHP\Transformer\TransformerInterface;
15
use Http\Client\HttpClient;
16
use Http\Discovery\MessageFactoryDiscovery;
17
use Http\Message\RequestFactory;
18
19
/**
20
 * Class InstapushClient.
21
 */
22
final class InstapushClient
23
{
24
    /** @var \Http\Client\HttpClient */
25
    private $httpClient;
26
27
    /** @var \Http\Message\RequestFactory */
28
    private $requestFactory;
29
30
    /** @var \Fnayou\InstapushPHP\Transformer\TransformerInterface */
31
    private $transformer;
32
33
    /**
34
     * @param \Http\Client\HttpClient                                    $httpClient
35
     * @param \Http\Message\RequestFactory|null                          $requestFactory
36
     * @param \Fnayou\InstapushPHP\Transformer\TransformerInterface|null $transformer
37
     */
38
    public function __construct(
39
        HttpClient $httpClient,
40
        RequestFactory $requestFactory = null,
41
        TransformerInterface $transformer = null
42
    ) {
43
        $this->httpClient = $httpClient;
44
        $this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find();
45
        $this->transformer = $transformer ?: new ModelTransformer();
46
    }
47
48
    /**
49
     * @param \Fnayou\InstapushPHP\HttpClientConfigurator                $httpClientConfigurator
50
     * @param \Http\Message\RequestFactory|null                          $requestFactory
51
     * @param \Fnayou\InstapushPHP\Transformer\TransformerInterface|null $hydrator
52
     *
53
     * @return $this
54
     */
55
    public static function configure(
56
        HttpClientConfigurator $httpClientConfigurator,
57
        RequestFactory $requestFactory = null,
58
        TransformerInterface $hydrator = null
59
    ) {
60
        $httpClient = $httpClientConfigurator->createConfiguredClient();
61
62
        return new static($httpClient, $hydrator, $requestFactory);
0 ignored issues
show
Bug introduced by
It seems like $hydrator defined by parameter $hydrator on line 58 can also be of type object<Fnayou\InstapushP...r\TransformerInterface>; however, Fnayou\InstapushPHP\InstapushClient::__construct() does only seem to accept null|object<Http\Message\RequestFactory>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $requestFactory defined by parameter $requestFactory on line 57 can also be of type object<Http\Message\RequestFactory>; however, Fnayou\InstapushPHP\InstapushClient::__construct() does only seem to accept null|object<Fnayou\Insta...r\TransformerInterface>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
63
    }
64
65
    /**
66
     * @param string $userToken
67
     * @param string $appIdentifier
68
     * @param string $appSecret
69
     *
70
     * @return $this
71
     */
72
    public static function create(string $userToken, string $appIdentifier, string $appSecret)
73
    {
74
        $httpClientConfigurator = new HttpClientConfigurator();
75
        $httpClientConfigurator->setApiCredentials($userToken, $appIdentifier, $appSecret);
76
77
        return static::configure($httpClientConfigurator);
78
    }
79
}
80