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;
use b8\Exception\HttpException;
use PHPCensor\Exception\HttpException;
use b8\Http\Response;
use b8\Http\Response\RedirectResponse;
use PHPCensor\Store\Factory;
use b8\Exception\HttpException\NotFoundException;
use PHPCensor\Exception\HttpException\NotFoundException;
use b8\Http\Request;
use b8\Http\Router;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,8 +1,8 @@
<?php
namespace b8\Exception\HttpException;
namespace PHPCensor\Exception\HttpException;
use b8\Exception\HttpException;
use PHPCensor\Exception\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
namespace b8\Exception\HttpException;
namespace PHPCensor\Exception\HttpException;
use b8\Exception\HttpException;
use PHPCensor\Exception\HttpException;
class ValidationException extends HttpException
{

View file

@ -2,7 +2,7 @@
namespace PHPCensor;
use b8\Exception\HttpException;
use PHPCensor\Exception\HttpException\ValidationException;
class Model
{
@ -87,12 +87,12 @@ class Model
* @param string $name
* @param mixed $value
*
* @throws HttpException\ValidationException
* @throws ValidationException
*/
protected function validateString($name, $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 mixed $value
*
* @throws HttpException\ValidationException
* @throws ValidationException
*/
protected function validateInt($name, $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 mixed $value
*
* @throws HttpException\ValidationException
* @throws ValidationException
*/
protected function validateNotNull($name, $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\Model\BuildError;
use b8\Exception\HttpException;
use PHPCensor\Exception\HttpException;
use PHPCensor\Store;
class BuildErrorStore extends Store

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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