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

Holdings   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 57
loc 57
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\Bibs;
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 Holdings extends CountableGhostModelList 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...
11
{
12
    use ArrayAccessResource;
13
    use IterableResource;
14
15
    /* @var Bib */
16
    public $bib;
17
18
    public function __construct(Client $client, Bib $bib)
19
    {
20
        parent::__construct($client);
21
        $this->bib = $bib;
22
    }
23
24
    /**
25
     * Get resource.
26
     *
27
     * @param string $holding_id
28
     * @return Holding
29
     */
30
    public function get($holding_id)
31
    {
32
        return Holding::make($this->client, $this->bib, $holding_id);
33
    }
34
35
    public function setData(\stdClass $data)
36
    {
37
        $this->resources = array_map(
38
            function (\stdClass $holding) {
39
                return Holding::make($this->client, $this->bib, $holding->holding_id)
40
                    ->init($holding);
41
            },
42
            $data->holding
43
        );
44
    }
45
46
    /**
47
     * Check if we have the full representation of our data object.
48
     *
49
     * @param \stdClass $data
50
     * @return boolean
51
     */
52
    protected function isInitialized($data)
53
    {
54
        return $data->total_record_count;
55
    }
56
57
    /**
58
     * Generate the base URL for this resource.
59
     *
60
     * @return string
61
     */
62
    protected function urlBase()
63
    {
64
        return "/bibs/{$this->bib->mms_id}/holdings";
65
    }
66
}
67