Completed
Push — dev ( 0ee1b7...c0bb06 )
by Marcin
18s queued 13s
created
src/ApiCodesHelpers.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@
 block discarded – undo
112 112
 
113 113
         $map = static::getMap();
114 114
 
115
-        return $map[ $api_code ] ?? null;
115
+        return $map[$api_code] ?? null;
116 116
     }
117 117
 
118 118
     /**
Please login to merge, or discard this patch.
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -21,125 +21,125 @@
 block discarded – undo
21 21
  */
22 22
 trait ApiCodesHelpers
23 23
 {
24
-    /**
25
-     * Returns lowest allowed error code for this module
26
-     *
27
-     * @return integer
28
-     *
29
-     * @throws \RuntimeException Throws exception if no min_code set up
30
-     */
31
-    public static function getMinCode(): int
32
-    {
33
-        $key = ResponseBuilder::CONF_KEY_MIN_CODE;
34
-        $min_code = Config::get($key, null);
35
-
36
-        if ($min_code === null) {
37
-            throw new \RuntimeException(sprintf('CONFIG: Missing "%s" key', $key));
38
-        }
39
-
40
-        return $min_code;
41
-    }
42
-
43
-    /**
44
-     * Returns highest allowed error code for this module
45
-     *
46
-     * @return integer
47
-     *
48
-     * @throws \RuntimeException Throws exception if no max_code set up
49
-     */
50
-    public static function getMaxCode(): int
51
-    {
52
-        $key = ResponseBuilder::CONF_KEY_MAX_CODE;
53
-        $max_code = Config::get($key, null);
54
-
55
-        if ($max_code === null) {
56
-            throw new \RuntimeException(sprintf('CONFIG: Missing "%s" key', $key));
57
-        }
58
-
59
-        return $max_code;
60
-    }
61
-
62
-    /**
63
-     * Returns array of error code constants defined in this class. Used mainly for debugging/tests
64
-     *
65
-     * @return array
66
-     * @throws \ReflectionException
67
-     */
68
-    public static function getApiCodeConstants(): array
69
-    {
70
-        /** @noinspection PhpUnhandledExceptionInspection */
71
-        return (new \ReflectionClass(static::class))->getConstants();
72
-    }
73
-
74
-    /**
75
-     * Returns complete error code to locale string mapping array
76
-     *
77
-     * @return array
78
-     *
79
-     * @throws \RuntimeException Thrown when builder map is not configured.
80
-     */
81
-    public static function getMap(): array
82
-    {
83
-        $user_map = Config::get(ResponseBuilder::CONF_KEY_MAP, null);
84
-        if ($user_map === null) {
85
-            throw new \RuntimeException(sprintf('CONFIG: Missing "%s" key', ResponseBuilder::CONF_KEY_MAP));
86
-        }
87
-        if (!\is_array($user_map)) {
88
-            throw new \RuntimeException(sprintf('CONFIG: "%s" must be an array', ResponseBuilder::CONF_KEY_MAP));
89
-        }
90
-        return Util::mergeConfig(BaseApiCodes::getBaseMap(), $user_map);
91
-    }
92
-
93
-    /**
94
-     * Returns locale mappings key for given api code or @null if there's no mapping
95
-     *
96
-     * @param integer $api_code Api code to look for mapped message for.
97
-     *
98
-     * @return string|null
99
-     *
100
-     * @throws \InvalidArgumentException If $code is not in allowed range.
101
-     */
102
-    public static function getCodeMessageKey(int $api_code): ?string
103
-    {
104
-        if (!static::isCodeValid($api_code)) {
105
-            $min = static::getMinCode();
106
-            $max = static::getMaxCode();
107
-            throw new \InvalidArgumentException("API code value ({$api_code}) is out of allowed range {$min}-{$max}");
108
-        }
109
-
110
-        $map = static::getMap();
111
-
112
-        return $map[ $api_code ] ?? null;
113
-    }
114
-
115
-    /**
116
-     * Checks if given API $code can be used in current configuration.
117
-     *
118
-     * @param int $code API code to validate
119
-     *
120
-     * @return bool
121
-     */
122
-    public static function isCodeValid(int $code): bool
123
-    {
124
-        return ($code === 0) || (($code >= static::getMinCode()) && ($code <= static::getMaxCode()));
125
-    }
126
-
127
-    /**
128
-     * Returns final API code for internal code, remapped to configured code range
129
-     *
130
-     * @param int $internal_code
131
-     *
132
-     * @return int
133
-     *
134
-     * @throws \InvalidArgumentException
135
-     */
136
-    public static function getCodeForInternalOffset(int $internal_code): int
137
-    {
138
-        $min = static::RESERVED_MIN_API_CODE_OFFSET;
139
-        $max = static::RESERVED_MAX_API_CODE_OFFSET;
140
-        Validator::assertIsIntRange('internal_code', $internal_code, $min, $max);
141
-
142
-        return ($internal_code === 0) ? 0 : $internal_code + static::getMinCode();
143
-    }
24
+	/**
25
+	 * Returns lowest allowed error code for this module
26
+	 *
27
+	 * @return integer
28
+	 *
29
+	 * @throws \RuntimeException Throws exception if no min_code set up
30
+	 */
31
+	public static function getMinCode(): int
32
+	{
33
+		$key = ResponseBuilder::CONF_KEY_MIN_CODE;
34
+		$min_code = Config::get($key, null);
35
+
36
+		if ($min_code === null) {
37
+			throw new \RuntimeException(sprintf('CONFIG: Missing "%s" key', $key));
38
+		}
39
+
40
+		return $min_code;
41
+	}
42
+
43
+	/**
44
+	 * Returns highest allowed error code for this module
45
+	 *
46
+	 * @return integer
47
+	 *
48
+	 * @throws \RuntimeException Throws exception if no max_code set up
49
+	 */
50
+	public static function getMaxCode(): int
51
+	{
52
+		$key = ResponseBuilder::CONF_KEY_MAX_CODE;
53
+		$max_code = Config::get($key, null);
54
+
55
+		if ($max_code === null) {
56
+			throw new \RuntimeException(sprintf('CONFIG: Missing "%s" key', $key));
57
+		}
58
+
59
+		return $max_code;
60
+	}
61
+
62
+	/**
63
+	 * Returns array of error code constants defined in this class. Used mainly for debugging/tests
64
+	 *
65
+	 * @return array
66
+	 * @throws \ReflectionException
67
+	 */
68
+	public static function getApiCodeConstants(): array
69
+	{
70
+		/** @noinspection PhpUnhandledExceptionInspection */
71
+		return (new \ReflectionClass(static::class))->getConstants();
72
+	}
73
+
74
+	/**
75
+	 * Returns complete error code to locale string mapping array
76
+	 *
77
+	 * @return array
78
+	 *
79
+	 * @throws \RuntimeException Thrown when builder map is not configured.
80
+	 */
81
+	public static function getMap(): array
82
+	{
83
+		$user_map = Config::get(ResponseBuilder::CONF_KEY_MAP, null);
84
+		if ($user_map === null) {
85
+			throw new \RuntimeException(sprintf('CONFIG: Missing "%s" key', ResponseBuilder::CONF_KEY_MAP));
86
+		}
87
+		if (!\is_array($user_map)) {
88
+			throw new \RuntimeException(sprintf('CONFIG: "%s" must be an array', ResponseBuilder::CONF_KEY_MAP));
89
+		}
90
+		return Util::mergeConfig(BaseApiCodes::getBaseMap(), $user_map);
91
+	}
92
+
93
+	/**
94
+	 * Returns locale mappings key for given api code or @null if there's no mapping
95
+	 *
96
+	 * @param integer $api_code Api code to look for mapped message for.
97
+	 *
98
+	 * @return string|null
99
+	 *
100
+	 * @throws \InvalidArgumentException If $code is not in allowed range.
101
+	 */
102
+	public static function getCodeMessageKey(int $api_code): ?string
103
+	{
104
+		if (!static::isCodeValid($api_code)) {
105
+			$min = static::getMinCode();
106
+			$max = static::getMaxCode();
107
+			throw new \InvalidArgumentException("API code value ({$api_code}) is out of allowed range {$min}-{$max}");
108
+		}
109
+
110
+		$map = static::getMap();
111
+
112
+		return $map[ $api_code ] ?? null;
113
+	}
114
+
115
+	/**
116
+	 * Checks if given API $code can be used in current configuration.
117
+	 *
118
+	 * @param int $code API code to validate
119
+	 *
120
+	 * @return bool
121
+	 */
122
+	public static function isCodeValid(int $code): bool
123
+	{
124
+		return ($code === 0) || (($code >= static::getMinCode()) && ($code <= static::getMaxCode()));
125
+	}
126
+
127
+	/**
128
+	 * Returns final API code for internal code, remapped to configured code range
129
+	 *
130
+	 * @param int $internal_code
131
+	 *
132
+	 * @return int
133
+	 *
134
+	 * @throws \InvalidArgumentException
135
+	 */
136
+	public static function getCodeForInternalOffset(int $internal_code): int
137
+	{
138
+		$min = static::RESERVED_MIN_API_CODE_OFFSET;
139
+		$max = static::RESERVED_MAX_API_CODE_OFFSET;
140
+		Validator::assertIsIntRange('internal_code', $internal_code, $min, $max);
141
+
142
+		return ($internal_code === 0) ? 0 : $internal_code + static::getMinCode();
143
+	}
144 144
 
145 145
 }
Please login to merge, or discard this patch.
src/lang/pl/builder.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -10,54 +10,54 @@
 block discarded – undo
10 10
  */
