JobOath::getSocket()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
4
namespace Beanie\Job;
5
6
7
use Beanie\Exception\NotFoundException;
8
use Beanie\OathInterface;
9
use Beanie\Server\ResponseOath;
10
11
class JobOath implements OathInterface
12
{
13
    /** @var ResponseOath */
14
    protected $responseOath;
15
16
    /** @var JobFactory */
17
    protected $jobFactory;
18
19
    /**
20
     * @param ResponseOath $oath
21
     * @param JobFactory|null $jobFactory
22
     */
23 11
    public function __construct(ResponseOath $oath, JobFactory $jobFactory = null)
24
    {
25 11
        $this->jobFactory = $jobFactory ?: JobFactory::instance();
26 11
        $this->responseOath = $oath;
27 11
    }
28
29
    /**
30
     * @return resource
31
     */
32 1
    public function getSocket()
33
    {
34 1
        return $this->responseOath->getSocket();
35
    }
36
37
    /**
38
     * @return Job|null
39
     */
40 9
    public function invoke()
41
    {
42
        try {
43 9
            return $this->jobFactory->createFromResponse($this->responseOath->invoke());
44 2
        } catch (NotFoundException $notFound) {
45 2
            return null;
46
        }
47
    }
48
}
49