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

Portfolios::convertToResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 5
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Scriptotek\Alma\Bibs;
4
5
use Scriptotek\Alma\Bibs\Bib;
6
use Scriptotek\Alma\Client;
7
use Scriptotek\Alma\Bibs\Portfolio;
8
use Scriptotek\Alma\Model\IterableCollection;
9
use Scriptotek\Alma\Model\LazyResourceList;
10
use Scriptotek\Alma\Model\ReadOnlyArrayAccess;
11
12 View Code Duplication
class Portfolios 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...
13
{
14
    use ReadOnlyArrayAccess;
15
    use IterableCollection;
16
17
    /**
18
     * The Bib this Portfolios list belongs to.
19
     *
20
     * @var Bib
21
     */
22
    public $bib;
23
24
    /**
25
     * Portfolios constructor.
26
     *
27
     * @param Client $client
28
     * @param Bib    $bib
29
     */
30
    public function __construct(Client $client, Bib $bib)
31
    {
32
        parent::__construct($client, 'portfolio');
33
        $this->bib = $bib;
34
    }
35
36
    /**
37
     * Get a single portfolio record by id.
38
     *
39
     * @param string $id
40
     *
41
     * @return Portfolio
42
     */
43
    public function get($id)
44
    {
45
        return Portfolio::make($this->client, $this->bib, $id);
46
    }
47
48
    /**
49
     * Convert a data element to a resource object.
50
     *
51
     * @param $data
52
     *
53
     * @return Portfolio
54
     */
55
    protected function convertToResource($data)
56
    {
57
        return Portfolio::make($this->client, $this->bib, $data->id)
58
            ->init($data);
59
    }
60
61
    /**
62
     * Generate the base URL for this resource.
63
     *
64
     * @return string
65
     */
66
    protected function urlBase()
67
    {
68
        return "/bibs/{$this->bib->mms_id}/portfolios";
69
    }
70
}
71