Psr11ContainerCallbackResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 11
c 1
b 0
f 1
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 11 3
1
<?php
2
3
namespace Tarantool\JobQueue\Executor\CallbackResolver;
4
5
use Psr\Container\ContainerInterface as Container;
6
use Tarantool\JobQueue\Exception\BadPayloadException;
7
use Tarantool\JobQueue\JobBuilder\JobOptions;
8
9
class Psr11ContainerCallbackResolver implements CallbackResolver
10
{
11
    private $container;
12
    private $idFormat;
13
14 6
    public function __construct(Container $container, string $idFormat = '%s')
15
    {
16 6
        $this->container = $container;
17 6
        $this->idFormat = $idFormat;
18 6
    }
19
20 6
    public function resolve($payload): callable
21
    {
22 6
        if (empty($payload[JobOptions::PAYLOAD_SERVICE_ID])) {
23 1
            throw BadPayloadException::missingOrEmptyKeyValue($payload, JobOptions::PAYLOAD_SERVICE_ID, 'string', __CLASS__);
24
        }
25
26 5
        $id = sprintf($this->idFormat, $payload[JobOptions::PAYLOAD_SERVICE_ID]);
27
28 5
        return empty($payload[JobOptions::PAYLOAD_SERVICE_METHOD])
29
            ? $this->container->get($id)
30
            : [$this->container->get($id), $payload[JobOptions::PAYLOAD_SERVICE_METHOD]];
31
    }
32
}
33