Completed
Push — master ( 93e656...cbee39 )
by Denis
03:12
created

BookCollection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 50 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 21
loc 42
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getUrl() 0 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Class BookCollection
4
 *
5
 * @author       Denis Shestakov <[email protected]>
6
 * @copyright    Copyright (c) 2017, Lan Publishing
7
 * @license      MIT
8
 */
9
10
namespace Lan\Ebs\Sdk\Collection;
11
12
use Exception;
13
use Lan\Ebs\Sdk\Classes\Collection;
14
use Lan\Ebs\Sdk\Client;
15
use Lan\Ebs\Sdk\Model\Book;
16
17
/**
18
 * Коллекция книг
19
 *
20
 * @package      Lan\Ebs
21
 * @subpackage   Sdk
22
 * @category     Collection
23
 */
24 View Code Duplication
class BookCollection extends Collection
0 ignored issues
show
Duplication introduced by
This class 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...
25
{
26
    /**
27
     * Конструктор коллекции книг
28
     *
29
     * @param Client $client Инстанс клиента
30
     * @param array $fields Поля для выборки
31
     * @param int $limit Лимит выборки моделей книг
32
     * @param int $offset Смещение выборки моделей книг
33
     *
34
     * @throws Exception
35
     */
36 2
    public function __construct(Client $client, array $fields = [], $limit = 10, $offset = 0)
37
    {
38 2
        parent::__construct($client, $fields, Book::class, $limit, $offset);
39 2
    }
40
41
    /**
42
     * /**
43
     * Получение данных для запроса через API
44
     *
45
     * @param string $method Http-метод запроса
46
     * @param array $params Параметры для формирования урла
47
     *
48
     * @return array
49
     *
50
     * @throws Exception
51
     */
52 2
    public function getUrl($method, array $params = [])
53
    {
54
        switch ($method) {
55 2
            case 'load':
56
                return [
57 2
                    'url' => '/1.0/resource/book',
58
                    'method' => 'GET',
59
                    'code' => '200'
60
                ];
61
            default:
62
                throw new Exception('Route for ' . $method . ' not found');
63
        }
64
    }
65
}