Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from StyleCI #19

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Auth/ApiGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
use Illuminate\Http\Request;

/**
* Class ApiGuard
* @package Napp\Core\Api\Auth
* Class ApiGuard.
*/
class ApiGuard extends TokenGuard
{
/**
* @param UserProvider $provider
* @param Request $request
* @param Request $request
*/
public function __construct(UserProvider $provider, Request $request)
{
Expand All @@ -25,6 +24,7 @@ public function __construct(UserProvider $provider, Request $request)

/**
* @param array $credentials
*
* @return bool
*/
public function attempt(array $credentials = []): bool
Expand Down
3 changes: 1 addition & 2 deletions src/Auth/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
use Illuminate\Support\ServiceProvider;

/**
* Class AuthServiceProvider
* @package Napp\Core\Api\Auth
* Class AuthServiceProvider.
*/
class AuthServiceProvider extends ServiceProvider
{
Expand Down
3 changes: 1 addition & 2 deletions src/Auth/NappHttpHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace Napp\Core\Api\Auth;

/**
* Class NappHttpHeaders
* @package Napp\Core\Api\Auth
* Class NappHttpHeaders.
*/
class NappHttpHeaders
{
Expand Down
46 changes: 35 additions & 11 deletions src/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
use Illuminate\Support\Facades\Response;

/**
* Class ApiController
* @package Napp\Core\Api\Controllers
* Class ApiController.
*/
class ApiController extends BaseController
{
Expand Down Expand Up @@ -40,6 +39,7 @@ public function getStatusCode()

/**
* @param int $code
*
* @return $this
*/
public function setStatusCode($code)
Expand All @@ -51,6 +51,7 @@ public function setStatusCode($code)

/**
* @param int $code
*
* @return $this
*/
public function setResponseCode($code)
Expand All @@ -62,6 +63,7 @@ public function setResponseCode($code)

/**
* @param string $currentETag
*
* @return JsonResponse
*/
public function checkETag($currentETag): ?JsonResponse
Expand All @@ -76,6 +78,7 @@ public function checkETag($currentETag): ?JsonResponse
/**
* @param array $data
* @param array $headers
*
* @return JsonResponse
*/
public function respond(array $data, array $headers = []): JsonResponse
Expand All @@ -86,6 +89,7 @@ public function respond(array $data, array $headers = []): JsonResponse
/**
* @param array $data
* @param array $headers
*
* @return JsonResponse
*/
public function respondWithSingleObject(array $data, array $headers = []): JsonResponse
Expand All @@ -95,21 +99,23 @@ public function respondWithSingleObject(array $data, array $headers = []): JsonR

/**
* @param string $message
*
* @return JsonResponse
*/
public function respondWithError(string $message): JsonResponse
{
return $this->respond([
'error' => [
'message' => $message,
'code' => $this->getStatusCode()
]
'code' => $this->getStatusCode(),
],
]);
}

/**
* @param array $data
* @param array $headers
*
* @return JsonResponse
*/
public function responseCreated(array $data, array $headers = []): JsonResponse
Expand All @@ -120,7 +126,8 @@ public function responseCreated(array $data, array $headers = []): JsonResponse

/**
* @param string $message
* @param array $headers
* @param array $headers
*
* @return JsonResponse
*/
public function responseNoContent(
Expand All @@ -130,24 +137,25 @@ public function responseNoContent(
return $this->setResponseCode(204)
->respond(['message' => $message], $headers);
}
/**

/**
* @param string $message
* @param array $headers
* @param array $headers
*
* @return JsonResponse
*/
public function responseAccepted(
string $message = 'The request was accepted for processing',
array $headers = []
): JsonResponse {

return $this->setResponseCode(202)
->setStatusCode(224)
->respond(['message' => $message], $headers);
}

/**
* @param array $headers
*
* @return JsonResponse
*/
public function responseNotModified(array $headers = []): JsonResponse
Expand All @@ -158,6 +166,7 @@ public function responseNotModified(array $headers = []): JsonResponse

/**
* @param string $message
*
* @return \Illuminate\Http\JsonResponse
*/
public function responseBadRequest(string $message = 'The request failed due to an application error.'): JsonResponse
Expand All @@ -169,6 +178,7 @@ public function responseBadRequest(string $message = 'The request failed due to

/**
* @param string $message
*
* @return JsonResponse
*/
public function responseValidationFailed(string $message = 'Validation error.'): JsonResponse
Expand All @@ -180,6 +190,7 @@ public function responseValidationFailed(string $message = 'Validation error.'):

/**
* @param string $message
*
* @return JsonResponse
*/
public function responseUnprocessableEntity(string $message = 'The request was well-formed but was unable to be followed due to semantic errors.'): JsonResponse
Expand All @@ -191,6 +202,7 @@ public function responseUnprocessableEntity(string $message = 'The request was w

/**
* @param string $message
*
* @return JsonResponse
*/
public function responseUnauthorized(string $message = 'Authentication credentials were missing or incorrect.'): JsonResponse
Expand All @@ -202,6 +214,7 @@ public function responseUnauthorized(string $message = 'Authentication credentia

/**
* @param string $message
*
* @return JsonResponse
*/
public function responseUnauthorization(string $message = 'Authorization error. Requested resource is restricted.'): JsonResponse
Expand All @@ -213,6 +226,7 @@ public function responseUnauthorization(string $message = 'Authorization error.

/**
* @param string $message
*
* @return JsonResponse
*/
public function responseForbidden(string $message = 'Forbidden.'): JsonResponse
Expand All @@ -224,6 +238,7 @@ public function responseForbidden(string $message = 'Forbidden.'): JsonResponse

/**
* @param string $message
*
* @return JsonResponse
*/
public function responseNotFound(string $message = 'Not found.'): JsonResponse
Expand All @@ -235,6 +250,7 @@ public function responseNotFound(string $message = 'Not found.'): JsonResponse

/**
* @param string $message
*
* @return JsonResponse
*/
public function responseClientNotFound(string $message = 'Client not found.'): JsonResponse
Expand All @@ -246,6 +262,7 @@ public function responseClientNotFound(string $message = 'Client not found.'): J

/**
* @param string $message
*
* @return JsonResponse
*/
public function responseInternalServerError(string $message = 'Internal Server Error.'): JsonResponse
Expand All @@ -257,6 +274,7 @@ public function responseInternalServerError(string $message = 'Internal Server E

/**
* @param string $message
*
* @return JsonResponse
*/
public function responseNotImplemented(string $message = 'The request has not been implemented.'): JsonResponse
Expand All @@ -268,6 +286,7 @@ public function responseNotImplemented(string $message = 'The request has not be

/**
* @param string $message
*
* @return JsonResponse
*/
public function responseServiceUnavailable(string $message = 'Service Unavailable.'): JsonResponse
Expand All @@ -279,6 +298,7 @@ public function responseServiceUnavailable(string $message = 'Service Unavailabl

/**
* @param string $message
*
* @return JsonResponse
*/
public function responseHTTPVersionNotSupported(string $message = 'This is returned if you use the HTTP protocol.'): JsonResponse
Expand All @@ -290,6 +310,7 @@ public function responseHTTPVersionNotSupported(string $message = 'This is retur

/**
* @param Request $request
*
* @return int
*/
public function getLimit(Request $request): int
Expand All @@ -305,6 +326,7 @@ public function getLimit(Request $request): int

/**
* @param Request $request
*
* @return int
*/
protected function getOffset(Request $request): int
Expand All @@ -313,9 +335,10 @@ protected function getOffset(Request $request): int
}

/**
* Get the page for pagination
* Get the page for pagination.
*
* @param Request $request
*
* @return int
*/
public function getPage(Request $request): int
Expand All @@ -324,9 +347,10 @@ public function getPage(Request $request): int
}

/**
* Get the page size for pagination
* Get the page size for pagination.
*
* @param Request $request
*
* @return int
*/
public function getPageSize(Request $request): int
Expand Down
30 changes: 18 additions & 12 deletions src/Controllers/ApiInternalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
use Illuminate\Auth\AuthManager;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Napp\Core\Api\Auth\NappHttpHeaders;
use Napp\Core\Api\Exceptions\Exceptions\ApiInternalCallException;
use Napp\Core\Api\Router\Router;
use Napp\Core\Api\Auth\NappHttpHeaders;

/**
* Class ApiInternalController
* @package Napp\Core\Api\Controllers
* Class ApiInternalController.
*/
class ApiInternalController extends BaseController
{
Expand All @@ -27,7 +26,7 @@ class ApiInternalController extends BaseController

/**
* @param AuthManager $auth
* @param Router $router
* @param Router $router
*/
public function __construct(AuthManager $auth, Router $router)
{
Expand All @@ -45,7 +44,8 @@ public function getInternalRouter(): Router

/**
* @param string $uri
* @param array $headers
* @param array $headers
*
* @return array
*/
public function get(string $uri, array $headers = []): array
Expand All @@ -57,8 +57,9 @@ public function get(string $uri, array $headers = []): array

/**
* @param string $uri
* @param array $data
* @param array $headers
* @param array $data
* @param array $headers
*
* @return array
*/
public function post(string $uri, array $data, array $headers = []): array
Expand All @@ -70,8 +71,9 @@ public function post(string $uri, array $data, array $headers = []): array

/**
* @param string $uri
* @param array $data
* @param array $headers
* @param array $data
* @param array $headers
*
* @return array
*/
public function put(string $uri, array $data, array $headers = []): array
Expand All @@ -83,7 +85,8 @@ public function put(string $uri, array $data, array $headers = []): array

/**
* @param string $uri
* @param array $headers
* @param array $headers
*
* @return array
*/
public function delete(string $uri, array $headers = []): array
Expand All @@ -95,20 +98,23 @@ public function delete(string $uri, array $headers = []): array

/**
* @param array $headers
*
* @return array
*/
protected function getInternalCallHeaders(array $headers): array
{
return array_merge($headers, [
NappHttpHeaders::NAPP_API_CALL_TYPE => 'internal',
NappHttpHeaders::NAPP_API_CALL_TYPE => 'internal',
NappHttpHeaders::NAPP_AUTH_GLOBAL_USER_ID => $this->auth->guard()->id(),
]);
}

/**
* @param Response|JsonResponse $response
* @return array
*
* @throws ApiInternalCallException
*
* @return array
*/
protected function formatResponse($response): array
{
Expand Down
Loading