| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace AlibabaCloud\Client\Resolver; |
||||||
| 4 | |||||||
| 5 | use RuntimeException; |
||||||
| 6 | |||||||
| 7 | /** |
||||||
| 8 | * Trait CallTrait |
||||||
| 9 | * |
||||||
| 10 | * @codeCoverageIgnore |
||||||
| 11 | * @package AlibabaCloud\Client\Resolver |
||||||
| 12 | */ |
||||||
| 13 | trait CallTrait |
||||||
| 14 | { |
||||||
| 15 | /** |
||||||
| 16 | * Magic method for set or get request parameters. |
||||||
| 17 | * |
||||||
| 18 | * @param string $name |
||||||
| 19 | * @param mixed $arguments |
||||||
| 20 | * |
||||||
| 21 | * @return $this |
||||||
| 22 | */ |
||||||
| 23 | public function __call($name, $arguments) |
||||||
| 24 | { |
||||||
| 25 | if (strncmp($name, 'get', 3) === 0) { |
||||||
| 26 | $parameter = \mb_strcut($name, 3); |
||||||
| 27 | |||||||
| 28 | return $this->__get($parameter); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 29 | } |
||||||
| 30 | |||||||
| 31 | if (strncmp($name, 'with', 4) === 0) { |
||||||
| 32 | $parameter = \mb_strcut($name, 4); |
||||||
| 33 | |||||||
| 34 | $value = $this->getCallArguments($name, $arguments); |
||||||
| 35 | $this->data[$parameter] = $value; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 36 | $this->parameterPosition()[$parameter] = $value; |
||||||
|
0 ignored issues
–
show
The method
parameterPosition() does not exist on AlibabaCloud\Client\Resolver\CallTrait. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 37 | |||||||
| 38 | return $this; |
||||||
| 39 | } |
||||||
| 40 | |||||||
| 41 | if (strncmp($name, 'set', 3) === 0) { |
||||||
| 42 | $parameter = \mb_strcut($name, 3); |
||||||
| 43 | $with_method = "with$parameter"; |
||||||
| 44 | |||||||
| 45 | return $this->$with_method($this->getCallArguments($name, $arguments)); |
||||||
| 46 | } |
||||||
| 47 | |||||||
| 48 | throw new RuntimeException('Call to undefined method ' . __CLASS__ . '::' . $name . '()'); |
||||||
| 49 | } |
||||||
| 50 | |||||||
| 51 | /** |
||||||
| 52 | * @param string $name |
||||||
| 53 | * @param array $arguments |
||||||
| 54 | * @param int $index |
||||||
| 55 | * |
||||||
| 56 | * @return mixed |
||||||
| 57 | */ |
||||||
| 58 | private function getCallArguments($name, array $arguments, $index = 0) |
||||||
| 59 | { |
||||||
| 60 | if (!isset($arguments[$index])) { |
||||||
| 61 | throw new \InvalidArgumentException("Missing arguments to method $name"); |
||||||
| 62 | } |
||||||
| 63 | |||||||
| 64 | return $arguments[$index]; |
||||||
| 65 | } |
||||||
| 66 | } |
||||||
| 67 |