@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | try { |
| 19 | 19 | $response = $delegate->process($request); |
| 20 | - } catch(\Phrest\Http\Exception $e) { |
|
| 20 | + } catch (\Phrest\Http\Exception $e) { |
|
| 21 | 21 | $error = $e->error(); |
| 22 | 22 | |
| 23 | 23 | $errorEntries = []; |
| 24 | - foreach($error->errors() as $errorEntry) { |
|
| 24 | + foreach ($error->errors() as $errorEntry) { |
|
| 25 | 25 | /** @var \Phrest\API\ErrorEntry $errorEntry */ |
| 26 | 26 | $errorEntries[] = [ |
| 27 | 27 | 'code' => $errorEntry->code(), |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $e->getCode() |
| 45 | 45 | ); |
| 46 | 46 | |
| 47 | - $this->logger->info('Exception: '.$e->getMessage(), [ |
|
| 47 | + $this->logger->info('Exception: ' . $e->getMessage(), [ |
|
| 48 | 48 | 'exception' => get_class($e), |
| 49 | 49 | 'file' => $e->getFile(), |
| 50 | 50 | 'line' => $e->getLine(), |
@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public function process(\Psr\Http\Message\ServerRequestInterface $request, \Interop\Http\ServerMiddleware\DelegateInterface $delegate) |
| 17 | 17 | { |
| 18 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
| 19 | - if (! (error_reporting() & $errno)) { |
|
| 18 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
| 19 | + if (!(error_reporting() & $errno)) { |
|
| 20 | 20 | return; |
| 21 | 21 | } |
| 22 | 22 | throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | try { |
| 26 | 26 | $response = $delegate->process($request); |
| 27 | - if (! $response instanceof \Psr\Http\Message\ResponseInterface) { |
|
| 27 | + if (!$response instanceof \Psr\Http\Message\ResponseInterface) { |
|
| 28 | 28 | throw new \Phrest\Exception('Application did not return a response'); |
| 29 | 29 | } |
| 30 | 30 | } catch (\Throwable $e) { |
@@ -18,10 +18,10 @@ |
||
| 18 | 18 | const SEE_OTHER = 303; |
| 19 | 19 | const NOT_MODIFIED = 304; |
| 20 | 20 | const USE_PROXY = 305; |
| 21 | - const UNUSED= 306; |
|
| 21 | + const UNUSED = 306; |
|
| 22 | 22 | const TEMPORARY_REDIRECT = 307; |
| 23 | 23 | const BAD_REQUEST = 400; |
| 24 | - const UNAUTHORIZED = 401; |
|
| 24 | + const UNAUTHORIZED = 401; |
|
| 25 | 25 | const PAYMENT_REQUIRED = 402; |
| 26 | 26 | const FORBIDDEN = 403; |
| 27 | 27 | const NOT_FOUND = 404; |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | foreach ($parameters->getQueryParameters() as $parameterName => $parameter) { |
| 95 | 95 | $required = $parameter['required'] ?? false; |
| 96 | 96 | $value = $request->getQueryParams()[$parameterName] ?? ($parameter['default'] ?? null); |
| 97 | - if(!is_null($value) || $required) { |
|
| 97 | + if (!is_null($value) || $required) { |
|
| 98 | 98 | $errors = array_merge( |
| 99 | 99 | $errors, |
| 100 | 100 | $this->validateValueBySchema($value, $parameter, '{query}/' . $parameterName) |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | foreach ($parameters->getHeaderParameters() as $parameterName => $parameter) { |
| 109 | 109 | $required = $parameter['required'] ?? false; |
| 110 | 110 | $value = $request->getHeader($parameterName)[0] ?? ($parameter['default'] ?? null); |
| 111 | - if(!is_null($value) || $required) { |
|
| 111 | + if (!is_null($value) || $required) { |
|
| 112 | 112 | $errors = array_merge( |
| 113 | 113 | $errors, |
| 114 | 114 | $this->validateValueBySchema($value, $parameter, '{header}/' . $parameterName) |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | throw \Phrest\Http\Exception::BadRequest( |
| 146 | 146 | new \Phrest\API\Error( |
| 147 | 147 | \Phrest\API\ErrorCodes::REQUEST_PARAMETER_VALIDATION, |
| 148 | - 'request parameter validation failed. OperationId: '.$operationId, |
|
| 148 | + 'request parameter validation failed. OperationId: ' . $operationId, |
|
| 149 | 149 | ...$errors |
| 150 | 150 | ) |
| 151 | 151 | ); |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | |
| 25 | 25 | public function process(\Psr\Http\Message\ServerRequestInterface $request, \Interop\Http\ServerMiddleware\DelegateInterface $delegate) |
| 26 | 26 | { |
| 27 | - if(!$this->cache->hasItem(self::CACHE_ERROR_CODES)) { |
|
| 27 | + if (!$this->cache->hasItem(self::CACHE_ERROR_CODES)) { |
|
| 28 | 28 | $errorCodes = $this->errorCodes->getErrorCodes(); |
| 29 | 29 | $this->cache->setItem(self::CACHE_ERROR_CODES, serialize($errorCodes)); |
| 30 | 30 | } else { |
@@ -15,6 +15,6 @@ |
||
| 15 | 15 | |
| 16 | 16 | public function process(\Psr\Http\Message\ServerRequestInterface $request, \Interop\Http\ServerMiddleware\DelegateInterface $delegate) |
| 17 | 17 | { |
| 18 | - return new \Zend\Diactoros\Response\TextResponse((string) $this->swagger, 200, ['Content-Type' => 'application/json']); |
|
| 18 | + return new \Zend\Diactoros\Response\TextResponse((string)$this->swagger, 200, ['Content-Type' => 'application/json']); |
|
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | 21 | \ No newline at end of file |
@@ -22,9 +22,9 @@ |
||
| 22 | 22 | throw new \Phrest\Exception('no matched route found'); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - $operationId = $method.'.'.$route->getName(); |
|
| 25 | + $operationId = $method . '.' . $route->getName(); |
|
| 26 | 26 | $operationIds = $route->getOptions()['operationIds'] ?? []; |
| 27 | - if(array_key_exists($method, $operationIds)) { |
|
| 27 | + if (array_key_exists($method, $operationIds)) { |
|
| 28 | 28 | $operationId = $operationIds[$method]; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | 'factories' => [ |
| 75 | 75 | \Zend\Expressive\Helper\UrlHelper::class => \Zend\Expressive\Helper\UrlHelperFactory::class, |
| 76 | 76 | |
| 77 | - \Phrest\Application::SERVICE_LOGGER => function (\Interop\Container\ContainerInterface $container) use ($logger, $monologHandler, $monologProcessor) { |
|
| 77 | + \Phrest\Application::SERVICE_LOGGER => function(\Interop\Container\ContainerInterface $container) use ($logger, $monologHandler, $monologProcessor) { |
|
| 78 | 78 | $handlers = []; |
| 79 | 79 | foreach ($monologHandler as $handler) { |
| 80 | 80 | $handlers[] = $container->get($handler); |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | return $logger; |
| 87 | 87 | }, |
| 88 | 88 | |
| 89 | - \Phrest\Application::SERVICE_SWAGGER => function () use ($cache, $swaggerScanDirectory) { |
|
| 89 | + \Phrest\Application::SERVICE_SWAGGER => function() use ($cache, $swaggerScanDirectory) { |
|
| 90 | 90 | return new \Phrest\Swagger($cache, $swaggerScanDirectory); |
| 91 | 91 | }, |
| 92 | 92 | |
| 93 | - \Phrest\Application::SERVICE_HATEOAS => function (\Interop\Container\ContainerInterface $container) use ($enableCache, $cacheDirectory) { |
|
| 93 | + \Phrest\Application::SERVICE_HATEOAS => function(\Interop\Container\ContainerInterface $container) use ($enableCache, $cacheDirectory) { |
|
| 94 | 94 | /** @var \Zend\Expressive\Router\RouterInterface $router */ |
| 95 | 95 | $router = $container->get(\Zend\Expressive\Router\RouterInterface::class); |
| 96 | 96 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $hateoasBuilder->setUrlGenerator( |
| 107 | 107 | null, |
| 108 | 108 | new \Hateoas\UrlGenerator\CallableUrlGenerator( |
| 109 | - function ($route, array $parameters, $absolute) use ($router, $serverUrlHelper) { |
|
| 109 | + function($route, array $parameters, $absolute) use ($router, $serverUrlHelper) { |
|
| 110 | 110 | $uri = $router->generateUri($route, $parameters); |
| 111 | 111 | if ($absolute) { |
| 112 | 112 | return $serverUrlHelper($uri); |
@@ -118,11 +118,11 @@ discard block |
||
| 118 | 118 | return $hateoasBuilder->build(); |
| 119 | 119 | }, |
| 120 | 120 | |
| 121 | - \Phrest\Application::ACTION_SWAGGER => function (\Interop\Container\ContainerInterface $container) { |
|
| 121 | + \Phrest\Application::ACTION_SWAGGER => function(\Interop\Container\ContainerInterface $container) { |
|
| 122 | 122 | return new \Phrest\API\Action\Swagger($container->get(\Phrest\Application::SERVICE_SWAGGER)); |
| 123 | 123 | }, |
| 124 | 124 | |
| 125 | - \Phrest\Application::ACTION_ERROR_CODES => function (\Interop\Container\ContainerInterface $container) use ($cache, $errorCodes) { |
|
| 125 | + \Phrest\Application::ACTION_ERROR_CODES => function(\Interop\Container\ContainerInterface $container) use ($cache, $errorCodes) { |
|
| 126 | 126 | if ($errorCodes) { |
| 127 | 127 | $errorCodesInstance = $container->get($errorCodes); |
| 128 | 128 | } else { |
@@ -131,13 +131,13 @@ discard block |
||
| 131 | 131 | return new \Phrest\API\Action\ErrorCodes($cache, $errorCodesInstance); |
| 132 | 132 | }, |
| 133 | 133 | |
| 134 | - \Phrest\Application::SERVICE_HATEOAS_RESPONSE_GENERATOR => function (\Interop\Container\ContainerInterface $container) { |
|
| 134 | + \Phrest\Application::SERVICE_HATEOAS_RESPONSE_GENERATOR => function(\Interop\Container\ContainerInterface $container) { |
|
| 135 | 135 | return new \Phrest\API\HateoasResponseGenerator( |
| 136 | 136 | $container->get(\Phrest\Application::SERVICE_HATEOAS) |
| 137 | 137 | ); |
| 138 | 138 | }, |
| 139 | 139 | |
| 140 | - \Phrest\Application::SERVICE_REQUEST_SWAGGER_VALIDATOR => function (\Interop\Container\ContainerInterface $container) { |
|
| 140 | + \Phrest\Application::SERVICE_REQUEST_SWAGGER_VALIDATOR => function(\Interop\Container\ContainerInterface $container) { |
|
| 141 | 141 | /** @var \Phrest\Swagger $swagger */ |
| 142 | 142 | $swagger = $container->get(\Phrest\Application::SERVICE_SWAGGER); |
| 143 | 143 | $jsonValidator = new \JsonSchema\Validator( |
@@ -146,11 +146,11 @@ discard block |
||
| 146 | 146 | return new \Phrest\API\RequestSwaggerValidator($swagger, $jsonValidator); |
| 147 | 147 | }, |
| 148 | 148 | |
| 149 | - \Phrest\Application::SERVICE_ROUTER => function () { |
|
| 149 | + \Phrest\Application::SERVICE_ROUTER => function() { |
|
| 150 | 150 | return new \Zend\Expressive\Router\FastRouteRouter(); |
| 151 | 151 | }, |
| 152 | 152 | |
| 153 | - \Zend\Expressive\Router\RouterInterface::class => function (\Interop\Container\ContainerInterface $container) { |
|
| 153 | + \Zend\Expressive\Router\RouterInterface::class => function(\Interop\Container\ContainerInterface $container) { |
|
| 154 | 154 | return $container->get(\Phrest\Application::SERVICE_ROUTER); |
| 155 | 155 | } |
| 156 | 156 | ], |
@@ -158,21 +158,21 @@ discard block |
||
| 158 | 158 | \Zend\Expressive\Helper\ServerUrlHelper::class => \Zend\Expressive\Helper\ServerUrlHelper::class |
| 159 | 159 | ], |
| 160 | 160 | 'initializers' => [ |
| 161 | - \Psr\Log\LoggerAwareInterface::class => function (\Interop\Container\ContainerInterface $container, $service) { |
|
| 161 | + \Psr\Log\LoggerAwareInterface::class => function(\Interop\Container\ContainerInterface $container, $service) { |
|
| 162 | 162 | if ($service instanceof \Psr\Log\LoggerAwareInterface) { |
| 163 | 163 | $service->setLogger( |
| 164 | 164 | $container->get(\Phrest\Application::SERVICE_LOGGER) |
| 165 | 165 | ); |
| 166 | 166 | } |
| 167 | 167 | }, |
| 168 | - API\RequestSwaggerValidatorAwareInterface::class => function (\Interop\Container\ContainerInterface $container, $service) { |
|
| 168 | + API\RequestSwaggerValidatorAwareInterface::class => function(\Interop\Container\ContainerInterface $container, $service) { |
|
| 169 | 169 | if ($service instanceof API\RequestSwaggerValidatorAwareInterface) { |
| 170 | 170 | $service->setRequestSwaggerValidator( |
| 171 | 171 | $container->get(\Phrest\Application::SERVICE_REQUEST_SWAGGER_VALIDATOR) |
| 172 | 172 | ); |
| 173 | 173 | } |
| 174 | 174 | }, |
| 175 | - API\HateoasResponseGeneratorAwareInterface::class => function (\Interop\Container\ContainerInterface $container, $service) { |
|
| 175 | + API\HateoasResponseGeneratorAwareInterface::class => function(\Interop\Container\ContainerInterface $container, $service) { |
|
| 176 | 176 | if ($service instanceof API\HateoasResponseGeneratorAwareInterface) { |
| 177 | 177 | $service->setHateoasResponseGenerator( |
| 178 | 178 | $container->get(\Phrest\Application::SERVICE_HATEOAS_RESPONSE_GENERATOR) |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | $app->run($request); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - static function createCache(bool $enableCache, ?string $cacheDirectory): \Zend\Cache\Storage\StorageInterface |
|
| 209 | + static function createCache(bool $enableCache, ?string $cacheDirectory) : \Zend\Cache\Storage\StorageInterface |
|
| 210 | 210 | { |
| 211 | 211 | $cache = new \Zend\Cache\Storage\Adapter\BlackHole(); |
| 212 | 212 | if ($enableCache) { |