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

Sender::callRequestMethod()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 19
Code Lines 15

Duplication

Lines 4
Ratio 21.05 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 19
rs 8.2222
cc 7
eloc 15
nc 7
nop 3
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