Completed
Push — master ( f5a8d9...ecb36f )
by Clayton
10s
created

CallsServices::queue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace PerfectOblivion\Services\Traits;
4
5
use Illuminate\Container\Container;
6
use Illuminate\Contracts\Bus\Dispatcher;
7
use PerfectOblivion\Services\QueuedService;
8
use PerfectOblivion\Services\ServiceCaller;
9
use PerfectOblivion\Services\Exceptions\ServiceHandlerMethodException;
10
11
trait CallsServices
12
{
13
    /**
14
     * Call a service.
15
     *
16
     * @param  string  $service
17
     * @param  mixed  ...$params
18
     *
19
     * @return mixed
20
     */
21
    public function call(string $service, ...$params)
22
    {
23
        return Container::getInstance()->make(ServiceCaller::class)->call($service, ...$params);
24
    }
25
26
    /**
27
     * Push the service call to the queue..
28
     *
29
     * @param  string  $service
30
     * @param  mixed  ...$params
31
     *
32
     * @throws \PerfectOblivion\Services\Exceptions\ServiceHandlerMethodException
33
     *
34
     * @return mixed
35
     */
36 View Code Duplication
    public function queue(string $service, ...$params)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        if (! Container::getInstance()->make(ServiceCaller::class)->hasHandler($service)) {
39
            throw ServiceHandlerMethodException::notFound($service);
40
        }
41
42
        return resolve(Dispatcher::class)->dispatch(
43
            new QueuedService(Container::getInstance()->make($service), $params)
44
        );
45
    }
46
}
47