Completed
Branch proxy (a8ed88)
by leo
08:29
created

PGTCaller   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 23.08%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 3
cts 13
cp 0.2308
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A call() 0 18 2
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 15
    public function __construct(Client $client)
25
    {
26 15
        $this->client = $client;
27 15
    }
28
29
    public function call($pgtUrl, $pgt, $pgtiou)
30
    {
31
        $query = http_build_query(
32
            [
33
                'pgtId'  => $pgt,
34
                'pgtIou' => $pgtiou,
35
            ]
36
        );
37
        parse_str(parse_url($pgtUrl, PHP_URL_QUERY), $originQuery);
38
39
        try {
40
            $res = $this->client->get($pgtUrl, ['query' => array_merge($originQuery, $query)]);
41
42
            return $res->getStatusCode() == 200;
43
        } catch (\Exception $e) {
44
            return false;
45
        }
46
    }
47
}
48