Completed
Push — 0.1 ( 1296ef...144915 )
by Yuichi
19:51 queued 09:46
created

Client::changeAuthOptions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 12
cts 12
cp 1
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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
    public function __construct(array $config = [])
21
    {
22
        $cybozuConfig = new Config($config);
23
        if (!$cybozuConfig->hasRequired()) {
24
            throw new NotExistRequiredException('Parameters is invalid.');
25
        }
26 8
27
        parent::__construct($cybozuConfig->toGuzzleConfig());
28 8
    }
29 8
30 1
    /**
31
     * @param string $prefix
32
     * @throws RedirectResponseException
33 8
     * @throws \GuzzleHttp\Exception\GuzzleException
34
     */
35 8
    public function connectionTest($prefix = '/'): void
36
    {
37 8
        $response = $this->request('GET', $prefix, ['allow_redirects' => false]);
38 8
        if ($response->getStatusCode() === 302) {
39 8
            throw new RedirectResponseException('', $response);
40
        }
41
    }
42
}
43