Completed
Push — master ( 4474f6...7e8ad4 )
by Sergey
04:22 queued 02:10
created

Sender   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 7.02 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 1
dl 4
loc 57
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __call() 0 8 1
B callRequestMethod() 4 19 7

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 seregazhuk\SmsIntel\Api;
4
5
use seregazhuk\SmsIntel\Contracts\RequestInterface;
6
use seregazhuk\SmsIntel\Api\Requests\RequestsContainer;
7
8
class Sender
9
{
10
    /**
11
     * @var RequestsContainer
12
     */
13
    protected $requestsContainer;
14
15
    /**
16
     * @param RequestsContainer $requestsContainer
17
     */
18
    public function __construct(RequestsContainer $requestsContainer)
19
    {
20
        $this->requestsContainer = $requestsContainer;
21
    }
22
23
    /**
24
     * Proxies all methods to the appropriate Request object
25
     *
26
     * @param string $method
27
     * @param array $arguments
28
     * @return array
29
     */
30
    public function __call($method, $arguments)
31
    {
32
        $request = $this
33
            ->requestsContainer
34
            ->resolveRequestByAction($method);
35
36
        return $this->callRequestMethod($request, $method, $arguments);
37
    }
38
39
    /**
40
     * @param RequestInterface $request
41
     * @param string $method
42
     * @param array $arguments
43
     * @return mixed
44
     */
45
    protected function callRequestMethod(RequestInterface $request, $method, array $arguments)
46
    {
47
        if(empty($arguments)) return $request->{$method}();
48
49
        switch (count($arguments)) {
50
            case 1:
51
                return $request->{$method}($arguments[0]);
52
            case 2:
53
                return $request->{$method}($arguments[0], $arguments[1]);
54
            case 3:
55
                return $request->{$method}($arguments[0], $arguments[1], $arguments[2]);
56 View Code Duplication
            case 4:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
57
                return $request->{$method}($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
58 View Code Duplication
            case 5:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
59
                return $request->{$method}($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]);
60
            default:
61
                return $request->{$method}($arguments);
62
        }
63
    }
64
}
65