Completed
Push — master ( a79db0...dcb4db )
by Denis
03:08
created

Security   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 65%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 57
ccs 13
cts 20
cp 0.65
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getSecretKey() 0 12 4
A getUrl() 0 19 3
A getDemoUrl() 0 4 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 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
            default:
61
                throw new Exception('Route for ' . $method . ' not found');
62
        }
63
    }
64
65
    public function getDemoUrl($type, $id)
66
    {
67
        $this->client->getResponse($this->getUrl(__FUNCTION__), ['type' => $type, 'id' => $id])['data'];
68
    }
69
}