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

Loans   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 4 1
A convertToResource() 0 4 1
A urlBase() 0 4 1
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