Completed
Branch proxy (ca01d6)
by leo
03:49
created

PGTCaller::call()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 3
nop 3
dl 0
loc 16
ccs 9
cts 9
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: leo108
5
 * Date: 2016/10/26
6
 * Time: 11:01
7
 */
8
9
namespace Leo108\CAS\Services;
10
11
use GuzzleHttp\Client;
12
13
class PGTCaller
14
{
15
    /**
16
     * @var Client
17
     */
18
    protected $client;
19
20
    /**
21
     * PGTCaller constructor.
22
     * @param Client $client
23
     */
24 18
    public function __construct(Client $client)
25
    {
26 18
        $this->client = $client;
27 18
    }
28
29
    /**
30
     * @param string $pgtUrl
31
     * @param string $pgt
32
     * @param string $pgtiou
33
     * @return bool
34
     */
35 1
    public function call($pgtUrl, $pgt, $pgtiou)
36
    {
37
        $query = [
38 1
            'pgtId'  => $pgt,
39 1
            'pgtIou' => $pgtiou,
40 1
        ];
41 1
        parse_str(parse_url($pgtUrl, PHP_URL_QUERY), $originQuery);
42
43
        try {
44 1
            $res = $this->client->get($pgtUrl, ['query' => array_merge($originQuery, $query)]);
45
46 1
            return $res->getStatusCode() == 200;
47 1
        } catch (\Exception $e) {
48 1
            return false;
49
        }
50
    }
51
}
52