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: |
|
|
|
|
57
|
|
|
return $request->{$method}($arguments[0], $arguments[1], $arguments[2], $arguments[3]); |
58
|
|
View Code Duplication |
case 5: |
|
|
|
|
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
|
|
|
|
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.