11 11
 return [
12 12
 
13
-    'ok'                       => 'OK',
14
-    'no_error_message'         => 'Błąd #:api_code',
13
+	'ok'                       => 'OK',
14
+	'no_error_message'         => 'Błąd #:api_code',
15 15
 
16
-    // Used by Exception Handler Helper (when used)
17
-    'uncaught_exception'       => 'Nieprzechwycony wyjątek: :message',
18
-    'http_exception'           => 'Wyjątek HTTP: :message',
16
+	// Used by Exception Handler Helper (when used)
17
+	'uncaught_exception'       => 'Nieprzechwycony wyjątek: :message',
18
+	'http_exception'           => 'Wyjątek HTTP: :message',
19 19
 
20
-    // HttpException handler (added in 6.4.0)
21
-    // Error messages for HttpException caught w/o custom messages
22
-    // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
23
-    'http_400'                 => 'Bad Request',
24
-    'http_401'                 => 'Unauthorized',
25
-    'http_402'                 => 'Payment Required',
26
-    'http_403'                 => 'Forbidden',
27
-    'http_404'                 => 'Not Found',
28
-    'http_405'                 => 'Method Not Allowed',
29
-    'http_406'                 => 'Not Acceptable',
30
-    'http_407'                 => 'Proxy Authentication Required',
31
-    'http_408'                 => 'Request Timeout',
32
-    'http_409'                 => 'Conflict',
33
-    'http_410'                 => 'Gone',
34
-    'http_411'                 => 'Length Required',
35
-    'http_412'                 => 'Precondition Failed',
36
-    'http_413'                 => 'Payload Too Large',
37
-    'http_414'                 => 'URI Too Long',
38
-    'http_415'                 => 'Unsupported Media Type',
39
-    'http_416'                 => 'Range Not Satisfiable',
40
-    'http_417'                 => 'Expectation Failed',
41
-    'http_421'                 => 'Misdirected Request',
42
-    'http_422'                 => 'Unprocessable Entity',
43
-    'http_423'                 => 'Locked',
44
-    'http_424'                 => 'Failed Dependency',
45
-    'http_425'                 => 'Too Early',
46
-    'http_426'                 => 'Upgrade Required',
47
-    'http_428'                 => 'Precondition Required',
48
-    'http_429'                 => 'Too Many Requests',
49
-    'http_431'                 => 'Request Header Fields Too Large',
50
-    'http_451'                 => 'Unavailable For Legal Reasons',
51
-    'http_500'                 => 'Internal Server Error',
52
-    'http_501'                 => 'Not Implemented',
53
-    'http_502'                 => 'Bad Gateway',
54
-    'http_503'                 => 'Service Unavailable',
55
-    'http_504'                 => 'Gateway Timeout',
56
-    'http_505'                 => 'HTTP Version Not Supported',
57
-    'http_506'                 => 'Variant Also Negotiates',
58
-    'http_507'                 => 'Insufficient Storage',
59
-    'http_508'                 => 'Loop Detected',
60
-    'http_509'                 => 'Unassigned',
61
-    'http_510'                 => 'Not Extended',
62
-    'http_511'                 => 'Network Authentication Required',
20
+	// HttpException handler (added in 6.4.0)
21
+	// Error messages for HttpException caught w/o custom messages
22
+	// https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
23
+	'http_400'                 => 'Bad Request',
24
+	'http_401'                 => 'Unauthorized',
25
+	'http_402'                 => 'Payment Required',
26
+	'http_403'                 => 'Forbidden',
27
+	'http_404'                 => 'Not Found',
28
+	'http_405'                 => 'Method Not Allowed',
29
+	'http_406'                 => 'Not Acceptable',
30
+	'http_407'                 => 'Proxy Authentication Required',
31
+	'http_408'                 => 'Request Timeout',
32
+	'http_409'                 => 'Conflict',
33
+	'http_410'                 => 'Gone',
34
+	'http_411'                 => 'Length Required',
35
+	'http_412'                 => 'Precondition Failed',
36
+	'http_413'                 => 'Payload Too Large',
37
+	'http_414'                 => 'URI Too Long',
38
+	'http_415'                 => 'Unsupported Media Type',
39
+	'http_416'                 => 'Range Not Satisfiable',
40
+	'http_417'                 => 'Expectation Failed',
41
+	'http_421'                 => 'Misdirected Request',
42
+	'http_422'                 => 'Unprocessable Entity',
43
+	'http_423'                 => 'Locked',
44
+	'http_424'                 => 'Failed Dependency',
45
+	'http_425'                 => 'Too Early',
46
+	'http_426'                 => 'Upgrade Required',
47
+	'http_428'                 => 'Precondition Required',
48
+	'http_429'                 => 'Too Many Requests',
49
+	'http_431'                 => 'Request Header Fields Too Large',
50
+	'http_451'                 => 'Unavailable For Legal Reasons',
51
+	'http_500'                 => 'Internal Server Error',
52
+	'http_501'                 => 'Not Implemented',
53
+	'http_502'                 => 'Bad Gateway',
54
+	'http_503'                 => 'Service Unavailable',
55
+	'http_504'                 => 'Gateway Timeout',
56
+	'http_505'                 => 'HTTP Version Not Supported',
57
+	'http_506'                 => 'Variant Also Negotiates',
58
+	'http_507'                 => 'Insufficient Storage',
59
+	'http_508'                 => 'Loop Detected',
60
+	'http_509'                 => 'Unassigned',
61
+	'http_510'                 => 'Not Extended',
62
+	'http_511'                 => 'Network Authentication Required',
63 63
 ];
Please login to merge, or discard this patch.
src/lang/en/builder.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -10,55 +10,55 @@
 block discarded – undo
10 10
  */
11 11
 return [
12 12
 
13
-    'ok'                       => 'OK',
14
-    'no_error_message'         => 'Error #:api_code',
13
+	'ok'                       => 'OK',
14
+	'no_error_message'         => 'Error #:api_code',
15 15
 
16
-    // Used by Exception Handler Helper (when used)
17
-    'uncaught_exception'       => 'Uncaught exception: :message',
18
-    'http_exception'           => 'HTTP exception: :message',
16
+	// Used by Exception Handler Helper (when used)
17
+	'uncaught_exception'       => 'Uncaught exception: :message',
18
+	'http_exception'           => 'HTTP exception: :message',
19 19
 
20
-    // HttpException handler (added in 6.4.0)
21
-    // Error messages for HttpException caught w/o custom messages
22
-    // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
23
-    'http_400'                 => 'Bad Request',
24
-    'http_401'                 => 'Unauthorized',
25
-    'http_402'                 => 'Payment Required',
26
-    'http_403'                 => 'Forbidden',
27
-    'http_404'                 => 'Not Found',
28
-    'http_405'                 => 'Method Not Allowed',
29
-    'http_406'                 => 'Not Acceptable',
30
-    'http_407'                 => 'Proxy Authentication Required',
31
-    'http_408'                 => 'Request Timeout',
32
-    'http_409'                 => 'Conflict',
33
-    'http_410'                 => 'Gone',
34
-    'http_411'                 => 'Length Required',
35
-    'http_412'                 => 'Precondition Failed',
36
-    'http_413'                 => 'Payload Too Large',
37
-    'http_414'                 => 'URI Too Long',
38
-    'http_415'                 => 'Unsupported Media Type',
39
-    'http_416'                 => 'Range Not Satisfiable',
40
-    'http_417'                 => 'Expectation Failed',
41
-    'http_421'                 => 'Misdirected Request',
42
-    'http_422'                 => 'Unprocessable Entity',
43
-    'http_423'                 => 'Locked',
44
-    'http_424'                 => 'Failed Dependency',
45
-    'http_425'                 => 'Too Early',
46
-    'http_426'                 => 'Upgrade Required',
47
-    'http_428'                 => 'Precondition Required',
48
-    'http_429'                 => 'Too Many Requests',
49
-    'http_431'                 => 'Request Header Fields Too Large',
50
-    'http_451'                 => 'Unavailable For Legal Reasons',
51
-    'http_500'                 => 'Internal Server Error',
52
-    'http_501'                 => 'Not Implemented',
53
-    'http_502'                 => 'Bad Gateway',
54
-    'http_503'                 => 'Service Unavailable',
55
-    'http_504'                 => 'Gateway Timeout',
56
-    'http_505'                 => 'HTTP Version Not Supported',
57
-    'http_506'                 => 'Variant Also Negotiates',
58
-    'http_507'                 => 'Insufficient Storage',
59
-    'http_508'                 => 'Loop Detected',
60
-    'http_509'                 => 'Unassigned',
61
-    'http_510'                 => 'Not Extended',
62
-    'http_511'                 => 'Network Authentication Required',
20
+	// HttpException handler (added in 6.4.0)
21
+	// Error messages for HttpException caught w/o custom messages
22
+	// https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
23
+	'http_400'                 => 'Bad Request',
24
+	'http_401'                 => 'Unauthorized',
25
+	'http_402'                 => 'Payment Required',
26
+	'http_403'                 => 'Forbidden',
27
+	'http_404'                 => 'Not Found',
28
+	'http_405'                 => 'Method Not Allowed',
29
+	'http_406'                 => 'Not Acceptable',
30
+	'http_407'                 => 'Proxy Authentication Required',
31
+	'http_408'                 => 'Request Timeout',
32
+	'http_409'                 => 'Conflict',
33
+	'http_410'                 => 'Gone',
34
+	'http_411'                 => 'Length Required',
35
+	'http_412'                 => 'Precondition Failed',
36
+	'http_413'                 => 'Payload Too Large',
37
+	'http_414'                 => 'URI Too Long',
38
+	'http_415'                 => 'Unsupported Media Type',
39
+	'http_416'                 => 'Range Not Satisfiable',
40
+	'http_417'                 => 'Expectation Failed',
41
+	'http_421'                 => 'Misdirected Request',
42
+	'http_422'                 => 'Unprocessable Entity',
43
+	'http_423'                 => 'Locked',
44
+	'http_424'                 => 'Failed Dependency',
45
+	'http_425'                 => 'Too Early',
46
+	'http_426'                 => 'Upgrade Required',
47
+	'http_428'                 => 'Precondition Required',
48
+	'http_429'                 => 'Too Many Requests',
49
+	'http_431'                 => 'Request Header Fields Too Large',
50
+	'http_451'                 => 'Unavailable For Legal Reasons',
51
+	'http_500'                 => 'Internal Server Error',
52
+	'http_501'                 => 'Not Implemented',
53
+	'http_502'                 => 'Bad Gateway',
54
+	'http_503'                 => 'Service Unavailable',
55
+	'http_504'                 => 'Gateway Timeout',
56
+	'http_505'                 => 'HTTP Version Not Supported',
57
+	'http_506'                 => 'Variant Also Negotiates',
58
+	'http_507'                 => 'Insufficient Storage',
59
+	'http_508'                 => 'Loop Detected',
60
+	'http_509'                 => 'Unassigned',
61
+	'http_510'                 => 'Not Extended',
62
+	'http_511'                 => 'Network Authentication Required',
63 63
 ];
64 64
 
Please login to merge, or discard this patch.
src/lang/fa/builder.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -10,56 +10,56 @@
 block discarded – undo
10 10
  */
