diff --git a/.gitattributes b/.gitattributes index 3946beb0..13bb2a91 100644 --- a/.gitattributes +++ b/.gitattributes @@ -22,3 +22,4 @@ indocker export-ignore phpcs.xml export-ignore phpunit.xml.dist export-ignore phpunit-func.xml export-ignore +phpstan.neon diff --git a/.travis.yml b/.travis.yml index f3606d17..6e5357c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ before_script: script: - mkdir build - composer check - - if [[ $TRAVIS_PHP_VERSION = 7.1 ]] || [[ $TRAVIS_PHP_VERSION = 7.2 ]]; then ~/.composer/vendor/bin/phpstan analyse module/*/src/ --level=5 -c phpstan.neon; fi + - if [[ $TRAVIS_PHP_VERSION = 7.1 ]] || [[ $TRAVIS_PHP_VERSION = 7.2 ]]; then ~/.composer/vendor/bin/phpstan analyse module/*/src/ --level=6 -c phpstan.neon; fi after_script: - vendor/bin/phpcov merge build --clover build/clover.xml diff --git a/module/Common/src/Exception/ExceptionInterface.php b/module/Common/src/Exception/ExceptionInterface.php index 72e53d0f..349f3f4b 100644 --- a/module/Common/src/Exception/ExceptionInterface.php +++ b/module/Common/src/Exception/ExceptionInterface.php @@ -3,6 +3,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Exception; -interface ExceptionInterface +interface ExceptionInterface extends \Throwable { } diff --git a/module/Core/src/Exception/EntityDoesNotExistException.php b/module/Core/src/Exception/EntityDoesNotExistException.php index 732eaeba..ba4d233d 100644 --- a/module/Core/src/Exception/EntityDoesNotExistException.php +++ b/module/Core/src/Exception/EntityDoesNotExistException.php @@ -3,9 +3,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Exception; -use Shlinkio\Shlink\Common\Exception\ExceptionInterface; - -class EntityDoesNotExistException extends \RuntimeException implements ExceptionInterface +class EntityDoesNotExistException extends RuntimeException { public static function createFromEntityAndConditions($entityName, array $conditions) { diff --git a/module/Core/src/Exception/ExceptionInterface.php b/module/Core/src/Exception/ExceptionInterface.php new file mode 100644 index 00000000..2901b7cb --- /dev/null +++ b/module/Core/src/Exception/ExceptionInterface.php @@ -0,0 +1,8 @@ +getParsedBody(); // In requests that do not allow body or if the body has already been parsed, continue to next middleware - if (! empty($currentParams) || in_array($method, [ + if (! empty($currentParams) || \in_array($method, [ self::METHOD_GET, self::METHOD_HEAD, self::METHOD_OPTIONS, @@ -37,7 +37,7 @@ class BodyParserMiddleware implements MiddlewareInterface, RequestMethodInterfac // If the accepted content is JSON, try to parse the body from JSON $contentType = $this->getRequestContentType($request); - if (in_array($contentType, ['application/json', 'text/json', 'application/x-json'], true)) { + if (\in_array($contentType, ['application/json', 'text/json', 'application/x-json'], true)) { return $delegate->process($this->parseFromJson($request)); } @@ -48,27 +48,28 @@ class BodyParserMiddleware implements MiddlewareInterface, RequestMethodInterfac * @param Request $request * @return string */ - protected function getRequestContentType(Request $request) + private function getRequestContentType(Request $request): string { $contentType = $request->getHeaderLine('Content-type'); - $contentTypes = explode(';', $contentType); - return trim(array_shift($contentTypes)); + $contentTypes = \explode(';', $contentType); + return \trim(\array_shift($contentTypes)); } /** * @param Request $request * @return Request + * @throws RuntimeException */ - protected function parseFromJson(Request $request) + private function parseFromJson(Request $request): Request { $rawBody = (string) $request->getBody(); if (empty($rawBody)) { return $request; } - $parsedJson = json_decode($rawBody, true); - if (json_last_error() !== JSON_ERROR_NONE) { - throw new RuntimeException(sprintf('Error when parsing JSON request body: %s', json_last_error_msg())); + $parsedJson = \json_decode($rawBody, true); + if (\json_last_error() !== JSON_ERROR_NONE) { + throw new RuntimeException(\sprintf('Error when parsing JSON request body: %s', \json_last_error_msg())); } return $request->withParsedBody($parsedJson); @@ -78,7 +79,7 @@ class BodyParserMiddleware implements MiddlewareInterface, RequestMethodInterfac * @param Request $request * @return Request */ - protected function parseFromUrlEncoded(Request $request) + private function parseFromUrlEncoded(Request $request): Request { $rawBody = (string) $request->getBody(); if (empty($rawBody)) { diff --git a/module/Rest/src/Util/RestUtils.php b/module/Rest/src/Util/RestUtils.php index dcd6632e..407b0845 100644 --- a/module/Rest/src/Util/RestUtils.php +++ b/module/Rest/src/Util/RestUtils.php @@ -20,7 +20,7 @@ class RestUtils const NOT_FOUND_ERROR = 'NOT_FOUND'; const UNKNOWN_ERROR = 'UNKNOWN_ERROR'; - public static function getRestErrorCodeFromException(Common\ExceptionInterface $e) + public static function getRestErrorCodeFromException(\Throwable $e) { switch (true) { case $e instanceof Core\InvalidShortCodeException: