Client::connectionTest()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 6
rs 10
1
<?php
2
3
namespace CybozuHttp;
4
5
use CybozuHttp\Exception\RedirectResponseException;
6
use GuzzleHttp\Client as GuzzleClient;
7
use CybozuHttp\Exception\NotExistRequiredException;
8
9
/**
10
 * @author ochi51<[email protected]>
11
 */
12
class Client extends GuzzleClient
13
{
14
15
    /**
16
     * Client constructor.
17
     * @param array $config
18
     * @throws NotExistRequiredException
19
     */
20 3
    public function __construct(array $config = [])
21
    {
22 3
        $cybozuConfig = new Config($config);
23 3
        if (!$cybozuConfig->hasRequired()) {
24 1
            throw new NotExistRequiredException('Parameters is invalid.');
25
        }
26
27 3
        parent::__construct($cybozuConfig->toGuzzleConfig());
28
    }
29
30
    /**
31
     * @param string $prefix
32
     * @throws RedirectResponseException
33
     * @throws \GuzzleHttp\Exception\GuzzleException
34
     * @deprecated Due to changes in kintone specifications, this function is not working.
35
     */
36
    public function connectionTest($prefix = '/'): void
37
    {
38
        $response = $this->request('GET', $prefix, ['allow_redirects' => false]);
39
        if ($response->getStatusCode() === 302) {
40
            throw new RedirectResponseException('', $response);
41
        }
42
    }
43
}
44