11 11
 return [
12 12
 
13
-    'ok'                       => 'موفق',
14
-    'no_error_message'         => 'خطای شماره :api_code',
13
+	'ok'                       => 'موفق',
14
+	'no_error_message'         => 'خطای شماره :api_code',
15 15
 
16
-    // can be used by Exception Handler (if enabled)
17
-    'uncaught_exception'       => 'استثناء مدیریت نشده :message',
18
-    // we talking API call here, hence we have http_not_found
19
-    'http_exception'           => 'استثناء HTTP :message',
16
+	// can be used by Exception Handler (if enabled)
17
+	'uncaught_exception'       => 'استثناء مدیریت نشده :message',
18
+	// we talking API call here, hence we have http_not_found
19
+	'http_exception'           => 'استثناء HTTP :message',
20 20
 
21
-    // HttpException handler (added in 6.4.0)
22
-    // Error messages for HttpException caught w/o custom messages
23
-    // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
24
-    'http_400'                 => 'Bad Request',
25
-    'http_401'                 => 'اجازه دسترسی ندارید',
26
-    'http_402'                 => 'Payment Required',
27
-    'http_403'                 => 'Forbidden',
28
-    'http_404'                 => 'Not Found',
29
-    'http_405'                 => 'Method Not Allowed',
30
-    'http_406'                 => 'Not Acceptable',
31
-    'http_407'                 => 'Proxy Authentication Required',
32
-    'http_408'                 => 'Request Timeout',
33
-    'http_409'                 => 'Conflict',
34
-    'http_410'                 => 'Gone',
35
-    'http_411'                 => 'Length Required',
36
-    'http_412'                 => 'Precondition Failed',
37
-    'http_413'                 => 'Payload Too Large',
38
-    'http_414'                 => 'URI Too Long',
39
-    'http_415'                 => 'Unsupported Media Type',
40
-    'http_416'                 => 'Range Not Satisfiable',
41
-    'http_417'                 => 'Expectation Failed',
42
-    'http_421'                 => 'Misdirected Request',
43
-    'http_422'                 => 'داده معتبر نیست',
44
-    'http_423'                 => 'Locked',
45
-    'http_424'                 => 'Failed Dependency',
46
-    'http_425'                 => 'Too Early',
47
-    'http_426'                 => 'Upgrade Required',
48
-    'http_428'                 => 'Precondition Required',
49
-    'http_429'                 => 'Too Many Requests',
50
-    'http_431'                 => 'Request Header Fields Too Large',
51
-    'http_451'                 => 'Unavailable For Legal Reasons',
52
-    'http_500'                 => 'Internal Server Error',
53
-    'http_501'                 => 'Not Implemented',
54
-    'http_502'                 => 'Bad Gateway',
55
-    'http_503'                 => 'Service Unavailable',
56
-    'http_504'                 => 'Gateway Timeout',
57
-    'http_505'                 => 'HTTP Version Not Supported',
58
-    'http_506'                 => 'Variant Also Negotiates',
59
-    'http_507'                 => 'Insufficient Storage',
60
-    'http_508'                 => 'Loop Detected',
61
-    'http_509'                 => 'Unassigned',
62
-    'http_510'                 => 'Not Extended',
63
-    'http_511'                 => 'Network Authentication Required',
21
+	// HttpException handler (added in 6.4.0)
22
+	// Error messages for HttpException caught w/o custom messages
23
+	// https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
24
+	'http_400'                 => 'Bad Request',
25
+	'http_401'                 => 'اجازه دسترسی ندارید',
26
+	'http_402'                 => 'Payment Required',
27
+	'http_403'                 => 'Forbidden',
28
+	'http_404'                 => 'Not Found',
29
+	'http_405'                 => 'Method Not Allowed',
30
+	'http_406'                 => 'Not Acceptable',
31
+	'http_407'                 => 'Proxy Authentication Required',
32
+	'http_408'                 => 'Request Timeout',
33
+	'http_409'                 => 'Conflict',
34
+	'http_410'                 => 'Gone',
35
+	'http_411'                 => 'Length Required',
36
+	'http_412'                 => 'Precondition Failed',
37
+	'http_413'                 => 'Payload Too Large',
38
+	'http_414'                 => 'URI Too Long',
39
+	'http_415'                 => 'Unsupported Media Type',
40
+	'http_416'                 => 'Range Not Satisfiable',
41
+	'http_417'                 => 'Expectation Failed',
42
+	'http_421'                 => 'Misdirected Request',
43
+	'http_422'                 => 'داده معتبر نیست',
44
+	'http_423'                 => 'Locked',
45
+	'http_424'                 => 'Failed Dependency',
46
+	'http_425'                 => 'Too Early',
47
+	'http_426'                 => 'Upgrade Required',
48
+	'http_428'                 => 'Precondition Required',
49
+	'http_429'                 => 'Too Many Requests',
50
+	'http_431'                 => 'Request Header Fields Too Large',
51
+	'http_451'                 => 'Unavailable For Legal Reasons',
52
+	'http_500'                 => 'Internal Server Error',
53
+	'http_501'                 => 'Not Implemented',
54
+	'http_502'                 => 'Bad Gateway',
55
+	'http_503'                 => 'Service Unavailable',
56
+	'http_504'                 => 'Gateway Timeout',
57
+	'http_505'                 => 'HTTP Version Not Supported',
58
+	'http_506'                 => 'Variant Also Negotiates',
59
+	'http_507'                 => 'Insufficient Storage',
60
+	'http_508'                 => 'Loop Detected',
61
+	'http_509'                 => 'Unassigned',
62
+	'http_510'                 => 'Not Extended',
63
+	'http_511'                 => 'Network Authentication Required',
64 64
 ];
65 65
 
Please login to merge, or discard this patch.
src/Contracts/ConverterContract.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@
 block discarded – undo
15 15
  */
16 16
 interface ConverterContract
17 17
 {
18
-    /**
19
-     * Returns array representation of the object.
20
-     *
21
-     * @param object $obj    Object to be converted
22
-     * @param array  $config Converter config array to be used for this object (based on exact class
23
-     *                       name match or inheritance).
24
-     *
25
-     * @return array
26
-     */
27
-    public function convert($obj, array $config): array;
18
+	/**
19
+	 * Returns array representation of the object.
20
+	 *
21
+	 * @param object $obj    Object to be converted
22
+	 * @param array  $config Converter config array to be used for this object (based on exact class
23
+	 *                       name match or inheritance).
24
+	 *
25
+	 * @return array
26
+	 */
27
+	public function convert($obj, array $config): array;
28 28
 }
Please login to merge, or discard this patch.
src/BaseApiCodes.php 1 patch
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -21,194 +21,194 @@
 block discarded – undo
21 21
  */
22 22
 class BaseApiCodes
