Skip to content

Commit

Permalink
Fix CS in src/Server
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Oct 5, 2018
1 parent a95d2ad commit 7ba98ce
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 47 deletions.
54 changes: 37 additions & 17 deletions src/Server/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use GraphQL\Language\Parser;
use GraphQL\Utils\AST;
use GraphQL\Utils\Utils;
use JsonSerializable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
Expand Down Expand Up @@ -52,9 +53,11 @@ class Helper
*
* For PSR-7 request parsing use `parsePsrRequest()` instead.
*
* @api
* @return OperationParams|OperationParams[]
*
* @throws RequestError
*
* @api
*/
public function parseHttpRequest(?callable $readRawBodyFn = null)
{
Expand Down Expand Up @@ -104,12 +107,15 @@ public function parseHttpRequest(?callable $readRawBodyFn = null)
*
* Returned value is a suitable input for `executeOperation` or `executeBatch` (if array)
*
* @api
* @param string $method
* @param mixed[] $bodyParams
* @param mixed[] $queryParams
*
* @return OperationParams|OperationParams[]
*
* @throws RequestError
*
* @api
*/
public function parseRequestParams($method, array $bodyParams, array $queryParams)
{
Expand All @@ -136,8 +142,9 @@ public function parseRequestParams($method, array $bodyParams, array $queryParam
* Checks validity of OperationParams extracted from HTTP request and returns an array of errors
* if params are invalid (or empty array when params are valid)
*
* @api
* @return Error[]
*
* @api
*/
public function validateOperationParams(OperationParams $params)
{
Expand Down Expand Up @@ -185,9 +192,9 @@ public function validateOperationParams(OperationParams $params)
* Executes GraphQL operation with given server configuration and returns execution result
* (or promise when promise adapter is different from SyncPromiseAdapter)
*
* @api
*
* @return ExecutionResult|Promise
*
* @api
*/
public function executeOperation(ServerConfig $config, OperationParams $op)
{
Expand All @@ -205,9 +212,11 @@ public function executeOperation(ServerConfig $config, OperationParams $op)
* Executes batched GraphQL operations with shared promise queue
* (thus, effectively batching deferreds|promises of all queries at once)
*
* @api
* @param OperationParams[] $operations
*
* @return ExecutionResult|ExecutionResult[]|Promise
*
* @api
*/
public function executeBatch(ServerConfig $config, array $operations)
{
Expand All @@ -230,6 +239,7 @@ public function executeBatch(ServerConfig $config, array $operations)

/**
* @param bool $isBatch
*
* @return Promise
*/
private function promiseToExecuteOperation(
Expand All @@ -252,7 +262,7 @@ private function promiseToExecuteOperation(
if (! empty($errors)) {
$errors = Utils::map(
$errors,
function (RequestError $err) {
static function (RequestError $err) {
return Error::createLocatedError($err, null, null);
}
);
Expand Down Expand Up @@ -294,7 +304,7 @@ function (RequestError $err) {
);
}

$applyErrorHandling = function (ExecutionResult $result) use ($config) {
$applyErrorHandling = static function (ExecutionResult $result) use ($config) {
if ($config->getErrorsHandler()) {
$result->setErrorsHandler($config->getErrorsHandler());
}
Expand All @@ -315,6 +325,7 @@ function (RequestError $err) {

/**
* @return mixed
*
* @throws RequestError
*/
private function loadPersistedQuery(ServerConfig $config, OperationParams $operationParams)
Expand All @@ -341,6 +352,7 @@ private function loadPersistedQuery(ServerConfig $config, OperationParams $opera

/**
* @param string $operationType
*
* @return mixed[]|null
*/
private function resolveValidationRules(
Expand Down Expand Up @@ -368,13 +380,14 @@ private function resolveValidationRules(

/**
* @param string $operationType
*
* @return mixed
*/
private function resolveRootValue(ServerConfig $config, OperationParams $params, DocumentNode $doc, $operationType)
{
$root = $config->getRootValue();

if ($root instanceof \Closure) {
if (is_callable($root)) {
$root = $root($params, $doc, $operationType);
}

Expand All @@ -383,6 +396,7 @@ private function resolveRootValue(ServerConfig $config, OperationParams $params,

/**
* @param string $operationType
*
* @return mixed
*/
private function resolveContextValue(
Expand All @@ -393,7 +407,7 @@ private function resolveContextValue(
) {
$context = $config->getContext();

if ($context instanceof \Closure) {
if (is_callable($context)) {
$context = $context($params, $doc, $operationType);
}

Expand All @@ -403,9 +417,10 @@ private function resolveContextValue(
/**
* Send response using standard PHP `header()` and `echo`.
*
* @api
* @param Promise|ExecutionResult|ExecutionResult[] $result
* @param bool $exitWhenDone
*
* @api
*/
public function sendResponse($result, $exitWhenDone = false)
{
Expand All @@ -425,9 +440,9 @@ private function doSendResponse($result, $exitWhenDone)
}

/**
* @param mixed[]|\JsonSerializable $jsonSerializable
* @param int $httpStatus
* @param bool $exitWhenDone
* @param mixed[]|JsonSerializable $jsonSerializable
* @param int $httpStatus
* @param bool $exitWhenDone
*/
public function emitResponse($jsonSerializable, $httpStatus, $exitWhenDone)
{
Expand All @@ -450,14 +465,15 @@ private function readRawBody()

/**
* @param ExecutionResult|mixed[] $result
*
* @return int
*/
private function resolveHttpStatus($result)
{
if (is_array($result) && isset($result[0])) {
Utils::each(
$result,
function ($executionResult, $index) {
static function ($executionResult, $index) {
if (! $executionResult instanceof ExecutionResult) {
throw new InvariantViolation(sprintf(
'Expecting every entry of batched query result to be instance of %s but entry at position %d is %s',
Expand Down Expand Up @@ -490,9 +506,11 @@ function ($executionResult, $index) {
/**
* Converts PSR-7 request to OperationParams[]
*
* @api
* @return OperationParams[]|OperationParams
*
* @throws RequestError
*
* @api
*/
public function parsePsrRequest(ServerRequestInterface $request)
{
Expand Down Expand Up @@ -541,9 +559,11 @@ public function parsePsrRequest(ServerRequestInterface $request)
/**
* Converts query execution result to PSR-7 response
*
* @api
* @param Promise|ExecutionResult|ExecutionResult[] $result
*
* @return Promise|ResponseInterface
*
* @api
*/
public function toPsrResponse($result, ResponseInterface $response, StreamInterface $writableBodyStream)
{
Expand Down
11 changes: 8 additions & 3 deletions src/Server/OperationParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ class OperationParams
/**
* Creates an instance from given array
*
* @api
* @param mixed[] $params
* @param bool $readonly
*
* @return OperationParams
*
* @api
*/
public static function create(array $params, $readonly = false)
{
Expand Down Expand Up @@ -97,9 +99,11 @@ public static function create(array $params, $readonly = false)
}

/**
* @api
* @param string $key
*
* @return mixed
*
* @api
*/
public function getOriginalInput($key)
{
Expand All @@ -110,8 +114,9 @@ public function getOriginalInput($key)
* Indicates that operation is executed in read-only context
* (e.g. via HTTP GET request)
*
* @api
* @return bool
*
* @api
*/
public function isReadOnly()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Server/RequestError.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace GraphQL\Server;

use Exception;
use GraphQL\Error\ClientAware;

class RequestError extends \Exception implements ClientAware
class RequestError extends Exception implements ClientAware
{
/**
* Returns true when exception message is safe to be displayed to client
Expand Down
Loading

0 comments on commit 7ba98ce

Please sign in to comment.