| Total Complexity | 5 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | class PickService |
||
| 15 | { |
||
| 16 | /** @var ApiClient */ |
||
| 17 | protected $client; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * PickService constructor. |
||
| 21 | * |
||
| 22 | * @param string $token |
||
| 23 | * @param bool $sandbox |
||
| 24 | */ |
||
| 25 | public function __construct(string $token, bool $sandbox = false) |
||
| 26 | { |
||
| 27 | // create client. |
||
| 28 | $this->client = new ApiClient(); |
||
| 29 | |||
| 30 | // init client |
||
| 31 | $this->getClient()->setSandbox($sandbox)->setToken($token); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @return ApiClient |
||
| 36 | */ |
||
| 37 | public function getClient(): ApiClient |
||
| 38 | { |
||
| 39 | return $this->client; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * create new request to api. |
||
| 44 | * |
||
| 45 | * @param string $service |
||
| 46 | * @param string $type |
||
| 47 | * @param array ...$arg |
||
| 48 | * |
||
| 49 | * @throws \Exception |
||
| 50 | * |
||
| 51 | * @return ZttpResponse |
||
| 52 | */ |
||
| 53 | public function request(string $service, string $type, ...$arg) |
||
| 54 | { |
||
| 55 | $serviceClass = $this->getClass($service); |
||
| 56 | |||
| 57 | if (!\class_exists($serviceClass)) { |
||
| 58 | throw new \Exception("class $serviceClass not exists"); |
||
| 59 | } |
||
| 60 | |||
| 61 | $service = new $serviceClass($this->getClient()); |
||
| 62 | |||
| 63 | return $service->$type(...$arg); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Get service class. |
||
| 68 | * |
||
| 69 | * @param string $service |
||
| 70 | * |
||
| 71 | * @return string |
||
| 72 | */ |
||
| 73 | protected function getClass(string $service): string |
||
| 76 | } |
||
| 77 | } |
||
| 78 |