23 23
 {
24
-    use ApiCodesHelpers;
25
-
26
-    /**
27
-     * protected code range - lowest code for reserved range.
28
-     *
29
-     * @var int
30
-     */
31
-    public const RESERVED_MIN_API_CODE_OFFSET = 0;
32
-
33
-    /**
34
-     * protected code range - highest code for reserved range
35
-     *
36
-     * @var int
37
-     */
38
-    public const RESERVED_MAX_API_CODE_OFFSET = 19;
39
-
40
-    /**
41
-     * built-in codes: OK
42
-     *
43
-     * @var int
44
-     */
45
-    protected const OK_OFFSET = 0;
46
-    /**
47
-     * built-in code for fallback message mapping
48
-     *
49
-     * @var int
50
-     */
51
-    protected const NO_ERROR_MESSAGE_OFFSET = 1;
52
-    /**
53
-     * built-in error code for HTTP_NOT_FOUND exception
54
-     *
55
-     * @var int
56
-     */
57
-    protected const EX_HTTP_NOT_FOUND_OFFSET = 10;
58
-    /**
59
-     * built-in error code for HTTP_SERVICE_UNAVAILABLE exception
60
-     *
61
-     * @var int
62
-     */
63
-    protected const EX_HTTP_SERVICE_UNAVAILABLE_OFFSET = 11;
64
-    /**
65
-     * built-in error code for HTTP_EXCEPTION
66
-     *
67
-     * @var int
68
-     */
69
-    protected const EX_HTTP_EXCEPTION_OFFSET = 12;
70
-    /**
71
-     * built-in error code for UNCAUGHT_EXCEPTION
72
-     *
73
-     * @var int
74
-     */
75
-    protected const EX_UNCAUGHT_EXCEPTION_OFFSET = 13;
76
-
77
-    /**
78
-     * built-in error code for \Illuminate\Auth\AuthenticationException
79
-     *
80
-     * @var int
81
-     */
82
-    protected const EX_AUTHENTICATION_EXCEPTION_OFFSET = 14;
83
-
84
-    /**
85
-     * built-in error code for \Illuminate\Auth\AuthenticationException
86
-     *
87
-     * @var int
88
-     */
89
-    protected const EX_VALIDATION_EXCEPTION_OFFSET = 15;
90
-
91
-    /**
92
-     * Returns base code mapping array
93
-     *
94
-     * @return array
95
-     */
96
-    protected static function getBaseMap(): array
97
-    {
98
-        $tpl = 'response-builder::builder.http_%d';
99
-
100
-        return [
101
-            /** @scrutinizer ignore-deprecated */
102
-            self::OK()                          => 'response-builder::builder.ok',
103
-            /** @scrutinizer ignore-deprecated */
104
-            self::NO_ERROR_MESSAGE()            => 'response-builder::builder.no_error_message',
105
-            /** @scrutinizer ignore-deprecated */
106
-            self::EX_HTTP_EXCEPTION()           => 'response-builder::builder.http_exception',
107
-            /** @scrutinizer ignore-deprecated */
108
-            self::EX_UNCAUGHT_EXCEPTION()       => 'response-builder::builder.uncaught_exception',
109
-            /** @scrutinizer ignore-deprecated */
110
-            self::EX_HTTP_NOT_FOUND()           => sprintf($tpl, HttpResponse::HTTP_NOT_FOUND),
111
-            /** @scrutinizer ignore-deprecated */
112
-            self::EX_HTTP_SERVICE_UNAVAILABLE() => sprintf($tpl, HttpResponse::HTTP_SERVICE_UNAVAILABLE),
113
-            /** @scrutinizer ignore-deprecated */
114
-            self::EX_AUTHENTICATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNAUTHORIZED),
115
-            /** @scrutinizer ignore-deprecated */
116
-            self::EX_VALIDATION_EXCEPTION()     => sprintf($tpl, HttpResponse::HTTP_UNPROCESSABLE_ENTITY),
117
-        ];
118
-    }
119
-
120
-    /**
121
-     * Returns API code for internal code OK
122
-     *
123
-     * @return int valid API code in current range
124
-     *
125
-     * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
126
-     */
127
-    public static function OK(): int
128
-    {
129
-        return static::getCodeForInternalOffset(static::OK_OFFSET);
130
-    }
131
-
132
-    /**
133
-     * Returns API code for internal code NO_ERROR_MESSAGE
134
-     *
135
-     * @return int valid API code in current range
136
-     */
137
-    public static function NO_ERROR_MESSAGE(): int
138
-    {
139
-        return static::getCodeForInternalOffset(static::NO_ERROR_MESSAGE_OFFSET);
140
-    }
141
-
142
-    /**
143
-     * Returns API code for internal code EX_HTTP_NOT_FOUND
144
-     *
145
-     * @return int valid API code in current range
146
-     *
147
-     * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
148
-     */
149
-    public static function EX_HTTP_NOT_FOUND(): int
150
-    {
151
-        return static::getCodeForInternalOffset(static::EX_HTTP_NOT_FOUND_OFFSET);
152
-    }
153
-
154
-    /**
155
-     * Returns API code for internal code EX_HTTP_EXCEPTION
156
-     *
157
-     * @return int valid API code in current range
158
-     *
159
-     * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
160
-     */
161
-    public static function EX_HTTP_EXCEPTION(): int
162
-    {
163
-        return static::getCodeForInternalOffset(static::EX_HTTP_EXCEPTION_OFFSET);
164
-    }
165
-
166
-    /**
167
-     * Returns API code for internal code EX_UNCAUGHT_EXCEPTION
168
-     *
169
-     * @return int valid API code in current range
170
-     *
171
-     * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
172
-     */
173
-    public static function EX_UNCAUGHT_EXCEPTION(): int
174
-    {
175
-        return static::getCodeForInternalOffset(static::EX_UNCAUGHT_EXCEPTION_OFFSET);
176
-    }
177
-
178
-    /**
179
-     * Returns API code for internal code EX_AUTHENTICATION_EXCEPTION
180
-     *
181
-     * @return int valid API code in current range
182
-     *
183
-     * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
184
-     */
185
-    public static function EX_AUTHENTICATION_EXCEPTION(): int
186
-    {
187
-        return static::getCodeForInternalOffset(static::EX_AUTHENTICATION_EXCEPTION_OFFSET);
188
-    }
189
-
190
-    /**
191
-     * Returns API code for internal code EX_VALIDATION_EXCEPTION
192
-     *
193
-     * @return int valid API code in current range
194
-     *
195
-     * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
196
-     */
197
-    public static function EX_VALIDATION_EXCEPTION(): int
198
-    {
199
-        return static::getCodeForInternalOffset(static::EX_VALIDATION_EXCEPTION_OFFSET);
200
-    }
201
-
202
-    /**
203
-     * Returns API code for internal code EX_HTTP_SERVICE_UNAVAILABLE
204
-     *
205
-     * @return int valid API code in current range
206
-     *
207
-     * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
208
-     */
209
-    public static function EX_HTTP_SERVICE_UNAVAILABLE(): int
210
-    {
211
-        return static::getCodeForInternalOffset(static::EX_HTTP_SERVICE_UNAVAILABLE_OFFSET);
212
-    }
24
+	use ApiCodesHelpers;
25
+
26
+	/**
27
+	 * protected code range - lowest code for reserved range.
28
+	 *
29
+	 * @var int
30
+	 */
31
+	public const RESERVED_MIN_API_CODE_OFFSET = 0;
32
+
33
+	/**
34
+	 * protected code range - highest code for reserved range
35
+	 *
36
+	 * @var int
37
+	 */
38
+	public const RESERVED_MAX_API_CODE_OFFSET = 19;
39
+
40
+	/**
41
+	 * built-in codes: OK
42
+	 *
43
+	 * @var int
44
+	 */
45
+	protected const OK_OFFSET = 0;
46
+	/**
47
+	 * built-in code for fallback message mapping
48
+	 *
49
+	 * @var int
50
+	 */
51
+	protected const NO_ERROR_MESSAGE_OFFSET = 1;
52
+	/**
53
+	 * built-in error code for HTTP_NOT_FOUND exception
54
+	 *
55
+	 * @var int
56
+	 */
57
+	protected const EX_HTTP_NOT_FOUND_OFFSET = 10;
58
+	/**
59
+	 * built-in error code for HTTP_SERVICE_UNAVAILABLE exception
60
+	 *
61
+	 * @var int
62
+	 */
63
+	protected const EX_HTTP_SERVICE_UNAVAILABLE_OFFSET = 11;
64
+	/**
65
+	 * built-in error code for HTTP_EXCEPTION
66
+	 *
67
+	 * @var int
68
+	 */
69
+	protected const EX_HTTP_EXCEPTION_OFFSET = 12;
70
+	/**
71
+	 * built-in error code for UNCAUGHT_EXCEPTION
72
+	 *
73
+	 * @var int
74
+	 */
75
+	protected const EX_UNCAUGHT_EXCEPTION_OFFSET = 13;
76
+
77
+	/**
78
+	 * built-in error code for \Illuminate\Auth\AuthenticationException
79
+	 *
80
+	 * @var int
81
+	 */
82
+	protected const EX_AUTHENTICATION_EXCEPTION_OFFSET = 14;
83
+
84
+	/**
85
+	 * built-in error code for \Illuminate\Auth\AuthenticationException
86
+	 *
87
+	 * @var int
88
+	 */
89
+	protected const EX_VALIDATION_EXCEPTION_OFFSET = 15;
90
+
91
+	/**
92
+	 * Returns base code mapping array
93
+	 *
94
+	 * @return array
95
+	 */
96
+	protected static function getBaseMap(): array
97
+	{
98
+		$tpl = 'response-builder::builder.http_%d';
99
+
100
+		return [
101
+			/** @scrutinizer ignore-deprecated */
102
+			self::OK()                          => 'response-builder::builder.ok',
103
+			/** @scrutinizer ignore-deprecated */
104
+			self::NO_ERROR_MESSAGE()            => 'response-builder::builder.no_error_message',
105
+			/** @scrutinizer ignore-deprecated */
106
+			self::EX_HTTP_EXCEPTION()           => 'response-builder::builder.http_exception',
107
+			/** @scrutinizer ignore-deprecated */
108
+			self::EX_UNCAUGHT_EXCEPTION()       => 'response-builder::builder.uncaught_exception',
109
+			/** @scrutinizer ignore-deprecated */
110
+			self::EX_HTTP_NOT_FOUND()           => sprintf($tpl, HttpResponse::HTTP_NOT_FOUND),
111
+			/** @scrutinizer ignore-deprecated */
112
+			self::EX_HTTP_SERVICE_UNAVAILABLE() => sprintf($tpl, HttpResponse::HTTP_SERVICE_UNAVAILABLE),
113
+			/** @scrutinizer ignore-deprecated */
114
+			self::EX_AUTHENTICATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNAUTHORIZED),
115
+			/** @scrutinizer ignore-deprecated */
116
+			self::EX_VALIDATION_EXCEPTION()     => sprintf($tpl, HttpResponse::HTTP_UNPROCESSABLE_ENTITY),
117
+		];
118
+	}
119
+
120
+	/**
121
+	 * Returns API code for internal code OK
122
+	 *
123
+	 * @return int valid API code in current range
124
+	 *
125
+	 * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
126
+	 */
127
+	public static function OK(): int
128
+	{
129
+		return static::getCodeForInternalOffset(static::OK_OFFSET);
130
+	}
131
+
132
+	/**
133
+	 * Returns API code for internal code NO_ERROR_MESSAGE
134
+	 *
135
+	 * @return int valid API code in current range
136
+	 */
137
+	public static function NO_ERROR_MESSAGE(): int
138
+	{
139
+		return static::getCodeForInternalOffset(static::NO_ERROR_MESSAGE_OFFSET);
140
+	}
141
+
142
+	/**
143
+	 * Returns API code for internal code EX_HTTP_NOT_FOUND
144
+	 *
145
+	 * @return int valid API code in current range
146
+	 *
147
+	 * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
148
+	 */
149
+	public static function EX_HTTP_NOT_FOUND(): int
150
+	{
151
+		return static::getCodeForInternalOffset(static::EX_HTTP_NOT_FOUND_OFFSET);
152
+	}
153
+
154
+	/**
155
+	 * Returns API code for internal code EX_HTTP_EXCEPTION
156
+	 *
157
+	 * @return int valid API code in current range
158
+	 *
159
+	 * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
160
+	 */
161
+	public static function EX_HTTP_EXCEPTION(): int
162
+	{
163
+		return static::getCodeForInternalOffset(static::EX_HTTP_EXCEPTION_OFFSET);
164
+	}
165
+
166
+	/**
167
+	 * Returns API code for internal code EX_UNCAUGHT_EXCEPTION
168
+	 *
169
+	 * @return int valid API code in current range
170
+	 *
171
+	 * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
172
+	 */
173
+	public static function EX_UNCAUGHT_EXCEPTION(): int
174
+	{
175
+		return static::getCodeForInternalOffset(static::EX_UNCAUGHT_EXCEPTION_OFFSET);
176
+	}
177
+
178
+	/**
179
+	 * Returns API code for internal code EX_AUTHENTICATION_EXCEPTION
180
+	 *
181
+	 * @return int valid API code in current range
182
+	 *
183
+	 * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
184
+	 */
185
+	public static function EX_AUTHENTICATION_EXCEPTION(): int
186
+	{
187
+		return static::getCodeForInternalOffset(static::EX_AUTHENTICATION_EXCEPTION_OFFSET);
188
+	}
189
+
190
+	/**
191
+	 * Returns API code for internal code EX_VALIDATION_EXCEPTION
192
+	 *
193
+	 * @return int valid API code in current range
194
+	 *
195
+	 * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
196
+	 */
197
+	public static function EX_VALIDATION_EXCEPTION(): int
198
+	{
199
+		return static::getCodeForInternalOffset(static::EX_VALIDATION_EXCEPTION_OFFSET);
200
+	}
201
+
202
+	/**
203
+	 * Returns API code for internal code EX_HTTP_SERVICE_UNAVAILABLE
204
+	 *
205
+	 * @return int valid API code in current range
206
+	 *
207
+	 * @deprecated Configure Exception Handler to use your own API code. This method will be removed in v8.
208
+	 */
209
+	public static function EX_HTTP_SERVICE_UNAVAILABLE(): int
210
+	{
211
+		return static::getCodeForInternalOffset(static::EX_HTTP_SERVICE_UNAVAILABLE_OFFSET);
212
+	}
213 213
 
214 214
 }
Please login to merge, or discard this patch.
src/ResponseBuilderLegacy.php 1 patch
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -24,274 +24,274 @@
 block discarded – undo
24 24
  */
25 25
 class ResponseBuilderLegacy extends ResponseBuilderBase
