Refactored HttpExceptions.

This commit is contained in:
Dmitry Khomutov 2018-03-04 17:14:09 +07:00
parent 69e969436d
commit aadfabd714
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
27 changed files with 54 additions and 57 deletions

View file

@ -1,9 +0,0 @@
<?php
namespace b8\Exception\HttpException;
use b8\Exception\HttpException;
class ServerErrorException extends HttpException
{
}

View file

@ -2,11 +2,11 @@
namespace PHPCensor; namespace PHPCensor;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
use b8\Http\Response; use b8\Http\Response;
use b8\Http\Response\RedirectResponse; use b8\Http\Response\RedirectResponse;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use b8\Exception\HttpException\NotFoundException; use PHPCensor\Exception\HttpException\NotFoundException;
use b8\Http\Request; use b8\Http\Request;
use b8\Http\Router; use b8\Http\Router;

View file

@ -2,7 +2,7 @@
namespace PHPCensor; namespace PHPCensor;
use b8\Exception\HttpException\ForbiddenException; use PHPCensor\Exception\HttpException\ForbiddenException;
use b8\Http\Request; use b8\Http\Request;
use b8\Http\Response; use b8\Http\Response;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;

View file

@ -2,8 +2,7 @@
namespace PHPCensor\Controller; namespace PHPCensor\Controller;
use b8; use PHPCensor\Exception\HttpException\NotFoundException;
use b8\Exception\HttpException\NotFoundException;
use b8\Http\Response\JsonResponse; use b8\Http\Response\JsonResponse;
use JasonGrimes\Paginator; use JasonGrimes\Paginator;
use PHPCensor\BuildFactory; use PHPCensor\BuildFactory;

View file

