Completed
Push — master ( d2c1fa...92e8b2 )
by Sam
17:17 queued 15:28
created

ReserveJobCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Pheanstalk\Command;
4
5
use Pheanstalk\Contract\JobIdInterface;
6
use Pheanstalk\Contract\ResponseInterface;
7
use Pheanstalk\Contract\ResponseParserInterface;
8
use Pheanstalk\Exception\JobNotFoundException;
9
use Pheanstalk\Response\ArrayResponse;
10
11
/**
12
 * The 'reserve-job' command.
13
 *
14
 * Reserves/locks a specific job, new in beanstalkd 1.12+
15
 */
16
class ReserveJobCommand extends AbstractCommand implements ResponseParserInterface
17
{
18
    private $job;
19 2
    public function __construct(JobIdInterface $job)
20
    {
21 2
       $this->job = $job->getId();
22
    }
23
24 1
    public function getCommandLine(): string
25
    {
26 1
        return sprintf('reserve-job %d', $this->job);
27
    }
28
29 2
    public function parseResponse(string $responseLine, ?string $responseData): ArrayResponse
30
    {
31 2
        if ($responseLine === ResponseInterface::RESPONSE_NOT_FOUND) {
32 1
            throw new JobNotFoundException();
33
        }
34
35 1
        list($code, $id) = explode(' ', $responseLine);
36 1
        return $this->createResponse($code, [
37 1
            'id'      => (int) $id,
38 1
            'jobdata' => $responseData,
39
        ]);
40
    }
41
}
42