26 26
 {
27
-    /**
28
-     * Returns success
29
-     *
30
-     * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node
31
-     *                                         of the JSON response, single supported object or @null if there's no
32
-     *                                         to be returned.
33
-     * @param integer|null      $api_code      API code to be returned or @null to use value of BaseApiCodes::OK().
34
-     * @param array|null        $placeholders  Placeholders passed to Lang::get() for message placeholders
35
-     *                                         substitution or @null if none.
36
-     * @param integer|null      $http_code     HTTP code to be used for HttpResponse sent or @null
37
-     *                                         for default DEFAULT_HTTP_CODE_OK.
38
-     * @param integer|null      $json_opts     See http://php.net/manual/en/function.json-encode.php for supported
39
-     *                                         options or pass @null to use value from your config (or defaults).
40
-     *
41
-     * @return HttpResponse
42
-     */
43
-    public static function success($data = null, $api_code = null, array $placeholders = null,
44
-                                   int $http_code = null, int $json_opts = null): HttpResponse
45
-    {
46
-        return ResponseBuilder::asSuccess($api_code)
47
-            ->withData($data)
48
-            ->withPlaceholders($placeholders)
49
-            ->withHttpCode($http_code)
50
-            ->withJsonOptions($json_opts)
51
-            ->build();
52
-    }
27
+	/**
28
+	 * Returns success
29
+	 *
30
+	 * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node
31
+	 *                                         of the JSON response, single supported object or @null if there's no
32
+	 *                                         to be returned.
33
+	 * @param integer|null      $api_code      API code to be returned or @null to use value of BaseApiCodes::OK().
34
+	 * @param array|null        $placeholders  Placeholders passed to Lang::get() for message placeholders
35
+	 *                                         substitution or @null if none.
36
+	 * @param integer|null      $http_code     HTTP code to be used for HttpResponse sent or @null
37
+	 *                                         for default DEFAULT_HTTP_CODE_OK.
38
+	 * @param integer|null      $json_opts     See http://php.net/manual/en/function.json-encode.php for supported
39
+	 *                                         options or pass @null to use value from your config (or defaults).
40
+	 *
41
+	 * @return HttpResponse
42
+	 */
43
+	public static function success($data = null, $api_code = null, array $placeholders = null,
44
+								   int $http_code = null, int $json_opts = null): HttpResponse
45
+	{
46
+		return ResponseBuilder::asSuccess($api_code)
47
+			->withData($data)
48
+			->withPlaceholders($placeholders)
49
+			->withHttpCode($http_code)
50
+			->withJsonOptions($json_opts)
51
+			->build();
52
+	}
53 53
 
54
-    /**
55
-     * Returns success
56
-     *
57
-     * @param integer|null $api_code      API code to be returned or @null to use value of BaseApiCodes::OK().
58
-     * @param array|null   $placeholders  Placeholders passed to Lang::get() for message placeholders
59
-     *                                    substitution or @null if none.
60
-     * @param integer|null $http_code     HTTP code to be used for HttpResponse sent or @null
61
-     *                                    for default DEFAULT_HTTP_CODE_OK.
62
-     *
63
-     * @return HttpResponse
64
-     *
65
-     * @deprecated Please use Builder class.
66
-     */
67
-    public static function successWithCode(int $api_code = null, array $placeholders = null,
68
-                                           int $http_code = null): HttpResponse
69
-    {
70
-        return ResponseBuilder::asSuccess($api_code)
71
-            ->withPlaceholders($placeholders)
72
-            ->withHttpCode($http_code)
73
-            ->build();
74
-    }
54
+	/**
55
+	 * Returns success
56
+	 *
57
+	 * @param integer|null $api_code      API code to be returned or @null to use value of BaseApiCodes::OK().
58
+	 * @param array|null   $placeholders  Placeholders passed to Lang::get() for message placeholders
59
+	 *                                    substitution or @null if none.
60
+	 * @param integer|null $http_code     HTTP code to be used for HttpResponse sent or @null
61
+	 *                                    for default DEFAULT_HTTP_CODE_OK.
62
+	 *
63
+	 * @return HttpResponse
64
+	 *
65
+	 * @deprecated Please use Builder class.
66
+	 */
67
+	public static function successWithCode(int $api_code = null, array $placeholders = null,
68
+										   int $http_code = null): HttpResponse
69
+	{
70
+		return ResponseBuilder::asSuccess($api_code)
71
+			->withPlaceholders($placeholders)
72
+			->withHttpCode($http_code)
73
+			->build();
74
+	}
75 75
 
76
-    /**
77
-     * @param string            $message       Custom message to be returned as part of the response.
78
-     * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node
79
-     *                                         of the JSON response, single supported object or @null if there's no
80
-     *                                         to be returned.
81
-     * @param integer|null      $http_code     HTTP code to be used for HttpResponse sent or @null
82
-     *                                         for default DEFAULT_HTTP_CODE_OK.
83
-     *
84
-     * @return HttpResponse
85
-     *
86
-     * @deprecated Please use Builder class.
87
-     */
88
-    public static function successWithMessage(string $message, $data = null, int $api_code = null,
89
-                                              int $http_code = null): HttpResponse
90
-    {
91
-        return ResponseBuilder::asSuccess($api_code)
92
-            ->withMessage($message)
93
-            ->withData($data)
94
-            ->withHttpCode($http_code)
95
-            ->build();
96
-    }
76
+	/**
77
+	 * @param string            $message       Custom message to be returned as part of the response.
78
+	 * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node
79
+	 *                                         of the JSON response, single supported object or @null if there's no
80
+	 *                                         to be returned.
81
+	 * @param integer|null      $http_code     HTTP code to be used for HttpResponse sent or @null
82
+	 *                                         for default DEFAULT_HTTP_CODE_OK.
83
+	 *
84
+	 * @return HttpResponse
85
+	 *
86
+	 * @deprecated Please use Builder class.
87
+	 */
88
+	public static function successWithMessage(string $message, $data = null, int $api_code = null,
89
+											  int $http_code = null): HttpResponse
90
+	{
91
+		return ResponseBuilder::asSuccess($api_code)
92
+			->withMessage($message)
93
+			->withData($data)
94
+			->withHttpCode($http_code)
95
+			->build();
96
+	}
97 97
 
98
-    /**
99
-     * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node.
100
-     *                                         of the JSON response, single supported object or @null if there's no
101
-     *                                         to be returned.
102
-     * @param integer|null      $api_code      API code to be returned or @null to use value of BaseApiCodes::OK().
103
-     * @param array|null        $placeholders  Placeholders passed to Lang::get() for message placeholders
104
-     *                                         substitution or @null if none.
105
-     * @param integer|null      $http_code     HTTP code to be used for HttpResponse sent or @null
106
-     *                                         for default DEFAULT_HTTP_CODE_OK.
107
-     * @param integer|null      $json_opts     See http://php.net/manual/en/function.json-encode.php for supported
108
-     *                                         options or pass @null to use value from your config (or defaults).
109
-     *
110
-     * @return HttpResponse
111
-     *
112
-     * @deprecated Please use Builder class.
113
-     */
114
-    public static function successWithHttpCode(int $http_code = null): HttpResponse
115
-    {
116
-        return ResponseBuilder::asSuccess()
117
-            ->withHttpCode($http_code)
118
-            ->build();
119
-    }
98
+	/**
99
+	 * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node.
100
+	 *                                         of the JSON response, single supported object or @null if there's no
101
+	 *                                         to be returned.
102
+	 * @param integer|null      $api_code      API code to be returned or @null to use value of BaseApiCodes::OK().
103
+	 * @param array|null        $placeholders  Placeholders passed to Lang::get() for message placeholders
104
+	 *                                         substitution or @null if none.
105
+	 * @param integer|null      $http_code     HTTP code to be used for HttpResponse sent or @null
106
+	 *                                         for default DEFAULT_HTTP_CODE_OK.
107
+	 * @param integer|null      $json_opts     See http://php.net/manual/en/function.json-encode.php for supported
108
+	 *                                         options or pass @null to use value from your config (or defaults).
109
+	 *
110
+	 * @return HttpResponse
111
+	 *
112
+	 * @deprecated Please use Builder class.
113
+	 */
114
+	public static function successWithHttpCode(int $http_code = null): HttpResponse
115
+	{
116
+		return ResponseBuilder::asSuccess()
117
+			->withHttpCode($http_code)
118
+			->build();
119
+	}
120 120
 
121
-    /**
122
-     * Builds error Response object. Supports optional arguments passed to Lang::get() if associated error
123
-     * message uses placeholders as well as return data payload
124
-     *
125
-     * @param integer           $api_code      Your API code to be returned with the response object.
126
-     * @param array|null        $placeholders  Placeholders passed to Lang::get() for message placeholders
127
-     *                                         substitution or @null if none.
128
-     * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node
129
-     *                                         of the JSON response, single supported object or @null if there's no
130
-     *                                         to be returned.
131
-     * @param integer|null      $http_code     HTTP code to be used for HttpResponse sent or @null
132
-     *                                         for default DEFAULT_HTTP_CODE_ERROR.
133
-     * @param integer|null      $json_opts     See http://php.net/manual/en/function.json-encode.php for supported
134
-     *                                         options or pass @null to use value from your config (or defaults).
135
-     *
136
-     * @return HttpResponse
137
-     */
138
-    public static function error(int $api_code, array $placeholders = null, $data = null, int $http_code = null,
139
-                                 int $json_opts = null): HttpResponse
140
-    {
141
-        return ResponseBuilder::asError($api_code)
142
-            ->withPlaceholders($placeholders)
143
-            ->withData($data)
144
-            ->withHttpCode($http_code)
145
-            ->withJsonOptions($json_opts)
146
-            ->build();
147
-    }
121
+	/**
122
+	 * Builds error Response object. Supports optional arguments passed to Lang::get() if associated error
123
+	 * message uses placeholders as well as return data payload
124
+	 *
125
+	 * @param integer           $api_code      Your API code to be returned with the response object.
126
+	 * @param array|null        $placeholders  Placeholders passed to Lang::get() for message placeholders
127
+	 *                                         substitution or @null if none.
128
+	 * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node
129
+	 *                                         of the JSON response, single supported object or @null if there's no
130
+	 *                                         to be returned.
131
+	 * @param integer|null      $http_code     HTTP code to be used for HttpResponse sent or @null
132
+	 *                                         for default DEFAULT_HTTP_CODE_ERROR.
133
+	 * @param integer|null      $json_opts     See http://php.net/manual/en/function.json-encode.php for supported
134
+	 *                                         options or pass @null to use value from your config (or defaults).
135
+	 *
136
+	 * @return HttpResponse
137
+	 */
138
+	public static function error(int $api_code, array $placeholders = null, $data = null, int $http_code = null,
139
+								 int $json_opts = null): HttpResponse
140
+	{
141
+		return ResponseBuilder::asError($api_code)
142
+			->withPlaceholders($placeholders)
143
+			->withData($data)
144
+			->withHttpCode($http_code)
145
+			->withJsonOptions($json_opts)
146
+			->build();
147
+	}
148 148
 
149
-    /**
150
-     * @param integer           $api_code      Your API code to be returned with the response object.
151
-     * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node
152
-     *                                         of the JSON response, single supported object or @null if there's no
153
-     *                                         to be returned.
154
-     * @param array|null        $placeholders  Placeholders passed to Lang::get() for message placeholders
155
-     *                                         substitution or @null if none.
156
-     * @param integer|null      $json_opts     See http://php.net/manual/en/function.json-encode.php for supported
157
-     *                                         options or pass @null to use value from your config (or defaults).
158
-     *
159
-     * @return HttpResponse
160
-     *
161
-     * @deprecated Please use Builder class.
162
-     */
163
-    public static function errorWithData(int $api_code, $data, array $placeholders = null,
164
-                                         int $json_opts = null): HttpResponse
165
-    {
166
-        return ResponseBuilder::asError($api_code)
167
-            ->withData($data)
168
-            ->withPlaceholders($placeholders)
169
-            ->withJsonOptions($json_opts)
170
-            ->build();
171
-    }
149
+	/**
150
+	 * @param integer           $api_code      Your API code to be returned with the response object.
151
+	 * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node
152
+	 *                                         of the JSON response, single supported object or @null if there's no
153
+	 *                                         to be returned.
154
+	 * @param array|null        $placeholders  Placeholders passed to Lang::get() for message placeholders
155
+	 *                                         substitution or @null if none.
156
+	 * @param integer|null      $json_opts     See http://php.net/manual/en/function.json-encode.php for supported
157
+	 *                                         options or pass @null to use value from your config (or defaults).
158
+	 *
159
+	 * @return HttpResponse
160
+	 *
161
+	 * @deprecated Please use Builder class.
162
+	 */
163
+	public static function errorWithData(int $api_code, $data, array $placeholders = null,
164
+										 int $json_opts = null): HttpResponse
165
+	{
166
+		return ResponseBuilder::asError($api_code)
167
+			->withData($data)
168
+			->withPlaceholders($placeholders)
169
+			->withJsonOptions($json_opts)
170
+			->build();
171
+	}
172 172
 
173
-    /**
174
-     * @param integer           $api_code      Your API code to be returned with the response object.
175
-     * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node
176
-     *                                         of the JSON response, single supported object or @null if there's no
177
-     *                                         to be returned.
178
-     * @param integer           $http_code     HTTP code to be used for HttpResponse sent.
179
-     * @param array|null        $placeholders  Placeholders passed to Lang::get() for message placeholders
180
-     *                                         substitution or @null if none.
181
-     * @param integer|null      $json_opts     See http://php.net/manual/en/function.json-encode.php for supported
182
-     *                                         options or pass @null to use value from your config (or defaults).
183
-     *
184
-     * @return HttpResponse
185
-     *
186
-     * @throws \InvalidArgumentException if http_code is @null
187
-     *
188
-     * @deprecated Please use Builder class.
189
-     */
190
-    public static function errorWithDataAndHttpCode(int $api_code, $data, int $http_code, array $placeholders = null,
191
-                                                    int $json_opts = null): HttpResponse
192
-    {
193
-        return ResponseBuilder::asError($api_code)
194
-            ->withData($data)
195
-            ->withHttpCode($http_code)
196
-            ->withPlaceholders($placeholders)
197
-            ->withJsonOptions($json_opts)
198
-            ->build();
199
-    }
173
+	/**
174
+	 * @param integer           $api_code      Your API code to be returned with the response object.
175
+	 * @param object|array|null $data          Array of primitives and supported objects to be returned in 'data' node
176
+	 *                                         of the JSON response, single supported object or @null if there's no
177
+	 *                                         to be returned.
178
+	 * @param integer           $http_code     HTTP code to be used for HttpResponse sent.
179
+	 * @param array|null        $placeholders  Placeholders passed to Lang::get() for message placeholders
180
+	 *                                         substitution or @null if none.
181
+	 * @param integer|null      $json_opts     See http://php.net/manual/en/function.json-encode.php for supported
182
+	 *                                         options or pass @null to use value from your config (or defaults).
183
+	 *
184
+	 * @return HttpResponse
185
+	 *
186
+	 * @throws \InvalidArgumentException if http_code is @null
187
+	 *
188
+	 * @deprecated Please use Builder class.
189
+	 */
190
+	public static function errorWithDataAndHttpCode(int $api_code, $data, int $http_code, array $placeholders = null,
191
+													int $json_opts = null): HttpResponse
192
+	{
193
+		return ResponseBuilder::asError($api_code)
194
+			->withData($data)
195
+			->withHttpCode($http_code)
196
+			->withPlaceholders($placeholders)
197
+			->withJsonOptions($json_opts)
198
+			->build();
199
+	}
200 200
 
201
-    /**
202
-     * @param integer    $api_code     Your API code to be returned with the response object.
203
-     * @param integer    $http_code    HTTP code to be used for HttpResponse sent or @null
204
-     *                                 for default DEFAULT_HTTP_CODE_ERROR.
205
-     * @param array|null $placeholders Placeholders passed to Lang::get() for message placeholders
206
-     *                                 substitution or @null if none.
207
-     *
208
-     * @return HttpResponse
209
-     *
210
-     * @throws \InvalidArgumentException if http_code is @null
211
-     *
212
-     * @deprecated Please use Builder class.
213
-     */
214
-    public static function errorWithHttpCode(int $api_code, int $http_code, array $placeholders = null): HttpResponse
215
-    {
216
-        return ResponseBuilder::asError($api_code)
217
-            ->withHttpCode($http_code)
218
-            ->withPlaceholders($placeholders)
219
-            ->build();
220
-    }
201
+	/**
202
+	 * @param integer    $api_code     Your API code to be returned with the response object.
203
+	 * @param integer    $http_code    HTTP code to be used for HttpResponse sent or @null
204
+	 *                                 for default DEFAULT_HTTP_CODE_ERROR.
205
+	 * @param array|null $placeholders Placeholders passed to Lang::get() for message placeholders
206
+	 *                                 substitution or @null if none.
207
+	 *
208
+	 * @return HttpResponse
209
+	 *
210
+	 * @throws \InvalidArgumentException if http_code is @null
211
+	 *
212
+	 * @deprecated Please use Builder class.
213
+	 */
214
+	public static function errorWithHttpCode(int $api_code, int $http_code, array $placeholders = null): HttpResponse
215
+	{
216
+		return ResponseBuilder::asError($api_code)
217
+			->withHttpCode($http_code)
218
+			->withPlaceholders($placeholders)
219
+			->build();
220
+	}
221 221
 
222
-    /**
223
-     * @param integer           $api_code  Your API code to be returned with the response object.
224
-     * @param string            $message   Custom message to be returned as part of error response
225
-     * @param object|array|null $data      Array of primitives and supported objects to be returned in 'data' node
226
-     *                                     of the JSON response, single supported object or @null if there's no
227
-     *                                     to be returned.
228
-     * @param integer|null      $http_code Optional HTTP status code to be used for HttpResponse sent
229
-     *                                     or @null for DEFAULT_HTTP_CODE_ERROR
230
-     * @param integer|null      $json_opts See http://php.net/manual/en/function.json-encode.php for supported
231
-     *                                     options or pass @null to use value from your config (or defaults).
232
-     *
233
-     * @return HttpResponse
234
-     *
235
-     * @deprecated Please use Builder class.
236
-     */
237
-    public static function errorWithMessageAndData(int $api_code, string $message, $data,
238
-                                                   int $http_code = null, int $json_opts = null): HttpResponse
239
-    {
240
-        return ResponseBuilder::asError($api_code)
241
-            ->withMessage($message)
242
-            ->withData($data)
243
-            ->withHttpCode($http_code)
244
-            ->withJsonOptions($json_opts)
245
-            ->build();
246
-    }
222
+	/**
223
+	 * @param integer           $api_code  Your API code to be returned with the response object.
224
+	 * @param string            $message   Custom message to be returned as part of error response
225
+	 * @param object|array|null $data      Array of primitives and supported objects to be returned in 'data' node
226
+	 *                                     of the JSON response, single supported object or @null if there's no
227
+	 *                                     to be returned.
228
+	 * @param integer|null      $http_code Optional HTTP status code to be used for HttpResponse sent
229
+	 *                                     or @null for DEFAULT_HTTP_CODE_ERROR
230
+	 * @param integer|null      $json_opts See http://php.net/manual/en/function.json-encode.php for supported
231
+	 *                                     options or pass @null to use value from your config (or defaults).
232
+	 *
233
+	 * @return HttpResponse
234
+	 *
235
+	 * @deprecated Please use Builder class.
236
+	 */
237
+	public static function errorWithMessageAndData(int $api_code, string $message, $data,
238
+												   int $http_code = null, int $json_opts = null): HttpResponse
239
+	{
240
+		return ResponseBuilder::asError($api_code)
241
+			->withMessage($message)
242
+			->withData($data)
243
+			->withHttpCode($http_code)
244
+			->withJsonOptions($json_opts)
245
+			->build();
246
+	}
247 247
 
248
-    /**
249
-     * @param integer           $api_code   Your API code to be returned with the response object.
250
-     * @param string            $message    custom message to be returned as part of error response
251
-     * @param object|array|null $data       Array of primitives and supported objects to be returned in 'data' node
252
-     *                                      of the JSON response, single supported object or @null if there's no
253
-     *                                      to be returned.
254
-     * @param integer|null      $http_code  HTTP code to be used for HttpResponse sent or @null
255
-     *                                      for default DEFAULT_HTTP_CODE_ERROR.
256
-     * @param integer|null      $json_opts  See http://php.net/manual/en/function.json-encode.php for supported
257
-     *                                      options or pass @null to use value from your config (or defaults).
258
-     * @param array|null        $debug_data optional debug data array to be added to returned JSON.
259
-     *
260
-     * @return HttpResponse
261
-     *
262
-     * @deprecated Please use Builder class.
263
-     *
264
-     * @noinspection PhpTooManyParametersInspection
265
-     */
266
-    public static function errorWithMessageAndDataAndDebug(int $api_code, string $message, $data,
267
-                                                           int $http_code = null, int $json_opts = null,
268
-                                                           array $debug_data = null): HttpResponse
269
-    {
270
-        return ResponseBuilder::asError($api_code)
271
-            ->withMessage($message)
272
-            ->withData($data)
273
-            ->withHttpCode($http_code)
274
-            ->withJsonOptions($json_opts)
275
-            ->withDebugData($debug_data)
276
-            ->build();
277
-    }
248
+	/**
249
+	 * @param integer           $api_code   Your API code to be returned with the response object.
250
+	 * @param string            $message    custom message to be returned as part of error response
251
+	 * @param object|array|null $data       Array of primitives and supported objects to be returned in 'data' node
252
+	 *                                      of the JSON response, single supported object or @null if there's no
253
+	 *                                      to be returned.
254
+	 * @param integer|null      $http_code  HTTP code to be used for HttpResponse sent or @null
255
+	 *                                      for default DEFAULT_HTTP_CODE_ERROR.
256
+	 * @param integer|null      $json_opts  See http://php.net/manual/en/function.json-encode.php for supported
257
+	 *                                      options or pass @null to use value from your config (or defaults).
258
+	 * @param array|null        $debug_data optional debug data array to be added to returned JSON.
259
+	 *
260
+	 * @return HttpResponse
261
+	 *
262
+	 * @deprecated Please use Builder class.
263
+	 *
264
+	 * @noinspection PhpTooManyParametersInspection
265
+	 */
266
+	public static function errorWithMessageAndDataAndDebug(int $api_code, string $message, $data,
267
+														   int $http_code = null, int $json_opts = null,
268
+														   array $debug_data = null): HttpResponse
269
+	{
270
+		return ResponseBuilder::asError($api_code)
271
+			->withMessage($message)
272
+			->withData($data)
273
+			->withHttpCode($http_code)
274
+			->withJsonOptions($json_opts)
275
+			->withDebugData($debug_data)
276
+			->build();
277
+	}
278 278
 
279
-    /**
280
-     * @param integer      $api_code  Your API code to be returned with the response object.
281
-     * @param string       $message   Custom message to be returned as part of error response
282
-     * @param integer|null $http_code HTTP code to be used with final response sent or @null
283
-     *                                for default DEFAULT_HTTP_CODE_ERROR.
284
-     *
285
-     * @return HttpResponse
286
-     *
287
-     * @deprecated Please use Builder class.
288
-     */
289
-    public static function errorWithMessage(int $api_code, string $message, int $http_code = null): HttpResponse
290
-    {
291
-        return ResponseBuilder::asError($api_code)
292
-            ->withMessage($message)
293
-            ->withHttpCode($http_code)
294
-            ->build();
295
-    }
279
+	/**
280
+	 * @param integer      $api_code  Your API code to be returned with the response object.
281
+	 * @param string       $message   Custom message to be returned as part of error response
282
+	 * @param integer|null $http_code HTTP code to be used with final response sent or @null
283
+	 *                                for default DEFAULT_HTTP_CODE_ERROR.
284
+	 *
285
+	 * @return HttpResponse
286
+	 *
287
+	 * @deprecated Please use Builder class.
288
+	 */
289
+	public static function errorWithMessage(int $api_code, string $message, int $http_code = null): HttpResponse
290
+	{
291
+		return ResponseBuilder::asError($api_code)
292
+			->withMessage($message)
293
+			->withHttpCode($http_code)
294
+			->build();
295
+	}
296 296
 
297 297
 }
