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

AbstractServiceCaller   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
call() 0 1 ?
A hasHandler() 0 4 1
A setHandlerMethod() 0 4 1
1
<?php
2
3
namespace PerfectOblivion\Services;
4
5
use Illuminate\Contracts\Container\Container;
6
7
abstract class AbstractServiceCaller
8
{
9
    /**
10
     * The container implementation.
11
     *
12
     * @var \Illuminate\Contracts\Container\Container
13
     */
14
    protected $container;
15
16
    /**
17
     * The handler method to be called.
18
     *
19
     * @var string
20
     */
21
    public static $handlerMethod;
22
23
    /**
24
     * Create a new service caller instance.
25
     *
26
     * @param  \Illuminate\Contracts\Container\Container  $container
27
     */
28
    public function __construct(Container $container)
29
    {
30
        $this->container = $container;
31
    }
32
33
    /**
34
     * Call a service through its appropriate handler.
35
     *
36
     * @param  string  $service
37
     * @param  mixed  ...$params
38
     *
39
     * @return mixed
40
     */
41
    abstract public function call($service, ...$params);
42
43
    /**
44
     * Determine if the service handler method exists.
45
     *
46
     * @param  mixed  $service
47
     *
48
     * @return bool
49
     */
50
    public function hasHandler($service)
51
    {
52
        return method_exists($service, $this::$handlerMethod);
53
    }
54
55
    /**
56
     * Set the handler method name for services.
57
     *
58
     * @param  string  $method
59
     */
60
    public static function setHandlerMethod(string $method = 'run')
61
    {
62
        static::$handlerMethod = $method;
63
    }
64
}
65