PluginProbe
PostNL for WooCommerce / 4.0.1
PostNL for WooCommerce v4.0.1
5.9.12 5.9.11 5.9.10 5.9.9 5.9.8 5.9.7 5.9.6 trunk 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.1.4 3.1.5 3.1.6 3.1.7 4.0.0 4.0.1 4.0.2 4.3.2 4.3.3 4.4.0 4.4.1 All 72 releases
woo-postnl / includes / vendor / myparcelnl / sdk / src / Helper / RequestError.php

RequestError.php in PostNL for WooCommerce 4.0.1, at includes/vendor/myparcelnl/sdk/src/Helper/RequestError.php

79 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2 /**
3 * If you want to add improvements, please create a fork in our GitHub:
4 * https://github.com/myparcelnl
5 *
6 * @author Reindert Vetter <[email protected]>
7 * @copyright 2010-2020 MyParcel
8 * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US CC BY-NC-ND 3.0 NL
9 * @link https://github.com/myparcelnl/sdk
10 * @since File available since Release v2.0.0
11 */
12
13 namespace MyParcelNL\Sdk\src\Helper;
14
15 class RequestError
16 {
17 /**
18 * @param $error
19 * @param array $result
20 *
21 * @return string
22 */
23 public static function getTotalMessage($error, $result)
24 {
25 return
26 self::getErrorCode($error) . ' - ' .
27 self::getErrorHumanMessage($error) . ' - ' .
28 self::getErrorMessage($error, $result);
29 }
30
31 /**
32 * @param $error
33 *
34 * @return string
35 */
36 private static function getErrorCode($error)
37 {
38 $code = '';
39 if (key_exists('code', $error)) {
40 $code = $error['code'];
41 } elseif (key_exists('fields', $error)) {
42 $code = $error['fields'][0];
43 }
44
45 return $code;
46 }
47
48 /**
49 * @param $error
50 *
51 * @return string
52 */
53 private static function getErrorHumanMessage($error)
54 {
55 $humanMessage = key_exists('human', $error) ? $error['human'][0] : '';
56
57 return $humanMessage;
58 }
59
60 /**
61 * @param $error
62 * @param array $result
63 *
64 * @return string
65 */
66 private static function getErrorMessage($error, $result)
67 {
68 if (key_exists('message', $result)) {
69 $message = $result['message'];
70 } elseif (key_exists('message', $error)) {
71 $message = $error['message'];
72 } else {
73 $message = 'Unknown error: ' . json_encode($error) . '. Please contact MyParcel.';
74 }
75
76 return $message;
77 }
78 }
79