Loans   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 4
lcom 2
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\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