Test Setup Failed
Pull Request — master (#19)
by
unknown
01:55
created

JobInstances::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 5
loc 5
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 string */
20
    public $job_id;
21
22
    /**
23
     * Job Instances constructor.
24
     *
25
     * @param Client $client
26
     * @param string $job_id
27
     */
28
    public function __construct(Client $client, $job_id)
29
    {
30
        $this->job_id = $job_id;
31
        parent::__construct($client, 'job_instance');
32
    }
33
34
    /**
35
     * Get a single Job Instance by its job_id and instance_id.
36
     *
37
     * @param string $job_id
38
     * @param string $instance_id
39
     *
40
     * @return JobInstance
41
     */
42
    public function get($job_id, $instance_id)
43
    {
44
        return JobInstance::make($this->client, $job_id, $instance_id);
45
    }
46
47
    /**
48
     * Convert a data element to a resource object.
49
     *
50
     * @param $data
51
     *
52
     * @return JobInstance
53
     */
54
    protected function convertToResource($data)
55
    {
56
        return JobInstance::make($this->client, $data->job_info->id, $data->id)
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/jobs/{$this->job_id}/instances";
68
    }
69
}
70