Completed
Push — 2.0 ( 896296...c88480 )
by Marco
09:04
created

AddBulk::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 3
nop 2
dl 0
loc 23
ccs 0
cts 18
cp 0
crap 12
rs 9.0856
c 0
b 0
f 0
1
<?php namespace Comodojo\Extender\Socket\Commands\Queue;
2
3
use \Comodojo\Extender\Queue\Manager;
4
use \Comodojo\Daemon\Daemon;
5
use \Comodojo\RpcServer\Request\Parameters;
6
use \Comodojo\Extender\Socket\Messages\Task\Request as TaskRequestMessage;
7
use \Comodojo\Extender\Task\Request as TaskRequest;
8
use \Comodojo\Exception\RpcException;
9
use \Exception;
10
11
class AddBulk {
12
13
    public static function execute(Parameters $params, Daemon $daemon) {
14
15
        $messages = $params->get('requests');
16
17
        $requests = [];
18
19
        try {
20
            foreach ($messages as $message) {
21
                $requests[] = TaskRequest::createFromMessage(
22
                    TaskRequestMessage::createFromExport($message)
23
                );
24
            }
25
        } catch (Exception $e) {
26
            throw new RpcException("Invalid message payload in request", -32600);
27
        }
28
29
        $manager = new Manager(
30
            $daemon->getConfiguration(),
0 ignored issues
show
Bug introduced by
The method getConfiguration() does not exist on Comodojo\Daemon\Daemon. It seems like you code against a sub-type of Comodojo\Daemon\Daemon such as Comodojo\Extender\ExtenderDaemon. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
            $daemon->/** @scrutinizer ignore-call */ 
31
                     getConfiguration(),
Loading history...
31
            $daemon->getLogger(),
32
            $daemon->getEvents()
33
        );
34
35
        return $manager->addBulk($requests);
36
37
    }
38
39
}
40