Completed
Push — master ( 804c7f...1d2ba7 )
by Dan Michael O.
01:59
created

Portfolio   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A urlBase() 4 4 1
A isInitialized() 4 4 1
A getElectronicCollection() 6 6 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\Bibs\Bib;
6
use Scriptotek\Alma\Client;
7
use Scriptotek\Alma\Electronic\Collection;
8
use Scriptotek\Alma\Model\LazyResource;
9
10
/**
11
 * A single Portfolio resource.
12
 */
13 View Code Duplication
class Portfolio extends LazyResource
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
    /* @var string */
16
    public $portfolio_id;
17
18
    /* @var Bib */
19
    public $bib;
20
21
    public function __construct(Client $client, Bib $bib, $portfolio_id)
22
    {
23
        parent::__construct($client);
24
        $this->bib = $bib;
25
        $this->portfolio_id = $portfolio_id;
26
    }
27
28
    /**
29
     * Generate the base URL for this resource.
30
     *
31
     * @return string
32
     */
33
    protected function urlBase()
34
    {
35
        return "/bibs/{$this->bib->mms_id}/portfolios/{$this->portfolio_id}";
36
    }
37
38
    /**
39
     * Check if we have the full representation of our data object.
40
     *
41
     * @param \stdClass $data
42
     *
43
     * @return bool
44
     */
45
    protected function isInitialized($data)
46
    {
47
        return isset($data->linking_details);
48
    }
49
50
    public function getElectronicCollection()
51
    {
52
        $this->init();
53
54
        return new Collection($this->client, $this->data->electronic_collection->id->value);
55
    }
56
}
57