Completed
Push — master ( a9f057...061833 )
by Denis
02:47
created

Security::getDemoUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
crap 2
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
            default:
55
                throw new Exception('Route for ' . $method . ' not found');
56
        }
57
    }
58
59
    public function getDemoUrl($type, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    {
61
62
    }
63
}