JobOath   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A getSocket() 0 4 1
A invoke() 0 8 2
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