Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 7c5c695

Browse files
author
Kirill Fuchs
committed
refactored http exceptions to new structure
1 parent 7902d60 commit 7c5c695

21 files changed

+457
-305
lines changed

composer.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
"authors": [
66
{
77
"name": "Fuzz Web",
8-
"email": "web@fuzzproductions.com"
8+
"email": "opensource@fuzzproductions.com"
99
}
1010
],
11+
"require": {
12+
"php": ">=7.0"
13+
},
1114
"require-dev": {
12-
"phpunit/phpunit": "~5.0"
15+
"phpunit/phpunit": "~5.6"
1316
},
1417
"autoload": {
1518
"psr-4": {
1619
"Fuzz\\HttpException\\": "src/",
1720
"Fuzz\\HttpException\\Tests\\": "tests/"
1821
}
19-
},
20-
"require": {}
22+
}
2123
}

src/AccessDeniedHttpException.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ class AccessDeniedHttpException extends HttpException
1414
/**
1515
* Error code storage;
1616
*
17-
* @var string
17+
* @const string
1818
*/
19-
protected $error_name = 'access_denied';
19+
const ERROR = 'access_denied';
2020

2121
/**
22-
* NotFoundHttpException constructor.
22+
* AccessDeniedHttpException constructor.
2323
*
24-
* @param string $message
25-
* @param string $error_formatted
26-
* @param array $error_data
27-
* @param array $headers
28-
* @param \Exception $previous
24+
* @param string|null $errorDescription
25+
* @param array $errorData
26+
* @param string|null $userTitle
27+
* @param null $userMessage
28+
* @param array $headers
29+
* @param \Exception|null $previous
2930
*/
30-
public function __construct($message = null, array $error_data = [], $error_formatted = null, array $headers = [], \Exception $previous = null)
31+
public function __construct(string $errorDescription = null, array $errorData = [], string $userTitle = null, $userMessage = null, array $headers = [], \Exception $previous = null)
3132
{
32-
parent::__construct($message, $error_formatted, $error_data, $headers, self::HTTP_CODE, $previous);
33+
parent::__construct(self::HTTP_CODE, self::ERROR, $errorDescription, $errorData, $userTitle, $userMessage, $headers, $previous);
3334
}
3435
}

src/BadRequestHttpException.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ class BadRequestHttpException extends HttpException
1414
/**
1515
* Error code storage;
1616
*
17-
* @var string
17+
* @const string
1818
*/
19-
protected $error_name = 'bad_request';
19+
const ERROR = 'bad_request';
2020

2121
/**
22-
* NotFoundHttpException constructor.
22+
* BadRequestHttpException constructor.
2323
*
24-
* @param string $message
25-
* @param string $error_formatted
26-
* @param array $error_data
27-
* @param array $headers
28-
* @param \Exception $previous
24+
* @param string|null $errorDescription
25+
* @param array $errorData
26+
* @param string|null $userTitle
27+
* @param null $userMessage
28+
* @param array $headers
29+
* @param \Exception|null $previous
2930
*/
30-
public function __construct($message = null, array $error_data = [], $error_formatted = null, array $headers = [], \Exception $previous = null)
31+
public function __construct(string $errorDescription = null, array $errorData = [], string $userTitle = null, $userMessage = null, array $headers = [], \Exception $previous = null)
3132
{
32-
parent::__construct($message, $error_formatted, $error_data, $headers, self::HTTP_CODE, $previous);
33+
parent::__construct(self::HTTP_CODE, self::ERROR, $errorDescription, $errorData, $userTitle, $userMessage, $headers, $previous);
3334
}
3435
}

src/ConflictHttpException.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ class ConflictHttpException extends HttpException
1414
/**
1515
* Error code storage;
1616
*
17-
* @var string
17+
* @const string
1818
*/
19-
protected $error_name = 'conflict';
20-
19+
const ERROR = 'conflict';
20+
2121
/**
22-
* NotFoundHttpException constructor.
22+
* ConflictHttpException constructor.
2323
*
24-
* @param string $message
25-
* @param string $error_formatted
26-
* @param array $error_data
27-
* @param array $headers
28-
* @param \Exception $previous
24+
* @param string|null $errorDescription
25+
* @param array $errorData
26+
* @param string|null $userTitle
27+
* @param null $userMessage
28+
* @param array $headers
29+
* @param \Exception|null $previous
2930
*/
30-
public function __construct($message = null, array $error_data = [], $error_formatted = null, array $headers = [], \Exception $previous = null)
31+
public function __construct(string $errorDescription = null, array $errorData = [], string $userTitle = null, $userMessage = null, array $headers = [], \Exception $previous = null)
3132
{
32-
parent::__construct($message, $error_formatted, $error_data, $headers, self::HTTP_CODE, $previous);
33+
parent::__construct(self::HTTP_CODE, self::ERROR, $errorDescription, $errorData, $userTitle, $userMessage, $headers, $previous);
3334
}
3435
}

src/Contracts/HttpExceptionInterface.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function getStatusCode();
1616
*
1717
* @return array
1818
*/
19-
public function getHeaders();
19+
public function getHttpHeaders();
2020

2121
/**
2222
* Data corresponding to the error
@@ -32,12 +32,12 @@ public function getErrorData();
3232
*
3333
* @return string
3434
*/
35-
public function getErrorName();
35+
public function getError();
3636

3737
/**
3838
* A user-friendly error description
3939
*
4040
* @return string
4141
*/
42-
public function getErrorFormatted();
42+
public function getUserMessage();
4343
}

src/GoneHttpException.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ class GoneHttpException extends HttpException
1414
/**
1515
* Error code storage;
1616
*
17-
* @var string
17+
* @const string
1818
*/
19-
protected $error_name = 'gone';
19+
const ERROR = 'gone';
2020

2121
/**
22-
* NotFoundHttpException constructor.
22+
* GoneHttpException constructor.
2323
*
24-
* @param string $message
25-
* @param string $error_formatted
26-
* @param array $error_data
27-
* @param array $headers
28-
* @param \Exception $previous
24+
* @param string|null $errorDescription
25+
* @param array $errorData
26+
* @param string|null $userTitle
27+
* @param null $userMessage
28+
* @param array $headers
29+
* @param \Exception|null $previous
2930
*/
30-
public function __construct($message = null, array $error_data = [], $error_formatted = null, array $headers = [], \Exception $previous = null)
31+
public function __construct(string $errorDescription = null, array $errorData = [], string $userTitle = null, $userMessage = null, array $headers = [], \Exception $previous = null)
3132
{
32-
parent::__construct($message, $error_formatted, $error_data, $headers, self::HTTP_CODE, $previous);
33+
parent::__construct(self::HTTP_CODE, self::ERROR, $errorDescription, $errorData, $userTitle, $userMessage, $headers, $previous);
3334
}
3435
}

0 commit comments

Comments
 (0)