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

ReportForm::getSecretKey()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 6
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 1
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 ReportForm implements Common
14
{
15
    private $client;
16
17
    /**
18
     * Security constructor.
19
     *
20
     * @param  Client $client
21
     * @throws Exception
22
     */
23
    public function __construct(Client $client)
24
    {
25
        if (!$client) {
26
            throw new Exception('Client not defined');
27
        }
28
29
        $this->client = $client;
30
    }
31
32
    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
        if (is_string($date) && strlen($date) >= 8) {
35
            $date = substr($date, 0, 8);
36
37
            if (!empty($_SESSION[$date])) {
38
                return $_SESSION[$date];
39
            }
40
        }
41
42
        return $_SESSION[$date] = $this->client->getResponse($this->getUrl(__FUNCTION__), ['date' => $date])['data'];
43
    }
44
45
    public function getUrl($method, array $params = [])
46
    {
47
        switch ($method) {
48
            case 'getBibFond':
49
                return [
50
                    'url' => '/1.0/report/form/bibFond',
51
                    'method' => 'GET',
52
                    'code' => 200
53
                ];
54
            case 'getEBooks':
55
                return [
56
                    'url' => '/1.0/report/form/eBooks',
57
                    'method' => 'GET',
58
                    'code' => 200
59
                ];
60
            case 'getSpecPo':
61
                return [
62
                    'url' => '/1.0/report/form/specPo',
63
                    'method' => 'GET',
64
                    'code' => 200
65
                ];
66
            default:
67
                throw new Exception('Route for ' . $method . ' not found');
68
        }
69
    }
70
71
    public function getBibFond()
72
    {
73
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
74
    }
75
76
    public function getEBooks()
77
    {
78
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
79
    }
80
81
    public function getSpecPo()
82
    {
83
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
84
    }
85
}