Please login to merge, or discard this patch.
src/Validator.php 1 patch
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -15,183 +15,183 @@
 block discarded – undo
15 15
  */
16 16
 class Validator
17 17
 {
18
-    /** @var string */
19
-    public const TYPE_STRING = 'string';
20
-
21
-    /** @var string */
22
-    public const TYPE_INTEGER = 'integer';
23
-
24
-    /** @var string */
25
-    public const TYPE_BOOL = 'boolean';
26
-
27
-    /** @var string */
28
-    public const TYPE_ARRAY = 'array';
29
-
30
-    /** @var string */
31
-    public const TYPE_OBJECT = 'object';
32
-
33
-    /** @var string */
34
-    public const TYPE_NULL = 'NULL';
35
-
36
-    /**
37
-     * Checks if given $val is of type boolean
38
-     *
39
-     * @param string $key Name of the key to be used if exception is thrown.
40
-     * @param mixed  $var Variable to be asserted.
41
-     *
42
-     * @return void
43
-     *
44
-     * @throws \InvalidArgumentException
45
-     */
46
-    public static function assertIsBool(string $key, $var): void
47
-    {
48
-        self::assertIsType($key, $var, [self::TYPE_BOOL]);
49
-    }
50
-
51
-    /**
52
-     * Checks if given $val is of type integer
53
-     *
54
-     * @param string $key Name of the key to be used if exception is thrown.
55
-     * @param mixed  $var Variable to be asserted.
56
-     *
57
-     * @return void
58
-     *
59
-     * @throws \InvalidArgumentException
60
-     */
61
-    public static function assertIsInt(string $key, $var): void
62
-    {
63
-        self::assertIsType($key, $var, [self::TYPE_INTEGER]);
64
-    }
65
-
66
-    /**
67
-     * Checks if given $val is of type array
68
-     *
69
-     * @param string $key Name of the key to be used if exception is thrown.
70
-     * @param mixed  $var Variable to be asserted.
71
-     *
72
-     * @return void
73
-     *
74
-     * @throws \InvalidArgumentException
75
-     */
76
-    public static function assertIsArray(string $key, $var): void
77
-    {
78
-        self::assertIsType($key, $var, [self::TYPE_ARRAY]);
79
-    }
80
-
81
-    /**
82
-     * Checks if given $val is an object
83
-     *
84
-     * @param string $key Name of the key to be used if exception is thrown.
85
-     * @param mixed  $var Variable to be asserted.
86
-     *
87
-     * @return void
88
-     *
89
-     * @throws \InvalidArgumentException
90
-     */
91
-    public static function assertIsObject(string $key, $var): void
92
-    {
93
-        self::assertIsType($key, $var, [self::TYPE_OBJECT]);
94
-    }
95
-
96
-    /**
97
-     * Checks if given $val is of type string
98
-     *
99
-     * @param string $name Label or name of the variable to be used in exception message (if thrown).
100
-     * @param mixed  $var  Variable to be asserted.
101
-     *
102
-     * @return void
103
-     *
104
-     * @throws \InvalidArgumentException
105
-     */
106
-    public static function assertIsString(string $name, $var): void
107
-    {
108
-        self::assertIsType($name, $var, [self::TYPE_STRING]);
109
-    }
110
-
111
-    /**
112
-     * @param string $name Label or name of the variable to be used in exception message (if thrown).
113
-     * @param mixed  $var  Variable to be asserted.
114
-     * @param int    $min  Min allowed value (inclusive)
115
-     * @param int    $max  Max allowed value (inclusive)
116
-     *
117
-     * @return void
118
-     *
119
-     * @throws \InvalidArgumentException
120
-     * @throws \RuntimeException
121
-     */
122
-    public static function assertIsIntRange(string $name, $var, int $min, int $max): void
123
-    {
124
-        self::assertIsInt($name, $var);
125
-
126
-        if ($min > $max) {
127
-            throw new \RuntimeException(
128
-                \sprintf('%s: Invalid range for "%s". Ensure bound values are not swapped.', __FUNCTION__, $name));
129
-        }
130
-
131
-        if (($min > $var) || ($var > $max)) {
132
-            throw new \InvalidArgumentException(
133
-                \sprintf('Invalid value of "%s" (%d). Must be between %d-%d inclusive.', $name, $var, $min, $max));
134
-        }
135
-    }
136
-
137
-    /**
138
-     * Checks if $item (of name $key) is of type that is include in $allowed_types.
139
-     *
140
-     * @param string $name          Label or name of the variable to be used in exception message (if thrown).
141
-     * @param mixed  $var           Variable to be asserted.
142
-     * @param array  $allowed_types Array of allowed types for $var, i.e. [Validator::TYPE_INTEGER]
143
-     *
144
-     * @return void
145
-     *
146
-     * @throws \InvalidArgumentException
147
-     */
148
-    public static function assertIsType(string $name, $var, array $allowed_types): void
149
-    {
150
-        $type = \gettype($var);
151
-        if (!\in_array($type, $allowed_types)) {
152
-            throw new \InvalidArgumentException(
153
-                \sprintf('"%s" must be one of allowed types: %s (%s given)',
154
-                    $name, implode(', ', $allowed_types), gettype($var))
155
-            );
156
-        }
157
-    }
158
-
159
-    /**
160
-     * Ensures given $http_code is valid code for error response.
161
-     *
162
-     * @param int $http_code
163
-     */
164
-    public static function assertErrorHttpCode(int $http_code): void
165
-    {
166
-        self::assertIsInt('http_code', $http_code);
167
-        self::assertIsIntRange('http_code', $http_code,
168
-            ResponseBuilder::ERROR_HTTP_CODE_MIN, ResponseBuilder::ERROR_HTTP_CODE_MAX);
169
-    }
170
-
171
-    /**
172
-     * Ensures given $http_code is valid for response indicating sucessful operation.
173
-     *
174
-     * @param int $http_code
175
-     */
176
-    public static function assertOkHttpCode(int $http_code): void
177
-    {
178
-        self::assertIsInt('http_code', $http_code);
179
-        self::assertIsIntRange('http_code', $http_code, 200, 299);
180
-    }
181
-
182
-    /**
183
-     * Ensures $obj is instance of $cls.
184
-     *
185
-     * @param string $name
186
-     * @param object $obj
187
-     * @param string $cls
188
-     */
189
-    public static function assertInstanceOf(string $name, object $obj, string $cls): void
190
-    {
191
-        if (!($obj instanceof $cls)) {
192
-            throw new \InvalidArgumentException(
193
-                \sprintf('"%s" must be instance of "%s".', $name, $cls)
194
-            );
195
-        }
196
-    }
18
+	/** @var string */
19
+	public const TYPE_STRING = 'string';
20
+
21
+	/** @var string */
22
+	public const TYPE_INTEGER = 'integer';
23
+
24
+	/** @var string */
25
+	public const TYPE_BOOL = 'boolean';
26
+
27
+	/** @var string */
28
+	public const TYPE_ARRAY = 'array';
29
+
30
+	/** @var string */
31
+	public const TYPE_OBJECT = 'object';
32
+
33
+	/** @var string */
34
+	public const TYPE_NULL = 'NULL';
35
+
36
+	/**
37
+	 * Checks if given $val is of type boolean
38
+	 *
39
+	 * @param string $key Name of the key to be used if exception is thrown.
40
+	 * @param mixed  $var Variable to be asserted.
41
+	 *
42
+	 * @return void
43
+	 *
44
+	 * @throws \InvalidArgumentException
45
+	 */
46
+	public static function assertIsBool(string $key, $var): void
47
+	{
48
+		self::assertIsType($key, $var, [self::TYPE_BOOL]);
49
+	}
50
+
51
+	/**
52
+	 * Checks if given $val is of type integer
53
+	 *
54
+	 * @param string $key Name of the key to be used if exception is thrown.
55
+	 * @param mixed  $var Variable to be asserted.
56
+	 *
57
+	 * @return void
58
+	 *
59
+	 * @throws \InvalidArgumentException
60
+	 */
61
+	public static function assertIsInt(string $key, $var): void
62
+	{
63
+		self::assertIsType($key, $var, [self::TYPE_INTEGER]);
64
+	}
65
+
66
+	/**
67
+	 * Checks if given $val is of type array
68
+	 *
69
+	 * @param string $key Name of the key to be used if exception is thrown.
70
+	 * @param mixed  $var Variable to be asserted.
71
+	 *
72
+	 * @return void
73
+	 *
74
+	 * @throws \InvalidArgumentException
75
+	 */
76
+	public static function assertIsArray(string $key, $var): void
77
+	{
78
+		self::assertIsType($key, $var, [self::TYPE_ARRAY]);
79
+	}
80
+
81
+	/**
82
+	 * Checks if given $val is an object
83
+	 *
84
+	 * @param string $key Name of the key to be used if exception is thrown.
85
+	 * @param mixed  $var Variable to be asserted.
86
+	 *
87
+	 * @return void
88
+	 *
89
+	 * @throws \InvalidArgumentException
90
+	 */
91
+	public static function assertIsObject(string $key, $var): void
92
+	{
93
+		self::assertIsType($key, $var, [self::TYPE_OBJECT]);
94
+	}
95
+
96
+	/**
97
+	 * Checks if given $val is of type string
98
+	 *
99
+	 * @param string $name Label or name of the variable to be used in exception message (if thrown).
100
+	 * @param mixed  $var  Variable to be asserted.
101
+	 *
102
+	 * @return void
103
+	 *
104
+	 * @throws \InvalidArgumentException
105
+	 */
106
+	public static function assertIsString(string $name, $var): void
107
+	{
108
+		self::assertIsType($name, $var, [self::TYPE_STRING]);
109
+	}
110
+
111
+	/**
112
+	 * @param string $name Label or name of the variable to be used in exception message (if thrown).
113
+	 * @param mixed  $var  Variable to be asserted.
114
+	 * @param int    $min  Min allowed value (inclusive)
115
+	 * @param int    $max  Max allowed value (inclusive)
116
+	 *
117
+	 * @return void
118
+	 *
119
+	 * @throws \InvalidArgumentException
120
+	 * @throws \RuntimeException
121
+	 */
122
+	public static function assertIsIntRange(string $name, $var, int $min, int $max): void
123
+	{
124
+		self::assertIsInt($name, $var);
125
+
126
+		if ($min > $max) {
127
+			throw new \RuntimeException(
128
+				\sprintf('%s: Invalid range for "%s". Ensure bound values are not swapped.', __FUNCTION__, $name));
129
+		}
130
+
131
+		if (($min > $var) || ($var > $max)) {
132
+			throw new \InvalidArgumentException(
133
+				\sprintf('Invalid value of "%s" (%d). Must be between %d-%d inclusive.', $name, $var, $min, $max));
134
+		}
135
+	}
136
+
137
+	/**
138
+	 * Checks if $item (of name $key) is of type that is include in $allowed_types.
139
+	 *
140
+	 * @param string $name          Label or name of the variable to be used in exception message (if thrown).
141
+	 * @param mixed  $var           Variable to be asserted.
142
+	 * @param array  $allowed_types Array of allowed types for $var, i.e. [Validator::TYPE_INTEGER]
143
+	 *
144
+	 * @return void
145
+	 *
146
+	 * @throws \InvalidArgumentException
147
+	 */
148
+	public static function assertIsType(string $name, $var, array $allowed_types): void
149
+	{
150
+		$type = \gettype($var);
151
+		if (!\in_array($type, $allowed_types)) {
152
+			throw new \InvalidArgumentException(
153
+				\sprintf('"%s" must be one of allowed types: %s (%s given)',
154
+					$name, implode(', ', $allowed_types), gettype($var))
155
+			);
156
+		}
157
+	}
158
+
159
+	/**
160
+	 * Ensures given $http_code is valid code for error response.
161
+	 *
162
+	 * @param int $http_code
163
+	 */
164
+	public static function assertErrorHttpCode(int $http_code): void
165
+	{
166
+		self::assertIsInt('http_code', $http_code);
167
+		self::assertIsIntRange('http_code', $http_code,
168
+			ResponseBuilder::ERROR_HTTP_CODE_MIN, ResponseBuilder::ERROR_HTTP_CODE_MAX);
169
+	}
170
+
171
+	/**
172
+	 * Ensures given $http_code is valid for response indicating sucessful operation.
173
+	 *
174
+	 * @param int $http_code
175
+	 */
176
+	public static function assertOkHttpCode(int $http_code): void
177
+	{
178
+		self::assertIsInt('http_code', $http_code);
179
+		self::assertIsIntRange('http_code', $http_code, 200, 299);
180
+	}
181
+
182
+	/**
183
+	 * Ensures $obj is instance of $cls.
184
+	 *
185
+	 * @param string $name
186
+	 * @param object $obj
187
+	 * @param string $cls
188
+	 */
189
+	public static function assertInstanceOf(string $name, object $obj, string $cls): void
190
+	{
191
+		if (!($obj instanceof $cls)) {
192
+			throw new \InvalidArgumentException(
193
+				\sprintf('"%s" must be instance of "%s".', $name, $cls)
194
+			);
195
+		}
196
+	}
197 197
 }
