Completed
Push — master ( 9d90d4...cee823 )
by Dan Michael O.
03:06
created

Locations::setData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Scriptotek\Alma\Conf;
4
5
use Scriptotek\Alma\Model\ReadOnlyArrayAccess;
6
use Scriptotek\Alma\Client;
7
use Scriptotek\Alma\Model\LazyResourceList;
8
use Scriptotek\Alma\Model\IterableCollection;
9
10
/**
11
 * Iterable collection of Location resources.
12
 */
13 View Code Duplication
class Locations extends LazyResourceList implements \ArrayAccess, \Countable, \Iterator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    use ReadOnlyArrayAccess;
16
    use IterableCollection;
17
18
    /**
19
     * The Library this Locations list belongs to.
20
     *
21
     * @var Library
22
     */
23
    protected $library;
24
25
    /**
26
     * Locations constructor.
27
     *
28
     * @param Client $client
29
     * @param Library $library
30
     */
31
    public function __construct(Client $client, Library $library)
32
    {
33
        parent::__construct($client, 'location');
34
        $this->library = $library;
35
    }
36
37
    /**
38
     * Get a single location by its location code.
39
     *
40
     * @param string $code
41
     * @return Location
42
     */
43
    public function get($code)
44
    {
45
        return Location::make($this->client, $this->library, $code);
46
    }
47
48
    /**
49
     * Convert a data element to a resource object.
50
     *
51
     * @param $data
52
     * @return Location
53
     */
54
    protected function convertToResource($data)
55
    {
56
        return Location::make($this->client, $this->library, $data->code)
57
            ->init($data);
58
    }
59
60
    /**
61
     * Generate the base URL for this resource.
62
     *
63
     * @return string
64
     */
65
    protected function urlBase()
66
    {
67
        return "/conf/libraries/{$this->library->code}/locations";
68
    }
69
}
70