Completed
Push — master ( ce9410...27e308 )
by Denis
06:09
created

Security   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 12.5%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 63
ccs 4
cts 32
cp 0.125
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getDemoUrl() 0 4 1
B getUrl() 0 25 4
A getAutologinUrl() 0 12 1
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, $fio = null, $email = null, $redirect = null) {
64
        return $this->client->getResponse(
65
            $this->getUrl(__FUNCTION__),
66
            [
67
                'uid' => $uid,
68
                'time' => date('YmdHi'),
69
                'fio' => $fio,
70
                'email' => $email,
71
                'redirect' => $redirect
72
            ]
73
        )['data'];
74
    }
75
}