HappyrClient::statement()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Happyr\ApiClient;
4
5
use Happyr\ApiClient\Hydrator\Hydrator;
6
use Happyr\ApiClient\Hydrator\ModelHydrator;
7
use Http\Client\HttpClient;
8
use Http\Discovery\MessageFactoryDiscovery;
9
use Http\Message\RequestFactory;
10
11
/**
12
 * @author Tobias Nyholm <[email protected]>
13
 */
14
final class HappyrClient
15
{
16
    /**
17
     * @var HttpClient
18
     */
19
    private $httpClient;
20
21
    /**
22
     * @var Hydrator
23
     */
24
    private $hydrator;
25
26
    /**
27
     * @var RequestFactory
28
     */
29
    private $requestFactory;
30
31
    /**
32
     * The constructor accepts already configured HTTP clients.
33
     * Use the configure method to pass a configuration to the Client and create an HTTP Client.
34
     *
35
     * @param HttpClient          $httpClient
36
     * @param Hydrator|null       $hydrator
37
     * @param RequestFactory|null $requestFactory
38
     */
39
    public function __construct(
40
        HttpClient $httpClient,
41
        Hydrator $hydrator = null,
42
        RequestFactory $requestFactory = null
43
    ) {
44
        $this->httpClient = $httpClient;
45
        $this->hydrator = $hydrator ?: new ModelHydrator();
46
        $this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find();
47
    }
48
49
    /**
50
     * @param HttpClientConfigurator $httpClientConfigurator
51
     * @param Hydrator|null          $hydrator
52
     * @param RequestFactory|null    $requestFactory
53
     *
54
     * @return HappyrClient
55
     */
56
    public static function configure(
57
        HttpClientConfigurator $httpClientConfigurator,
58
        Hydrator $hydrator = null,
59
        RequestFactory $requestFactory = null
60
    ) {
61
        $httpClient = $httpClientConfigurator->createConfiguredClient();
62
63
        return new self($httpClient, $hydrator, $requestFactory);
64
    }
65
66
    /**
67
     * @param string $identifier
68
     * @param string $secret
69
     *
70
     * @return HappyrClient
71
     */
72
    public static function create($identifier, $secret)
73
    {
74
        $httpClientConfigurator = (new HttpClientConfigurator())->setApiCredentials($identifier, $secret);
75
76
        return self::configure($httpClientConfigurator);
77
    }
78
79
    /**
80
     * @return Api\Interview
81
     */
82
    public function interview()
83
    {
84
        return new Api\Interview($this->httpClient, $this->hydrator, $this->requestFactory);
85
    }
86
87
    /**
88
     * @return Api\Dimension
89
     */
90
    public function dimensions()
91
    {
92
        return new Api\Dimension($this->httpClient, $this->hydrator, $this->requestFactory);
93
    }
94
95
    /**
96
     * @return Api\Match
97
     */
98
    public function match()
99
    {
100
        return new Api\Match($this->httpClient, $this->hydrator, $this->requestFactory);
101
    }
102
103
    /**
104
     * @return Api\Norm
105
     */
106
    public function norm()
107
    {
108
        return new Api\Norm($this->httpClient, $this->hydrator, $this->requestFactory);
109
    }
110
111
    /**
112
     * @return Api\ProfilePattern
113
     */
114
    public function profilePattern()
115
    {
116
        return new Api\ProfilePattern($this->httpClient, $this->hydrator, $this->requestFactory);
117
    }
118
119
    /**
120
     * @return Api\Statement
121
     */
122
    public function statement()
123
    {
124
        return new Api\Statement($this->httpClient, $this->hydrator, $this->requestFactory);
125
    }
126
127
    /**
128
     * @return Api\UserManagement
129
     */
130
    public function userManagement()
131
    {
132
        return new Api\UserManagement($this->httpClient, $this->hydrator, $this->requestFactory);
133
    }
134
}
135