Completed
Push — master ( 257c81...98d67f )
by Denis
06:10
created

Security::getUrl()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 8
cp 0
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 19
nc 4
nop 2
crap 20
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dp
5
 * Date: 16.08.17
6
 * Time: 13:09
7
 */
8
9
namespace Lan\Ebs\Sdk;
10
11
use Exception;
12
13
final class Security implements Common
14
{
15
    private $client;
16
17
    /**
18
     * Security constructor.
19
     *
20
     * @param  Client $client
21
     * @throws Exception
22
     */
23 1
    public function __construct(Client $client)
24
    {
25 1
        if (!$client) {
26
            throw new Exception('Client not defined');
27
        }
28
29 1
        $this->client = $client;
30 1
    }
31
32
    public function getUrl($method, array $params = [])
33
    {
34
        switch ($method) {
35
            case 'getSecretKey':
36
                return [
37
                    'url' => '/1.0/security/secretKey',
38
                    'method' => 'GET',
39
                    'code' => 200
40
                ];
41
            case 'getDemoUrl':
42
                return [
43
                    'url' => '/1.0/security/demoUrl',
44
                    'method' => 'GET',
45
                    'code' => 200
46
                ];
47
            case 'getAutologinUrl':
48
                return [
49
                    'url' => '/1.0/security/autologinUrl',
50
                    'method' => 'GET',
51
                    'code' => 200
52
                ];
53
            default:
54
                throw new Exception('Route for ' . $method . ' not found');
55
        }
56
    }
57
58
    public function getDemoUrl($type, $id)
59
    {
60
        return $this->client->getResponse($this->getUrl(__FUNCTION__), ['type' => $type, 'id' => $id])['data'];
61
    }
62
63
    public function getAutologinUrl($uid, $time, $fio = null, $email = null, $redirect = null) {
64
        return $this->client->getResponse(
65
            $this->getUrl(__FUNCTION__),
66
            [
67
                'uid' => $uid,
68
                'time' => $time,
69
                'fio' => $fio,
70
                'email' => $email,
71
                'redirect' => $redirect
72
            ]
73
        )['data'];
74
    }
75
}