Completed
Push — master ( 47778c...ba169d )
by Dan Michael O.
10:36
created

Loans::urlBase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
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\SimplePagedLazyResourceList;
7
8
/**
9
 * Iterable collection of Loan resources belonging to some User.
10
 */
11
class Loans extends SimplePagedLazyResourceList implements \Countable, \Iterator
12
{
13
    /* @var User */
14
    public $user;
15
16
    public function __construct(Client $client, User $user)
17
    {
18
        parent::__construct($client);
19
        $this->user = $user;
20
    }
21
22
    /**
23
     * Get resource.
24
     *
25
     * @param string $loan_id
26
     * @return Loan
27
     */
28
    public function get($loan_id)
29
    {
30
        return Loan::make($this->client, $this->user, $loan_id);
31
    }
32
33
    /**
34
     * Convert a retrieved resource object to a model object.
35
     *
36
     * @param $data
37
     * @return Loan
38
     */
39
    public function convertToResource($data)
40
    {
41
        return $this->get($data->loan_id)->init($data);
42
    }
43
44
    /**
45
     * Generate the base URL for this resource.
46
     *
47
     * @return string
48
     */
49
    protected function urlBase()
50
    {
51
        return "/users/{$this->user->id}/loans";
52
    }
53
}
54