@ -2,8 +2,9 @@
namespace PHPCensor\Controller; namespace PHPCensor\Controller;
use b8; use b8\Http\Response;
use b8\Exception\HttpException\NotFoundException; use b8\Http\Response\RedirectResponse;
use PHPCensor\Exception\HttpException\NotFoundException;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\BuildFactory; use PHPCensor\BuildFactory;
use PHPCensor\Model\Project; use PHPCensor\Model\Project;
@ -76,7 +77,6 @@ class BuildStatusController extends Controller
* @return bool * @return bool
* *
* @throws \Exception * @throws \Exception
* @throws b8\Exception\HttpException
*/ */
public function ccxml($projectId) public function ccxml($projectId)
{ {
@ -131,7 +131,7 @@ class BuildStatusController extends Controller
* *
* @param $projectId * @param $projectId
* *
* @return b8\Http\Response|b8\Http\Response\RedirectResponse * @return Response
*/ */
public function image($projectId) public function image($projectId)
{ {
@ -149,7 +149,7 @@ class BuildStatusController extends Controller
$status = $this->getStatus($projectId); $status = $this->getStatus($projectId);
if (is_null($status)) { if (is_null($status)) {
$response = new b8\Http\Response\RedirectResponse(); $response = new RedirectResponse();
$response->setHeader('Location', '/'); $response->setHeader('Location', '/');
return $response; return $response;
@ -182,6 +182,7 @@ class BuildStatusController extends Controller
$this->response->disableLayout(); $this->response->disableLayout();
$this->response->setHeader('Content-Type', 'image/svg+xml'); $this->response->setHeader('Content-Type', 'image/svg+xml');
$this->response->setContent($image); $this->response->setContent($image);
return $this->response; return $this->response;
} }
@ -192,7 +193,7 @@ class BuildStatusController extends Controller
* *
* @return string * @return string
* *
* @throws \b8\Exception\HttpException\NotFoundException * @throws NotFoundException
*/ */
public function view($projectId) public function view($projectId)
{ {

View file

@ -2,8 +2,7 @@
namespace PHPCensor\Controller; namespace PHPCensor\Controller;
use b8; use PHPCensor\Exception\HttpException\NotFoundException;
use b8\Exception\HttpException\NotFoundException;
use b8\Form; use b8\Form;
use JasonGrimes\Paginator; use JasonGrimes\Paginator;
use PHPCensor; use PHPCensor;

View file

@ -3,7 +3,7 @@
namespace PHPCensor\Controller; namespace PHPCensor\Controller;
use PHPCensor\Config; use PHPCensor\Config;
use b8\Exception\HttpException\NotFoundException; use PHPCensor\Exception\HttpException\NotFoundException;
use b8\Form; use b8\Form;
use PHPCensor\Controller; use PHPCensor\Controller;
use PHPCensor\Helper\Lang; use PHPCensor\Helper\Lang;

View file

@ -2,7 +2,6 @@
namespace PHPCensor\Controller; namespace PHPCensor\Controller;
use b8;
use Exception; use Exception;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use PHPCensor\Helper\Lang; use PHPCensor\Helper\Lang;
@ -13,7 +12,7 @@ use PHPCensor\Store\BuildStore;
use PHPCensor\Store\ProjectStore; use PHPCensor\Store\ProjectStore;
use PHPCensor\Controller; use PHPCensor\Controller;
use PHPCensor\Config; use PHPCensor\Config;
use b8\Exception\HttpException\NotFoundException; use PHPCensor\Exception\HttpException\NotFoundException;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use b8\Http\Request; use b8\Http\Request;
use b8\Http\Response; use b8\Http\Response;
@ -75,7 +74,7 @@ class WebhookController extends Controller
*/ */
public function handleAction($action, $actionParams) public function handleAction($action, $actionParams)
{ {
$response = new b8\Http\Response\JsonResponse(); $response = new Response\JsonResponse();
try { try {
$data = call_user_func_array([$this, $action], $actionParams); $data = call_user_func_array([$this, $action], $actionParams);
if (isset($data['responseCode'])) { if (isset($data['responseCode'])) {

View file

@ -1,6 +1,6 @@
<?php <?php
namespace b8\Exception; namespace PHPCensor\Exception;
class HttpException extends \Exception class HttpException extends \Exception
{ {

View file

@ -1,8 +1,8 @@
<?php <?php
namespace b8\Exception\HttpException; namespace PHPCensor\Exception\HttpException;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
class BadRequestException extends HttpException class BadRequestException extends HttpException
{ {

View file

@ -1,8 +1,8 @@
<?php <?php
namespace b8\Exception\HttpException; namespace PHPCensor\Exception\HttpException;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
class ForbiddenException extends HttpException class ForbiddenException extends HttpException
{ {

View file

@ -1,8 +1,8 @@
<?php <?php
namespace b8\Exception\HttpException; namespace PHPCensor\Exception\HttpException;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
class NotAuthorizedException extends HttpException class NotAuthorizedException extends HttpException
{ {

View file

@ -1,8 +1,8 @@
<?php <?php
namespace b8\Exception\HttpException; namespace PHPCensor\Exception\HttpException;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
class NotFoundException extends HttpException class NotFoundException extends HttpException
{ {

View file

@ -0,0 +1,9 @@
<?php
namespace PHPCensor\Exception\HttpException;
use PHPCensor\Exception\HttpException;
class ServerErrorException extends HttpException
{
}

View file

@ -1,8 +1,8 @@
<?php <?php
namespace b8\Exception\HttpException; namespace PHPCensor\Exception\HttpException;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
class ValidationException extends HttpException class ValidationException extends HttpException
{ {

View file

@ -2,7 +2,7 @@
namespace PHPCensor; namespace PHPCensor;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException\ValidationException;
class Model class Model
{ {
@ -87,12 +87,12 @@ class Model
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
* *
* @throws HttpException\ValidationException * @throws ValidationException
*/ */
protected function validateString($name, $value) protected function validateString($name, $value)
{ {
if (!is_string($value) && !is_null($value)) { if (!is_string($value) && !is_null($value)) {
throw new HttpException\ValidationException('Column "' . $name . '" must be a string.'); throw new ValidationException('Column "' . $name . '" must be a string.');
} }
} }
@ -100,12 +100,12 @@ class Model
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
* *
* @throws HttpException\ValidationException * @throws ValidationException
*/ */
protected function validateInt($name, $value) protected function validateInt($name, $value)
{ {
if (!is_integer($value) && !is_null($value)) { if (!is_integer($value) && !is_null($value)) {
throw new HttpException\ValidationException('Column "' . $name . '" must be an integer.'); throw new ValidationException('Column "' . $name . '" must be an integer.');
} }
} }
@ -113,12 +113,12 @@ class Model
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
* *
* @throws HttpException\ValidationException * @throws ValidationException
*/ */
protected function validateNotNull($name, $value) protected function validateNotNull($name, $value)
{ {
if (is_null($value)) { if (is_null($value)) {
throw new HttpException\ValidationException('Column "' . $name . '" must not be null.'); throw new ValidationException('Column "' . $name . '" must not be null.');
} }
} }
} }

View file

@ -4,7 +4,7 @@ namespace PHPCensor\Store;
use PHPCensor\Database; use PHPCensor\Database;
use PHPCensor\Model\BuildError; use PHPCensor\Model\BuildError;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
use PHPCensor\Store; use PHPCensor\Store;
class BuildErrorStore extends Store class BuildErrorStore extends Store

View file

@ -5,7 +5,7 @@ namespace PHPCensor\Store;
use PHPCensor\Store; use PHPCensor\Store;
use PHPCensor\Database; use PHPCensor\Database;
use PHPCensor\Model\BuildMeta; use PHPCensor\Model\BuildMeta;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
class BuildMetaStore extends Store class BuildMetaStore extends Store
{ {

View file

@ -4,7 +4,7 @@ namespace PHPCensor\Store;
use PHPCensor\Database; use PHPCensor\Database;
use PHPCensor\Model\Build; use PHPCensor\Model\Build;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
use PHPCensor\Model\BuildMeta; use PHPCensor\Model\BuildMeta;
use PHPCensor\Store; use PHPCensor\Store;

View file

@ -5,7 +5,7 @@ namespace PHPCensor\Store;
use PHPCensor\Database; use PHPCensor\Database;
use PHPCensor\Model\Environment; use PHPCensor\Model\Environment;
use PHPCensor\Store; use PHPCensor\Store;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
class EnvironmentStore extends Store class EnvironmentStore extends Store
{ {

View file

@ -3,7 +3,7 @@
namespace PHPCensor\Store; namespace PHPCensor\Store;
use PHPCensor\Database; use PHPCensor\Database;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
use PHPCensor\Store; use PHPCensor\Store;
use PHPCensor\Model\ProjectGroup; use PHPCensor\Model\ProjectGroup;

View file

@ -5,7 +5,7 @@ namespace PHPCensor\Store;
use PHPCensor\Database; use PHPCensor\Database;
use PHPCensor\Model\Project; use PHPCensor\Model\Project;
use PHPCensor\Store; use PHPCensor\Store;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
/** /**
* @author Dan Cryer <dan@block8.co.uk> * @author Dan Cryer <dan@block8.co.uk>

View file

@ -4,7 +4,7 @@ namespace PHPCensor\Store;
use PHPCensor\Store; use PHPCensor\Store;
use PHPCensor\Database; use PHPCensor\Database;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
use PHPCensor\Model\User; use PHPCensor\Model\User;
/** /**

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Tests\b8; namespace Tests\PHPCensor;
use PHPCensor\Config; use PHPCensor\Config;
use PHPCensor\Database; use PHPCensor\Database;

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Tests\b8; namespace Tests\PHPCensor;
use PHPCensor\Config; use PHPCensor\Config;
use PHPCensor\Database; use PHPCensor\Database;

View file

@ -1,8 +1,8 @@
<?php <?php
namespace Tests\b8; namespace Tests\PHPCensor;
use b8\Exception\HttpException; use PHPCensor\Exception\HttpException;
class HttpExceptionTest extends \PHPUnit\Framework\TestCase class HttpExceptionTest extends \PHPUnit\Framework\TestCase
{ {

View file

@ -2,9 +2,8 @@
namespace Tests\PHPCensor\Model; namespace Tests\PHPCensor\Model;
use b8\Exception\HttpException\ValidationException; use PHPCensor\Exception\HttpException\ValidationException;
use PHPCensor\Model\Build; use PHPCensor\Model\Build;
use PHPCensor\Model;
/** /**
* Unit tests for the Build model class. * Unit tests for the Build model class.