Completed
Push — master ( 5ba59a...5157fd )
by Denis
02:04
created

Article::text()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 4
nop 1
crap 12
1
<?php
2
3
namespace Lan\Ebs\Sdk\Model;
4
5
use Exception;
6
use Lan\Ebs\Sdk\Classes\Model;
7
use Lan\Ebs\Sdk\Client;
8
9
/**
10
 * @property mixed name
11
 * @property mixed description
12
 * @property mixed issn
13
 * @property mixed eissn
14
 * @property mixed vac
15
 * @property mixed year
16
 * @property mixed issuesPerYear
17
 * @property mixed editors
18
 * @property mixed publisher
19
 * @property mixed url
20
 */
21
class Article extends Model
22
{
23
    /**
24
     * Наименование статьи
25
     */
26
    const FIELD_NAME = 'name';
27
28
    /**
29
     * Авторы статьи
30
     */
31
    const FIELD_AUTHORS = 'authors';
32
33
    /**
34
     * Аннотация статьи
35
     */
36
    const FIELD_DESCRIPTION = 'description';
37
38
    /**
39
     * Ключевые слова статьи
40
     */
41
    const FIELD_KEYWORDS = 'keywords';
42
43
    /**
44
     * Страница начала статьи
45
     */
46
    const START_PAGE = 'startPage';
47
48
    /**
49
     * Страница окончания статьи
50
     */
51
    const FINISH_PAGE = 'finish_page';
52
53
    /**
54
     * Библиографическая запись
55
     */
56
    const FIELD_BIBLIOGRAPHIC_RECORD = 'bibliographicRecord';
57
58
59
    /**
60
     * Конструктор модели пользователя
61
     *
62
     * @param Client $client Инстанс клиента
63
     * @param array $fields Поля для выборки
64
     *
65
     * @throws Exception
66
     */
67
    public function __construct(Client $client, array $fields = [])
68
    {
69
        parent::__construct($client, $fields);
70
    }
71
72
    /**
73
     * Получение данных для запроса через API
74
     *
75
     * @param string $method Http-метод запроса
76
     * @param array $params Параметры для формирования урла
77
     *
78
     * @return array
79
     *
80
     * @throws Exception
81
     */
82 View Code Duplication
    public function getUrl($method, array $params = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
    {
84
        switch ($method) {
85
            case 'get':
86
                return [
87
                    'url' => vsprintf('/1.0/resource/journal/article/get/%d', $params),
88
                    'method' => 'GET',
89
                    'code' => 200
90
                ];
91
            case 'text':
92
                return [
93
                    'url' => vsprintf('/1.0/resource/journal/article/text/%d', $params),
94
                    'method' => 'GET',
95
                    'code' => 200
96
                ];
97
            default:
98
                throw new Exception('Route for ' . $method . ' not found');
99
        }
100
    }
101
102
    /**
103
     * Получение текстов статьи
104
     *
105
     * @param int $id Идентификатор модели
106
     *
107
     * @return array
108
     *
109
     * @throws Exception
110
     */
111 View Code Duplication
    public function text($id = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113
        if ($id) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $id of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
114
            $this->setId($id);
115
        } else {
116
            $id = $this->getId();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $id is correct as $this->getId() (which targets Lan\Ebs\Sdk\Classes\Model::getId()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
117
        }
118
119
        if (empty($id)) {
120
            throw new Exception(Model::MESSAGE_ID_REQUIRED);
121
        }
122
123
        return $this->getClient()->getResponse($this->getUrl(__FUNCTION__, [$id]))['data'];
124
    }
125
}