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

User   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 58
ccs 21
cts 24
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B getUrl() 0 32 5
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
}