JobInstances::urlBase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 4
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Scriptotek\Alma\Conf;
4
5
use Scriptotek\Alma\Client;
6
use Scriptotek\Alma\Model\IterableCollection;
7
use Scriptotek\Alma\Model\SimplePaginatedList;
8
use Scriptotek\Alma\Model\ReadOnlyArrayAccess;
9
use Scriptotek\Alma\Conf\JobInstance;
10
11
/**
12
 * Iterable collection of Job Instances.
13
 */
14 View Code Duplication
class JobInstances extends SimplePaginatedList 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...
15
{
16
    use ReadOnlyArrayAccess;
17
    use IterableCollection;
18
19
    /** @var Job */
20
    public $job;
21
22
    /**
23
     * Job Instances constructor.
24
     *
25
     * @param Client $client
26
     * @param Job $job
27
     */
28
    public function __construct(Client $client, Job $job)
29
    {
30
        parent::__construct($client, 'job_instance');
31
        $this->job = $job;
32
    }
33
34
    /**
35
     * Get a single Job Instance by its instance_id.
36
     *
37
     * @param string $instance_id
38
     *
39
     * @return JobInstance
40
     */
41
    public function get(string $instance_id)
42
    {
43
        return JobInstance::make($this->client, $this->job, $instance_id);
44
    }
45
46
    /**
47
     * Convert a data element to a resource object.
48
     *
49
     * @param $data
50
     *
51
     * @return JobInstance
52
     */
53
    protected function convertToResource($data)
54
    {
55
        return JobInstance::make($this->client, $this->job, $data->id)
56
            ->init($data);
57
    }
58
59
    /**
60
     * Generate the base URL for this resource.
61
     *
62
     * @return string
63
     */
64
    protected function urlBase()
65
    {
66
        return "/conf/jobs/{$this->job->job_id}/instances";
67
    }
68
}
69