| Conditions | 5 |
| Paths | 3 |
| Total Lines | 31 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 21 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | 2 | public function execute($request) |
|
| 19 | { |
||
| 20 | 2 | RequestNotSupportedException::assertSupports($this, $request); |
|
| 21 | |||
| 22 | 2 | $details = ArrayObject::ensureArrayObject($request->getModel()); |
|
| 23 | |||
| 24 | 2 | $params = $this->api->createTransaction((array) $details); |
|
| 25 | |||
| 26 | 2 | $details->replace($params); |
|
| 27 | |||
| 28 | 2 | if (isset($params['url']) === false) { |
|
| 29 | 1 | throw new LogicException("Response content is not valid json: \n\n".urldecode(json_encode(array_map(function ($data) { |
|
| 30 | 1 | return is_string($data) === true ? urlencode($data) : $data; |
|
| 31 | 1 | }, $params)))); |
|
| 32 | } else { |
||
| 33 | $map = [ |
||
| 34 | 1 | 'zh-tw' => 'zh-TW', |
|
| 35 | 1 | 'tw' => 'zh-TW', |
|
| 36 | 1 | 'zh-cn' => 'zh-CN', |
|
| 37 | 1 | 'cn' => 'zh-CN', |
|
| 38 | 1 | 'en-us' => 'en', |
|
| 39 | 1 | 'en' => 'en', |
|
| 40 | 1 | ]; |
|
| 41 | 1 | $locale = strtolower( |
|
| 42 | 1 | isset($details['locale']) === true ? $details['locale'] : 'zh-TW' |
|
| 43 | 1 | ); |
|
| 44 | 1 | $locale = isset($map[$locale]) === true ? $map[$locale] : 'zh-TW'; |
|
| 45 | |||
| 46 | 1 | throw new HttpRedirect($params['url'].'?locale='.$locale); |
|
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 60 |