Please login to merge, or discard this patch.
src/ResponseBuilder.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 * @return HttpResponse
85 85
 	 */
86 86
 	public static function success($data = null, $api_code = null, array $placeholders = null,
87
-	                               int $http_code = null, int $json_opts = null): HttpResponse
87
+								   int $http_code = null, int $json_opts = null): HttpResponse
88 88
 	{
89 89
 		return ResponseBuilder::asSuccess($api_code)
90 90
 			->withData($data)
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 * @return HttpResponse
113 113
 	 */
114 114
 	public static function error(int $api_code, array $placeholders = null, $data = null, int $http_code = null,
115
-	                             int $json_opts = null): HttpResponse
115
+								 int $json_opts = null): HttpResponse
116 116
 	{
117 117
 		return ResponseBuilder::asError($api_code)
118 118
 			->withPlaceholders($placeholders)
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	public function withHttpCode(int $http_code = null): self
162 162
 	{
163 163
 		Validator::assertIsType('http_code', $http_code, [Validator::TYPE_INTEGER,
164
-		                                                  Validator::TYPE_NULL]);
164
+														  Validator::TYPE_NULL]);
165 165
 		$this->http_code = $http_code;
166 166
 
167 167
 		return $this;
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 	public function withData($data = null): self
176 176
 	{
177 177
 		Validator::assertIsType('data', $data, [Validator::TYPE_ARRAY,
178
-		                                        Validator::TYPE_OBJECT,
179
-		                                        Validator::TYPE_NULL]);
178
+												Validator::TYPE_OBJECT,
179
+												Validator::TYPE_NULL]);
180 180
 		$this->data = $data;
