Code Duplication    Length = 36-45 lines in 2 locations

src/Conf/Library.php 1 location

@@ 8-52 (lines=45) @@
5
use Scriptotek\Alma\Client;
6
use Scriptotek\Alma\GhostModel;
7
8
class Library extends GhostModel
9
{
10
    /** @var string */
11
    public $code;
12
13
    /** @var Locations */
14
    public $locations;
15
16
    /**
17
     * Library constructor.
18
     *
19
     * @param Client $client
20
     * @param string $code
21
     */
22
    public function __construct(Client $client, $code)
23
    {
24
        parent::__construct($client);
25
        $this->code = $code;
26
        $this->locations = Locations::make($this->client, $this);
27
    }
28
29
    /**
30
     * Check if we have the full representation of our data object.
31
     * For libraries, it seems like we get the same data in the list
32
     * response as in the single-item response, so we just check some
33
     * random element.
34
     *
35
     * @param \stdClass $data
36
     * @return boolean
37
     */
38
    protected function isInitialized($data)
39
    {
40
        return isset($data->path);
41
    }
42
43
    /**
44
     * Generate the base URL for this resource.
45
     *
46
     * @return string
47
     */
48
    protected function urlBase()
49
    {
50
        return "/conf/libraries/{$this->code}";
51
    }
52
}
53

src/Conf/Location.php 1 location

@@ 8-43 (lines=36) @@
5
use Scriptotek\Alma\Client;
6
use Scriptotek\Alma\GhostModel;
7
8
class Location extends GhostModel
9
{
10
    /** @var Library */
11
    public $library;
12
13
    /** @var string */
14
    public $code;
15
16
    public function __construct(Client $client, Library $library, $code)
17
    {
18
        parent::__construct($client);
19
        $this->library = $library;
20
        $this->code = $code;
21
    }
22
23
    /**
24
     * Check if we have the full representation of our data object.
25
     *
26
     * @param \stdClass $data
27
     * @return boolean
28
     */
29
    protected function isInitialized($data)
30
    {
31
        return isset($data->location);
32
    }
33
34
    /**
35
     * Generate the base URL for this resource.
36
     *
37
     * @return string
38
     */
39
    protected function urlBase()
40
    {
41
        return "/conf/libraries/{$this->library->code}/locations/{$this->code}";
42
    }
43
}
44