Remove code parameter from HTTPException constructor

- Remove duplicate HTTPException->httpcode class variable
This commit is contained in:
Hypolite Petovan 2019-05-01 21:24:51 -04:00
parent 07cb887885
commit 8eba329111
24 changed files with 60 additions and 29 deletions

View File

@ -3,7 +3,7 @@
/**
* Throwable exceptions to return HTTP status code
*
* This list of Exception has be extracted from
* This list of Exception has been extracted from
* here http://racksburg.com/choosing-an-http-status-code/
*/
@ -11,17 +11,17 @@ namespace Friendica\Network;
use Exception;
class HTTPException extends Exception
abstract class HTTPException extends Exception
{
var $httpcode = 200;
var $httpdesc = "";
public $httpdesc = '';
public function __construct($message = '', $code = 0, Exception $previous = null)
public function __construct($message = '', Exception $previous = null)
{
if ($this->httpdesc == '') {
parent::__construct($message, $this->code, $previous);
if (empty($this->httpdesc)) {
$classname = str_replace('Exception', '', str_replace('Friendica\Network\HTTPException\\', '', get_class($this)));
$this->httpdesc = preg_replace("|([a-z])([A-Z])|",'$1 $2', $classname);
}
parent::__construct($message, $code, $previous);
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException;
class AcceptedException extends HTTPException
{
protected $code = 202;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class BadGatewayException extends HTTPException
{
var $httpcode = 502;
protected $code = 502;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class BadRequestException extends HTTPException
{
var $httpcode = 400;
protected $code = 400;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class ConflictException extends HTTPException
{
var $httpcode = 409;
protected $code = 409;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class ExpectationFailedException extends HTTPException
{
var $httpcode = 417;
protected $code = 417;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class ForbiddenException extends HTTPException
{
var $httpcode = 403;
}
protected $code = 403;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class GatewayTimeoutException extends HTTPException
{
var $httpcode = 504;
protected $code = 504;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class GoneException extends HTTPException
{
var $httpcode = 410;
protected $code = 410;
}

View File

@ -6,6 +6,6 @@ use Friendica\Network\HTTPException;
class ImATeapotException extends HTTPException
{
var $httpcode = 418;
protected $code = 418;
var $httpdesc = "I'm A Teapot";
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class InternalServerErrorException extends HTTPException
{
var $httpcode = 500;
protected $code = 500;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class LenghtRequiredException extends HTTPException
{
var $httpcode = 411;
protected $code = 411;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class MethodNotAllowedException extends HTTPException
{
var $httpcode = 405;
protected $code = 405;
}

View File

@ -0,0 +1,10 @@
<?php
namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException;
class NoContentException extends HTTPException
{
protected $code = 204;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class NonAcceptableException extends HTTPException
{
var $httpcode = 406;
protected $code = 406;
}

View File

@ -4,6 +4,7 @@ namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException;
class NotFoundException extends HTTPException {
var $httpcode = 404;
class NotFoundException extends HTTPException
{
protected $code = 404;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class NotImplementedException extends HTTPException
{
var $httpcode = 501;
protected $code = 501;
}

View File

@ -0,0 +1,10 @@
<?php
namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException;
class OKException extends HTTPException
{
protected $code = 200;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class PreconditionFailedException extends HTTPException
{
var $httpcode = 412;
protected $code = 412;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class ServiceUnavaiableException extends HTTPException
{
var $httpcode = 503;
protected $code = 503;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class TooManyRequestsException extends HTTPException
{
var $httpcode = 429;
protected $code = 429;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class UnauthorizedException extends HTTPException
{
var $httpcode = 401;
protected $code = 401;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class UnprocessableEntityException extends HTTPException
{
var $httpcode = 422;
protected $code = 422;
}

View File

@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
class UnsupportedMediaTypeException extends HTTPException
{
var $httpcode = 415;
protected $code = 415;
}