Requests   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 42
loc 42
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A convertToResource() 5 5 1
A urlBase() 4 4 1

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
namespace Scriptotek\Alma\Users;
4
5
use Scriptotek\Alma\Client;
6
use Scriptotek\Alma\Model\IterableCollection;
7
use Scriptotek\Alma\Model\LazyResourceList;
8
use Scriptotek\Alma\Model\ReadOnlyArrayAccess;
9
10
/**
11
 * Iterable collection of Request resources.
12
 */
13 View Code Duplication
class Requests extends LazyResourceList implements \Countable, \Iterator, \ArrayAccess
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...
14
{
15
    use ReadOnlyArrayAccess;
16
    use IterableCollection;
17
18
    protected $_urlBase;
19
20
    /**
21
     * Requests constructor.
22
     *
23
     * @param Client $client
24
     * @param string $url
25
     */
26
    public function __construct(Client $client, $url)
27
    {
28
        parent::__construct($client, 'user_request');
29
        $this->_urlBase = $url;
30
    }
31
32
    /**
33
     * Convert a data element to a resource object.
34
     *
35
     * @param $data
36
     *
37
     * @return Request
38
     */
39
    protected function convertToResource($data)
40
    {
41
        return Request::make($this->client, User::make($this->client, $data->user_primary_id), $data->request_id)
42
            ->init($data);
43
    }
44
45
    /**
46
     * Generate the base URL for this resource.
47
     *
48
     * @return string
49
     */
50
    protected function urlBase()
51
    {
52
        return $this->_urlBase;
53
    }
54
}
55