Test Failed
Push — master ( c6b6d3...528954 )
by Dan Michael O.
03:21
created

Locations   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A get() 4 4 1
A setData() 10 10 1
A isInitialized() 4 4 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\Conf;
4
5
use Scriptotek\Alma\ArrayAccessResource;
6
use Scriptotek\Alma\Client;
7
use Scriptotek\Alma\CountableGhostModelList;
8
use Scriptotek\Alma\IterableResource;
9
10 View Code Duplication
class Locations extends CountableGhostModelList implements \ArrayAccess, \Countable, \Iterator
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...
11
{
12
    use ArrayAccessResource;
13
    use IterableResource;
14
15
    /** @var Library */
16
    protected $library;
17
18
    /**
19
     * Locations constructor.
20
     *
21
     * @param Client $client
22
     * @param Library $library
23
     */
24
    public function __construct(Client $client, Library $library)
25
    {
26
        parent::__construct($client);
27
        $this->library = $library;
28
    }
29
30
    /**
31
     * Get resource.
32
     *
33
     * @param string $code
34
     * @return Location
35
     */
36
    public function get($code)
37
    {
38
        return Location::make($this->client, $this->library, $code);
39
    }
40
41
    protected function setData(\stdClass $data)
42
    {
43
        $this->resources = array_map(
44
            function (\stdClass $location) {
45
                return Location::make($this->client, $this->library, $location->code)
46
                    ->init($location);
47
            },
48
            $data->location
49
        );
50
    }
51
52
    /**
53
     * Check if we have the full representation of our data object.
54
     *
55
     * @param \stdClass $data
56
     * @return boolean
57
     */
58
    protected function isInitialized($data)
59
    {
60
        return isset($data->location);
61
    }
62
63
    /**
64
     * Generate the base URL for this resource.
65
     *
66
     * @return string
67
     */
68
    protected function urlBase()
69
    {
70
        return "/conf/libraries/{$this->library->code}/locations";
71
    }
72
}
73