Remove code parameter from HTTPException constructor
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 2 May 2019 01:24:51 +0000 (21:24 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 2 May 2019 15:26:55 +0000 (11:26 -0400)
- Remove duplicate HTTPException->httpcode class variable

24 files changed:
src/Network/HTTPException.php
src/Network/HTTPException/AcceptedException.php [new file with mode: 0644]
src/Network/HTTPException/BadGatewayException.php
src/Network/HTTPException/BadRequestException.php
src/Network/HTTPException/ConflictException.php
src/Network/HTTPException/ExpectationFailedException.php
src/Network/HTTPException/ForbiddenException.php
src/Network/HTTPException/GatewayTimeoutException.php
src/Network/HTTPException/GoneException.php
src/Network/HTTPException/ImATeapotException.php
src/Network/HTTPException/InternalServerErrorException.php
src/Network/HTTPException/LenghtRequiredException.php
src/Network/HTTPException/MethodNotAllowedException.php
src/Network/HTTPException/NoContentException.php [new file with mode: 0644]
src/Network/HTTPException/NonAcceptableException.php
src/Network/HTTPException/NotFoundException.php
src/Network/HTTPException/NotImplementedException.php
src/Network/HTTPException/OKException.php [new file with mode: 0644]
src/Network/HTTPException/PreconditionFailedException.php
src/Network/HTTPException/ServiceUnavaiableException.php
src/Network/HTTPException/TooManyRequestsException.php
src/Network/HTTPException/UnauthorizedException.php
src/Network/HTTPException/UnprocessableEntityException.php
src/Network/HTTPException/UnsupportedMediaTypeException.php

index b9bad45..89c447b 100644 (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);
        }
 }
diff --git a/src/Network/HTTPException/AcceptedException.php b/src/Network/HTTPException/AcceptedException.php
new file mode 100644 (file)
index 0000000..b8c843e
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class AcceptedException extends HTTPException
+{
+       protected $code = 202;
+}
index 6fc80c9..c23d7e5 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class BadGatewayException extends HTTPException
 {
-       var $httpcode = 502;
+       protected $code = 502;
 }
index dd1dc19..9f25c61 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class BadRequestException extends HTTPException
 {
-       var $httpcode = 400;
+       protected $code = 400;
 }
index 1d5053c..5d63922 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class ConflictException extends HTTPException
 {
-       var $httpcode = 409;
+       protected $code = 409;
 }
index fe932a9..7c928f3 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class ExpectationFailedException extends HTTPException
 {
-       var $httpcode = 417;
+       protected $code = 417;
 }
index 66a063e..f83fe52 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class ForbiddenException extends HTTPException
 {
-       var $httpcode = 403;
-}
\ No newline at end of file
+       protected $code = 403;
+}
index bcd9808..2e51648 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class GatewayTimeoutException extends HTTPException
 {
-       var $httpcode = 504;
+       protected $code = 504;
 }
index 42e19e8..0f66520 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class GoneException extends HTTPException
 {
-       var $httpcode = 410;
+       protected $code = 410;
 }
index f4eea40..89a28be 100644 (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";
 }
index c049ef2..dca1894 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class InternalServerErrorException extends HTTPException
 {
-       var $httpcode = 500;
+       protected $code = 500;
 }
index 1f2f0f1..071cac7 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class LenghtRequiredException extends HTTPException
 {
-       var $httpcode = 411;
+       protected $code = 411;
 }
index 82fd3e7..128b9dc 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class MethodNotAllowedException extends HTTPException
 {
-       var $httpcode = 405;
+       protected $code = 405;
 }
diff --git a/src/Network/HTTPException/NoContentException.php b/src/Network/HTTPException/NoContentException.php
new file mode 100644 (file)
index 0000000..7bd60fb
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class NoContentException extends HTTPException
+{
+       protected $code = 204;
+}
index 356bc0c..9ef40d6 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class NonAcceptableException extends HTTPException
 {
-       var $httpcode = 406;
+       protected $code = 406;
 }
index 2d24cce..f581794 100644 (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;
 }
index c0dc21c..76cb5d4 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class NotImplementedException extends HTTPException
 {
-       var $httpcode = 501;
+       protected $code = 501;
 }
diff --git a/src/Network/HTTPException/OKException.php b/src/Network/HTTPException/OKException.php
new file mode 100644 (file)
index 0000000..d506ddf
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+
+namespace Friendica\Network\HTTPException;
+
+use Friendica\Network\HTTPException;
+
+class OKException extends HTTPException
+{
+       protected $code = 200;
+}
index fd5fdbc..325c88a 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class PreconditionFailedException extends HTTPException
 {
-       var $httpcode = 412;
+       protected $code = 412;
 }
index 9270bc4..6c0e659 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class ServiceUnavaiableException extends HTTPException
 {
-       var $httpcode = 503;
+       protected $code = 503;
 }
index 093911f..e06d9d9 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class TooManyRequestsException extends HTTPException
 {
-       var $httpcode = 429;
+       protected $code = 429;
 }
index a3015d4..eda1f07 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class UnauthorizedException extends HTTPException
 {
-       var $httpcode = 401;
+       protected $code = 401;
 }
index 02852e2..b33a75f 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class UnprocessableEntityException extends HTTPException
 {
-       var $httpcode = 422;
+       protected $code = 422;
 }
index b039901..02962df 100644 (file)
@@ -6,5 +6,5 @@ use Friendica\Network\HTTPException;
 
 class UnsupportedMediaTypeException extends HTTPException
 {
-       var $httpcode = 415;
+       protected $code = 415;
 }