Completed
Push — master ( f22d83...d711c3 )
by Denis
02:01
created

User::getUrl()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 32
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 5.0729

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 18
cts 21
cp 0.8571
rs 8.439
c 0
b 0
f 0
cc 5
eloc 25
nc 5
nop 2
crap 5.0729
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dp
5
 * Date: 26.07.17
6
 * Time: 11:57
7
 */
8
9
namespace Lan\Ebs\Sdk\Model;
10
11
use Exception;
12
use Lan\Ebs\Sdk\Classes\Model;
13
use Lan\Ebs\Sdk\Client;
14
15
/**
16
 * @property mixed login
17
 * @property mixed email
18
 * @property mixed fio
19
 * @property mixed registered_at
20
 */
21
class User extends Model
22
{
23
    const FIELD_LOGIN = 'login';
24
    const FIELD_EMAIL = 'email';
25
    const FIELD_FIO = 'fio';
26
    const FIELD_REGISTERED = 'registered_at';
27
28
    public static $defaultFields = [
29
        User::FIELD_LOGIN,
30
        User::FIELD_EMAIL,
31
        User::FIELD_FIO,
32
        User::FIELD_REGISTERED
33
    ];
34
35
    /**
36
     * User constructor.
37
     * @param Client $client
38
     * @param array $fields
39
     * @throws Exception
40
     */
41 7
    public function __construct(Client $client, array $fields = [])
42
    {
43 7
        parent::__construct($client, $fields);
44 7
    }
45
46 4
    public function getUrl($method, array $params = [])
47
    {
48
        switch ($method) {
49 4
            case 'get':
50
                return [
51 2
                    'url' => vsprintf('/1.0/security/user/get/%d', $params),
52 2
                    'method' => 'GET',
53
                    'code' => 200
54 2
                ];
55 3
            case 'post':
56
                return [
57 1
                    'url' => '/1.0/security/user/post',
58 1
                    'params' => [],
59 1
                    'method' => 'POST',
60
                    'code' => 201
61 1
                ];
62 2
            case 'put':
63
                return [
64 1
                    'url' => vsprintf('/1.0/security/user/put/%d', $params),
65 1
                    'method' => 'PUT',
66
                    'code' => 200
67 1
                ];
68 1
            case 'delete':
69
                return [
70 1
                    'url' => vsprintf('/1.0/security/user/delete/%d', $params),
71 1
                    'method' => 'DELETE',
72
                    'code' => 200
73 1
                ];
74
            default:
75
                throw new Exception('Route for ' . $method . ' not found');
76
        }
77
    }
78
}