Loans::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Scriptotek\Alma\Users;
4
5
use Scriptotek\Alma\Client;
6
use Scriptotek\Alma\Model\SimplePaginatedList;
7
8
/**
9
 * Iterable collection of Loan resources belonging to some User.
10
 */
11
class Loans extends SimplePaginatedList implements \Countable, \Iterator
12
{
13
    /* @var User */
14
    public $user;
15
16
    public function __construct(Client $client, User $user)
17
    {
18
        parent::__construct($client, 'item_loan');
19
        $this->user = $user;
20
    }
21
22
    /**
23
     * Get resource.
24
     *
25
     * @param string $loan_id
26
     *
27
     * @return Loan
28
     */
29
    public function get($loan_id)
30
    {
31
        return Loan::make($this->client, $this->user, $loan_id);
32
    }
33
34
    /**
35
     * Convert a retrieved resource object to a model object.
36
     *
37
     * @param $data
38
     *
39
     * @return Loan
40
     */
41
    public function convertToResource($data)
42
    {
43
        return $this->get($data->loan_id)->init($data);
44
    }
45
46
    /**
47
     * Generate the base URL for this resource.
48
     *
49
     * @return string
50
     */
51
    protected function urlBase()
52
    {
53
        return sprintf('/users/%s/loans', $this->user->id);
54
    }
55
}
56