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

PGTCaller   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 12
cts 12
cp 1
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 16 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 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