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

Job::isInitialized()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
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\LazyResource;
7
use Scriptotek\Alma\Conf\JobInstances;
8
9
/**
10
 * A single Job resource.
11
 */
12
class Job extends LazyResource
13
{
14
    /** @var string */
15
    public $job_id;
16
17
    /** @var JobInstances */
18
    public $instances;
19
20
    /**
21
     * Job constructor.
22
     *
23
     * @param Client $client
24
     * @param string $job_id
25
     */
26
    public function __construct(Client $client, $job_id)
27
    {
28
        parent::__construct($client);
29
        $this->job_id = $job_id;
30
        $this->instances = new JobInstances($client, $job_id);
31
    }
32
33
    /**
34
     * Submit the job for running
35
     *
36
     * @return string The API response body
37
     */
38
    public function submit()
39
    {
40
        return $this->client->post($this->url().'?op=run', json_encode($this->jsonSerialize()));
41
    }
42
43
    /**
44
     * Check if we have the full representation of our data object.
45
     *
46
     * @param \stdClass $data
47
     *
48
     * @return bool
49
     */
50
    protected function isInitialized($data)
51
    {
52
        return isset($data->name);
53
    }
54
55
    /**
56
     * Generate the base URL for this resource.
57
     *
58
     * @return string
59
     */
60
    protected function urlBase()
61
    {
62
        return "/conf/jobs/{$this->job_id}";
63
    }
64
}
65