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

ServiceCaller   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 10
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A call() 0 8 2
A queue() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace PerfectOblivion\Services;
4
5
use Illuminate\Container\Container;
6
use Illuminate\Contracts\Bus\Dispatcher;
7
use PerfectOblivion\Services\Exceptions\ServiceHandlerMethodException;
8
9
class ServiceCaller extends AbstractServiceCaller
10
{
11
    /**
12
     * Call a service through its appropriate handler.
13
     *
14
     * @param  string  $service
15
     * @param  mixed  ...$params
16
     *
17
     * @return mixed
18
     */
19
    public function call($service, ...$params)
20
    {
21
        if (! $this->hasHandler($service)) {
22
            throw ServiceHandlerMethodException::notFound($service);
23
        }
24
25
        return $this->container->make($service)->{$this::$handlerMethod}(...$params);
26
    }
27
28
    /**
29
     * Push the service call to the queue..
30
     *
31
     * @param  string  $service
32
     * @param  mixed  ...$params
33
     *
34
     * @throws \PerfectOblivion\Services\Exceptions\ServiceHandlerMethodException
35
     *
36
     * @return mixed
37
     */
38 View Code Duplication
    public function queue($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...
39
    {
40
        if (! $this->hasHandler($service)) {
41
            throw ServiceHandlerMethodException::notFound($service);
42
        }
43
44
        return resolve(Dispatcher::class)->dispatch(
45
            new QueuedService(Container::getInstance()->make($service), $params)
46
        );
47
    }
48
}
49