181 181
 
182 182
 		return $this;
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	public function withJsonOptions(int $json_opts = null): self
191 191
 	{
192 192
 		Validator::assertIsType('json_opts', $json_opts, [Validator::TYPE_INTEGER,
193
-		                                                  Validator::TYPE_NULL]);
193
+														  Validator::TYPE_NULL]);
194 194
 		$this->json_opts = $json_opts;
195 195
 
196 196
 		return $this;
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	public function withDebugData(array $debug_data = null): self
205 205
 	{
206 206
 		Validator::assertIsType('$debug_data', $debug_data, [Validator::TYPE_ARRAY,
207
-		                                                     Validator::TYPE_NULL]);
207
+															 Validator::TYPE_NULL]);
208 208
 		$this->debug_data = $debug_data;
209 209
 
210 210
 		return $this;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	public function withMessage(string $msg = null): self
219 219
 	{
220 220
 		Validator::assertIsType('message', $msg, [Validator::TYPE_STRING,
221
-		                                          Validator::TYPE_NULL]);
221
+												  Validator::TYPE_NULL]);
222 222
 		$this->message = $msg;
223 223
 
224 224
 		return $this;
@@ -305,8 +305,8 @@  discard block
 block discarded – undo
305 305
 	 * @noinspection PhpTooManyParametersInspection
306 306
 	 */
307 307
 	protected function make(bool $success, int $api_code, $msg_or_api_code, $data = null,
308
-	                        int $http_code = null, array $placeholders = null, array $http_headers = null,
309
-	                        int $json_opts = null, array $debug_data = null): HttpResponse
308
+							int $http_code = null, array $placeholders = null, array $http_headers = null,
309
+							int $json_opts = null, array $debug_data = null): HttpResponse
310 310
 	{
311 311
 		$http_headers = $http_headers ?? [];
312 312
 		$http_code = $http_code ?? ($success ? ResponseBuilder::DEFAULT_HTTP_CODE_OK : ResponseBuilder::DEFAULT_HTTP_CODE_ERROR);
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 	 * @noinspection PhpTooManyParametersInspection
346 346
 	 */
347 347
 	protected function buildResponse(bool $success, int $api_code,
348
-	                                 $msg_or_api_code, array $placeholders = null,
349
-	                                 $data = null, array $debug_data = null): array
348
+									 $msg_or_api_code, array $placeholders = null,
349
+									 $data = null, array $debug_data = null): array
350 350
 	{
351 351
 		// ensure $data is either @null, array or object of class with configured mapping.
352 352
 		$data = (new Converter())->convert($data);
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 		$data = (new Converter())->convert($data);
353 353
 		if ($data !== null && !\is_object($data)) {
354 354
 			// ensure we get object in final JSON structure in data node
355
-			$data = (object)$data;
355
+			$data = (object) $data;
356 356
 		}
357 357
 
358 358
 		// get human readable message for API code or use message string (if given instead of API code)
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 
375 375
 		if ($debug_data !== null) {
376 376
 			$debug_key = Config::get(ResponseBuilder::CONF_KEY_DEBUG_DEBUG_KEY, ResponseBuilder::KEY_DEBUG);
377
-			$response[ $debug_key ] = $debug_data;
377
+			$response[$debug_key] = $debug_data;
378 378
 		}
379 379
 
380 380
 		return $response;
Please login to merge, or discard this patch.