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

SelfCallingService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A call() 0 4 1
A queue() 0 10 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 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