Completed
Push — master ( 1392b0...257c81 )
by Denis
01:57
created

Security   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 43.33%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 76
ccs 13
cts 30
cp 0.4333
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getSecretKey() 0 12 4
B getUrl() 0 25 4
A getDemoUrl() 0 4 1
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 2
    public function __construct(Client $client)
24
    {
25 2
        if (!$client) {
26
            throw new Exception('Client not defined');
27
        }
28
29 2
        $this->client = $client;
30 2
    }
31
32 1
    public function getSecretKey($date)
0 ignored issues
show
Coding Style introduced by
getSecretKey uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
33
    {
34 1
        if (is_string($date) && strlen($date) >= 8) {
35 1
            $date = substr($date, 0, 8);
36
37 1
            if (!empty($_SESSION[$date])) {
38 1
                return $_SESSION[$date];
39
            }
40
        }
41
42 1
        return $_SESSION[$date] = $this->client->getResponse($this->getUrl(__FUNCTION__), ['date' => $date])['data'];
43
    }
44
45 1
    public function getUrl($method, array $params = [])
46
    {
47
        switch ($method) {
48 1
            case 'getSecretKey':
49
                return [
50 1
                    'url' => '/1.0/security/secretKey',
51
                    'method' => 'GET',
52
                    'code' => 200
53
                ];
54
            case 'getDemoUrl':
55
                return [
56
                    'url' => '/1.0/security/demoUrl',
57
                    'method' => 'GET',
58
                    'code' => 200
59
                ];
60
            case 'getAutologinUrl':
61
                return [
62
                    'url' => '/1.0/security/autologinUrl',
63
                    'method' => 'GET',
64
                    'code' => 200
65
                ];
66
            default:
67
                throw new Exception('Route for ' . $method . ' not found');
68
        }
69
    }
70
71
    public function getDemoUrl($type, $id)
72
    {
73
        return $this->client->getResponse($this->getUrl(__FUNCTION__), ['type' => $type, 'id' => $id])['data'];
74
    }
75
76
    public function getAutologinUrl($uid, $time, $fio = null, $email = null, $redirect = null) {
77
        return $this->client->getResponse(
78
            $this->getUrl(__FUNCTION__),
79
            [
80
                'uid' => $uid,
81
                'time' => $time,
82
                'fio' => $fio,
83
                'email' => $email,
84
                'redirect' => $redirect
85
            ]
86
        )['data'];
87
    }
88
}