Code Duplication    Length = 44-51 lines in 3 locations

src/Users/Fee.php 1 location

@@ 12-60 (lines=49) @@
9
/**
10
 * A single Fee resource.
11
 */
12
class Fee extends LazyResource
13
{
14
    /* @var User */
15
    protected $user;
16
17
    /* @var string */
18
    protected $id;
19
20
    public function __construct(Client $client, User $user, $id)
21
    {
22
        parent::__construct($client);
23
        $this->user = $user;
24
        $this->id = $id;
25
    }
26
27
    /**
28
     * Generate the base URL for this resource.
29
     *
30
     * @return string
31
     */
32
    protected function urlBase()
33
    {
34
        return "/users/{$this->user->id}/fees/{$this->id}";
35
    }
36
37
    /**
38
     * Check if we have the full representation of our data object.
39
     *
40
     * @param \stdClass $data
41
     *
42
     * @return bool
43
     */
44
    protected function isInitialized($data)
45
    {
46
        return isset($data->link);
47
    }
48
49
    /**
50
     * Get the related Item, if any.
51
     *
52
     * @return Item|null
53
     */
54
    public function getItem()
55
    {
56
        if (isset($this->barcode)) {
57
            return $this->client->items->fromBarcode($this->barcode);
58
        }
59
    }
60
}
61

src/Users/Loan.php 1 location

@@ 12-62 (lines=51) @@
9
/**
10
 * A single Loan resource.
11
 */
12
class Loan extends LazyResource
13
{
14
    /* @var User */
15
    protected $user;
16
17
    /* @var string */
18
    protected $loan_id;
19
20
    public function __construct(Client $client, User $user, $loan_id)
21
    {
22
        parent::__construct($client);
23
        $this->user = $user;
24
        $this->loan_id = $loan_id;
25
    }
26
27
    /**
28
     * Generate the base URL for this resource.
29
     *
30
     * @return string
31
     */
32
    protected function urlBase()
33
    {
34
        return "/users/{$this->user->id}/loans/{$this->loan_id}";
35
    }
36
37
    /**
38
     * Check if we have the full representation of our data object.
39
     *
40
     * @param \stdClass $data
41
     *
42
     * @return bool
43
     */
44
    protected function isInitialized($data)
45
    {
46
        return isset($data->loan_id);
47
    }
48
49
    /**
50
     * Get the Item on loan. Since the response from the loan(s) API does not
51
     * include the `holding_id` and `item_pid`, we cannot initiate an Item object
52
     * directly, so we have to lookup the barcode instead.
53
     *
54
     * @see https://developers.exlibrisgroup.com/discussions#!/forum/posts/list/1397.page
55
     *
56
     * @return Item
57
     */
58
    public function getItem()
59
    {
60
        return $this->client->items->fromBarcode($this->item_barcode);
61
    }
62
}
63

src/Bibs/Portfolio.php 1 location

@@ 13-56 (lines=44) @@
10
/**
11
 * A single Portfolio resource.
12
 */
13
class Portfolio extends LazyResource
14
{
15
    /* @var string */
16
    public $portfolio_id;
17
18
    /* @var Bib */
19
    public $bib;
20
21
    public function __construct(Client $client, Bib $bib, $portfolio_id)
22
    {
23
        parent::__construct($client);
24
        $this->bib = $bib;
25
        $this->portfolio_id = $portfolio_id;
26
    }
27
28
    /**
29
     * Generate the base URL for this resource.
30
     *
31
     * @return string
32
     */
33
    protected function urlBase()
34
    {
35
        return "/bibs/{$this->bib->mms_id}/portfolios/{$this->portfolio_id}";
36
    }
37
38
    /**
39
     * Check if we have the full representation of our data object.
40
     *
41
     * @param \stdClass $data
42
     *
43
     * @return bool
44
     */
45
    protected function isInitialized($data)
46
    {
47
        return isset($data->linking_details);
48
    }
49
50
    public function getElectronicCollection()
51
    {
52
        $this->init();
53
54
        return new Collection($this->client, $this->data->electronic_collection->id->value);
55
    }
56
}
57