Holdings   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
dl 59
loc 59
rs 10
c 0
b 0
f 0
wmc 4
lcom 2
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A get() 4 4 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\Bibs;
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 Holding resources belonging to some Bib resource.
12
 */
13 View Code Duplication
class Holdings 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
    /**
19
     * The Bib this Holdings list belongs to.
20
     *
21
     * @var Bib
22
     */
23
    public $bib;
24
25
    /**
26
     * Holdings constructor.
27
     *
28
     * @param Client $client
29
     * @param Bib    $bib
30
     */
31
    public function __construct(Client $client, Bib $bib)
32
    {
33
        parent::__construct($client, 'holding');
34
        $this->bib = $bib;
35
    }
36
37
    /**
38
     * Get a single holding record by id.
39
     *
40
     * @param string $holding_id
41
     *
42
     * @return Holding
43
     */
44
    public function get($holding_id)
45
    {
46
        return Holding::make($this->client, $this->bib, $holding_id);
47
    }
48
49
    /**
50
     * Convert a data element to a resource object.
51
     *
52
     * @param $data
53
     *
54
     * @return Holding
55
     */
56
    protected function convertToResource($data)
57
    {
58
        return Holding::make($this->client, $this->bib, $data->holding_id)
59
            ->init($data);
60
    }
61
62
    /**
63
     * Generate the base URL for this resource.
64
     *
65
     * @return string
66
     */
67
    protected function urlBase()
68
    {
69
        return "/bibs/{$this->bib->mms_id}/holdings";
70
    }
71
}
72