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

SelfCallingService::queue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
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 SelfCallingService
12
{
13
    /**
14
     * Run the service.
15
     *
16
     * @return mixed
17
     */
18
    public static function call()
19
    {
20
        return app(ServiceCaller::class)->call(static::class, ...func_get_args());
21
    }
22
23
    /**
24
     * Push the service call to the queue.
25
     *
26
     * @return mixed
27
     */
28
    public static function queue()
29
    {
30
        if (! app(ServiceCaller::class)->hasHandler(static::class)) {
31
            throw ServiceHandlerMethodException::notFound(static::class);
32
        }
33
34
        return resolve(Dispatcher::class)->dispatch(
35
            new QueuedService(Container::getInstance()->make(static::class), func_get_args())
36
        );
37
    }
38
}
39