From 77d810b735948bad6ea28db98aed80656dce1e00 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 28 Oct 2018 08:24:06 +0100 Subject: [PATCH] Replaced all FQ global function and constants by explicit imports --- config/config.php | 3 ++- data/migrations/Version20180913205455.php | 3 ++- .../CLI/src/Command/Api/DisableKeyCommand.php | 3 ++- .../Command/ShortUrl/DeleteShortUrlCommand.php | 7 ++++--- .../ShortUrl/GeneratePreviewCommand.php | 3 ++- .../ShortUrl/GenerateShortUrlCommand.php | 15 +++++++++------ .../src/Command/ShortUrl/GetVisitsCommand.php | 3 ++- .../Command/ShortUrl/ListShortUrlsCommand.php | 17 +++++++++++------ .../src/Command/ShortUrl/ResolveUrlCommand.php | 7 ++++--- .../ShortUrl/DeleteShortCodeCommandTest.php | 14 ++++++++------ .../Command/ShortUrl/GetVisitsCommandTest.php | 7 ++++--- module/Common/functions/functions.php | 8 ++++++-- .../src/Exception/ExceptionInterface.php | 4 +++- .../src/Exception/InvalidArgumentException.php | 4 +++- .../Common/src/Exception/RuntimeException.php | 4 +++- .../Common/src/Exception/WrongIpException.php | 3 ++- .../DottedAccessConfigAbstractFactory.php | 3 ++- .../Adapter/PaginableRepositoryAdapter.php | 4 +++- .../src/Paginator/Util/PaginatorUtilsTrait.php | 3 ++- module/Common/src/Response/PixelResponse.php | 3 ++- module/Common/src/Type/ChronosDateTimeType.php | 5 +++-- module/Common/src/Util/ResponseUtilsTrait.php | 3 ++- ...nseImplicitOptionsMiddlewareFactoryTest.php | 3 ++- module/Common/test/Image/ImageFactoryTest.php | 5 +++-- .../test/Service/IpApiLocationResolverTest.php | 3 ++- .../test/Type/ChronosDateTimeTypeTest.php | 12 ++++++++---- .../Core/src/Action/AbstractTrackingAction.php | 3 ++- module/Core/src/Entity/ShortUrl.php | 3 ++- module/Core/src/Entity/Tag.php | 3 ++- module/Core/src/Entity/Visit.php | 3 ++- module/Core/src/Entity/VisitLocation.php | 18 ++++++++++-------- .../src/Exception/DeleteShortUrlException.php | 3 ++- .../Core/src/Exception/ExceptionInterface.php | 4 +++- .../src/Exception/InvalidArgumentException.php | 4 +++- .../Exception/InvalidShortCodeException.php | 9 ++++++--- .../Core/src/Exception/InvalidUrlException.php | 4 +++- module/Core/src/Exception/RuntimeException.php | 4 +++- .../Core/src/Exception/ValidationException.php | 16 ++++++++++------ .../Transformer/ShortUrlDataTransformer.php | 3 ++- module/Core/src/Util/TagManagerTrait.php | 5 ++++- .../src/Validation/ShortUrlMetaInputFilter.php | 5 +++-- .../Repository/ShortUrlRepositoryTest.php | 3 ++- module/Core/test/Action/PreviewActionTest.php | 3 ++- .../Exception/DeleteShortUrlExceptionTest.php | 6 ++++-- .../ShortUrl/DeleteShortUrlServiceTest.php | 6 ++++-- .../src/Model/CustomizableAppConfig.php | 3 ++- .../test/Command/InstallCommandTest.php | 3 ++- module/Rest/src/Action/AbstractRestAction.php | 3 ++- .../ShortUrl/AbstractCreateShortUrlAction.php | 8 +++++--- .../Action/ShortUrl/DeleteShortUrlAction.php | 5 +++-- .../src/Action/ShortUrl/EditShortUrlAction.php | 3 ++- .../Action/ShortUrl/ListShortUrlsAction.php | 3 ++- .../Action/ShortUrl/ResolveShortUrlAction.php | 8 +++++--- .../Rest/src/Action/Visit/GetVisitsAction.php | 3 ++- module/Rest/src/Authentication/JWTService.php | 5 +++-- .../JsonErrorResponseGenerator.php | 7 +++++-- .../src/Exception/AuthenticationException.php | 4 +++- .../Rest/src/Exception/ExceptionInterface.php | 4 +++- module/Rest/src/Exception/RuntimeException.php | 4 +++- .../src/Middleware/PathVersionMiddleware.php | 3 ++- ...ateShortUrlContentNegotiationMiddleware.php | 12 ++++++++---- .../ShortUrl/ShortCodePathMiddleware.php | 3 ++- module/Rest/src/Util/RestUtils.php | 3 ++- .../ShortUrl/CreateShortUrlActionTest.php | 3 ++- .../ShortUrl/DeleteShortUrlActionTest.php | 3 ++- .../ShortUrl/ListShortUrlsActionTest.php | 3 ++- .../ShortUrl/ResolveShortUrlActionTest.php | 3 ++- .../test/Action/Visit/GetVisitsActionTest.php | 3 ++- .../Middleware/PathVersionMiddlewareTest.php | 3 ++- phpcs.xml | 2 ++ 70 files changed, 235 insertions(+), 123 deletions(-) diff --git a/config/config.php b/config/config.php index 744d99d0..d9d9132e 100644 --- a/config/config.php +++ b/config/config.php @@ -6,6 +6,7 @@ namespace Shlinkio\Shlink; use Acelaya\ExpressiveErrorHandler; use Zend\ConfigAggregator; use Zend\Expressive; +use function class_exists; return (new ConfigAggregator\ConfigAggregator([ Expressive\ConfigProvider::class, @@ -13,7 +14,7 @@ return (new ConfigAggregator\ConfigAggregator([ Expressive\Router\FastRouteRouter\ConfigProvider::class, Expressive\Plates\ConfigProvider::class, Expressive\Helper\ConfigProvider::class, - \class_exists(Expressive\Swoole\ConfigProvider::class) + class_exists(Expressive\Swoole\ConfigProvider::class) ? Expressive\Swoole\ConfigProvider::class : new ConfigAggregator\ArrayProvider([]), ExpressiveErrorHandler\ConfigProvider::class, diff --git a/data/migrations/Version20180913205455.php b/data/migrations/Version20180913205455.php index a0fe3451..0b012ca1 100644 --- a/data/migrations/Version20180913205455.php +++ b/data/migrations/Version20180913205455.php @@ -6,6 +6,7 @@ namespace ShlinkMigrations; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; +use PDO; use Shlinkio\Shlink\Common\Exception\WrongIpException; use Shlinkio\Shlink\Common\Util\IpAddress; @@ -38,7 +39,7 @@ final class Version20180913205455 extends AbstractMigration ->set('v.remote_addr', ':obfuscatedAddr') ->where('v.id=:id'); - while ($row = $st->fetch(\PDO::FETCH_ASSOC)) { + while ($row = $st->fetch(PDO::FETCH_ASSOC)) { $addr = $row['remote_addr'] ?? null; if ($addr === null) { continue; diff --git a/module/CLI/src/Command/Api/DisableKeyCommand.php b/module/CLI/src/Command/Api/DisableKeyCommand.php index 7d4c14c8..09bf52dc 100644 --- a/module/CLI/src/Command/Api/DisableKeyCommand.php +++ b/module/CLI/src/Command/Api/DisableKeyCommand.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Api; +use InvalidArgumentException; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -47,7 +48,7 @@ class DisableKeyCommand extends Command try { $this->apiKeyService->disable($apiKey); $io->success(sprintf($this->translator->translate('API key "%s" properly disabled'), $apiKey)); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $io->error(sprintf($this->translator->translate('API key "%s" does not exist.'), $apiKey)); } } diff --git a/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php b/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php index 50fed1c4..61618e8d 100644 --- a/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php @@ -12,6 +12,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; class DeleteShortUrlCommand extends Command { @@ -68,7 +69,7 @@ class DeleteShortUrlCommand extends Command $this->runDelete($io, $shortCode, $ignoreThreshold); } catch (Exception\InvalidShortCodeException $e) { $io->error( - \sprintf($this->translator->translate('Provided short code "%s" could not be found.'), $shortCode) + sprintf($this->translator->translate('Provided short code "%s" could not be found.'), $shortCode) ); } catch (Exception\DeleteShortUrlException $e) { $this->retry($io, $shortCode, $e); @@ -77,7 +78,7 @@ class DeleteShortUrlCommand extends Command private function retry(SymfonyStyle $io, string $shortCode, Exception\DeleteShortUrlException $e): void { - $warningMsg = \sprintf($this->translator->translate( + $warningMsg = sprintf($this->translator->translate( 'It was not possible to delete the short URL with short code "%s" because it has more than %s visits.' ), $shortCode, $e->getVisitsThreshold()); $io->writeln('' . $warningMsg . ''); @@ -93,7 +94,7 @@ class DeleteShortUrlCommand extends Command private function runDelete(SymfonyStyle $io, string $shortCode, bool $ignoreThreshold): void { $this->deleteShortUrlService->deleteByShortCode($shortCode, $ignoreThreshold); - $io->success(\sprintf( + $io->success(sprintf( $this->translator->translate('Short URL with short code "%s" successfully deleted.'), $shortCode )); diff --git a/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php b/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php index 3b41eb44..2e9b60fe 100644 --- a/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php +++ b/module/CLI/src/Command/ShortUrl/GeneratePreviewCommand.php @@ -11,6 +11,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; class GeneratePreviewCommand extends Command { @@ -71,7 +72,7 @@ class GeneratePreviewCommand extends Command private function processUrl($url, OutputInterface $output): void { try { - $output->write(\sprintf($this->translator->translate('Processing URL %s...'), $url)); + $output->write(sprintf($this->translator->translate('Processing URL %s...'), $url)); $this->previewGenerator->generatePreview($url); $output->writeln($this->translator->translate(' Success!')); } catch (PreviewGenerationException $e) { diff --git a/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php b/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php index 0aacbcc8..d67e7d9e 100644 --- a/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php @@ -16,6 +16,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\Diactoros\Uri; use Zend\I18n\Translator\TranslatorInterface; +use function array_merge; +use function explode; +use function sprintf; class GenerateShortUrlCommand extends Command { @@ -107,8 +110,8 @@ class GenerateShortUrlCommand extends Command $tags = $input->getOption('tags'); $processedTags = []; foreach ($tags as $key => $tag) { - $explodedTags = \explode(',', $tag); - $processedTags = \array_merge($processedTags, $explodedTags); + $explodedTags = explode(',', $tag); + $processedTags = array_merge($processedTags, $explodedTags); } $tags = $processedTags; $customSlug = $input->getOption('customSlug'); @@ -126,16 +129,16 @@ class GenerateShortUrlCommand extends Command $shortUrl = $this->buildShortUrl($this->domainConfig, $shortCode); $io->writeln([ - \sprintf('%s %s', $this->translator->translate('Processed long URL:'), $longUrl), - \sprintf('%s %s', $this->translator->translate('Generated short URL:'), $shortUrl), + sprintf('%s %s', $this->translator->translate('Processed long URL:'), $longUrl), + sprintf('%s %s', $this->translator->translate('Generated short URL:'), $shortUrl), ]); } catch (InvalidUrlException $e) { - $io->error(\sprintf( + $io->error(sprintf( $this->translator->translate('Provided URL "%s" is invalid. Try with a different one.'), $longUrl )); } catch (NonUniqueSlugException $e) { - $io->error(\sprintf( + $io->error(sprintf( $this->translator->translate( 'Provided slug "%s" is already in use by another URL. Try with a different one.' ), diff --git a/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php b/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php index ada4d72d..40bf0986 100644 --- a/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php +++ b/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php @@ -13,6 +13,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function array_values; class GetVisitsCommand extends Command { @@ -95,7 +96,7 @@ class GetVisitsCommand extends Command $rowData['country'] = $row->getVisitLocation()->getCountryName(); - $rows[] = \array_values($rowData); + $rows[] = array_values($rowData); } $io->table([ $this->translator->translate('Referer'), diff --git a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php index 219382ec..516da14b 100644 --- a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php @@ -13,6 +13,11 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function array_values; +use function count; +use function explode; +use function implode; +use function sprintf; class ListShortUrlsCommand extends Command { @@ -97,7 +102,7 @@ class ListShortUrlsCommand extends Command $page = (int) $input->getOption('page'); $searchTerm = $input->getOption('searchTerm'); $tags = $input->getOption('tags'); - $tags = ! empty($tags) ? \explode(',', $tags) : []; + $tags = ! empty($tags) ? explode(',', $tags) : []; $showTags = $input->getOption('showTags'); $transformer = new ShortUrlDataTransformer($this->domainConfig); @@ -120,13 +125,13 @@ class ListShortUrlsCommand extends Command foreach ($result as $row) { $shortUrl = $transformer->transform($row); if ($showTags) { - $shortUrl['tags'] = \implode(', ', $shortUrl['tags']); + $shortUrl['tags'] = implode(', ', $shortUrl['tags']); } else { unset($shortUrl['tags']); } unset($shortUrl['originalUrl']); - $rows[] = \array_values($shortUrl); + $rows[] = array_values($shortUrl); } $io->table($headers, $rows); @@ -135,7 +140,7 @@ class ListShortUrlsCommand extends Command $io->success($this->translator->translate('Short URLs properly listed')); } else { $continue = $io->confirm( - \sprintf($this->translator->translate('Continue with page') . ' %s?', $page), + sprintf($this->translator->translate('Continue with page') . ' %s?', $page), false ); } @@ -149,7 +154,7 @@ class ListShortUrlsCommand extends Command return null; } - $orderBy = \explode(',', $orderBy); - return \count($orderBy) === 1 ? $orderBy[0] : [$orderBy[0] => $orderBy[1]]; + $orderBy = explode(',', $orderBy); + return count($orderBy) === 1 ? $orderBy[0] : [$orderBy[0] => $orderBy[1]]; } } diff --git a/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php b/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php index 57f50a79..cc06c869 100644 --- a/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php @@ -12,6 +12,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; class ResolveUrlCommand extends Command { @@ -71,15 +72,15 @@ class ResolveUrlCommand extends Command try { $url = $this->urlShortener->shortCodeToUrl($shortCode); $output->writeln( - \sprintf('%s %s', $this->translator->translate('Long URL:'), $url->getLongUrl()) + sprintf('%s %s', $this->translator->translate('Long URL:'), $url->getLongUrl()) ); } catch (InvalidShortCodeException $e) { $io->error( - \sprintf($this->translator->translate('Provided short code "%s" has an invalid format.'), $shortCode) + sprintf($this->translator->translate('Provided short code "%s" has an invalid format.'), $shortCode) ); } catch (EntityDoesNotExistException $e) { $io->error( - \sprintf($this->translator->translate('Provided short code "%s" could not be found.'), $shortCode) + sprintf($this->translator->translate('Provided short code "%s" could not be found.'), $shortCode) ); } } diff --git a/module/CLI/test/Command/ShortUrl/DeleteShortCodeCommandTest.php b/module/CLI/test/Command/ShortUrl/DeleteShortCodeCommandTest.php index 8d326758..f273ae14 100644 --- a/module/CLI/test/Command/ShortUrl/DeleteShortCodeCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/DeleteShortCodeCommandTest.php @@ -12,6 +12,8 @@ use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Zend\I18n\Translator\Translator; +use function array_pop; +use function sprintf; class DeleteShortCodeCommandTest extends TestCase { @@ -47,7 +49,7 @@ class DeleteShortCodeCommandTest extends TestCase $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); - $this->assertContains(\sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), $output); + $this->assertContains(sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), $output); $deleteByShortCode->shouldHaveBeenCalledTimes(1); } @@ -64,7 +66,7 @@ class DeleteShortCodeCommandTest extends TestCase $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); - $this->assertContains(\sprintf('Provided short code "%s" could not be found.', $shortCode), $output); + $this->assertContains(sprintf('Provided short code "%s" could not be found.', $shortCode), $output); $deleteByShortCode->shouldHaveBeenCalledTimes(1); } @@ -76,7 +78,7 @@ class DeleteShortCodeCommandTest extends TestCase $shortCode = 'abc123'; $deleteByShortCode = $this->service->deleteByShortCode($shortCode, Argument::type('bool'))->will( function (array $args) { - $ignoreThreshold = \array_pop($args); + $ignoreThreshold = array_pop($args); if (!$ignoreThreshold) { throw new Exception\DeleteShortUrlException(10); @@ -88,11 +90,11 @@ class DeleteShortCodeCommandTest extends TestCase $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); - $this->assertContains(\sprintf( + $this->assertContains(sprintf( 'It was not possible to delete the short URL with short code "%s" because it has more than 10 visits.', $shortCode ), $output); - $this->assertContains(\sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), $output); + $this->assertContains(sprintf('Short URL with short code "%s" successfully deleted.', $shortCode), $output); $deleteByShortCode->shouldHaveBeenCalledTimes(2); } @@ -110,7 +112,7 @@ class DeleteShortCodeCommandTest extends TestCase $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); - $this->assertContains(\sprintf( + $this->assertContains(sprintf( 'It was not possible to delete the short URL with short code "%s" because it has more than 10 visits.', $shortCode ), $output); diff --git a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php index ba2a9fb5..88563a05 100644 --- a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php @@ -15,6 +15,7 @@ use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Zend\I18n\Translator\Translator; +use function strpos; class GetVisitsCommandTest extends TestCase { @@ -88,8 +89,8 @@ class GetVisitsCommandTest extends TestCase 'shortCode' => $shortCode, ]); $output = $this->commandTester->getDisplay(); - $this->assertGreaterThan(0, \strpos($output, 'foo')); - $this->assertGreaterThan(0, \strpos($output, 'Spain')); - $this->assertGreaterThan(0, \strpos($output, 'bar')); + $this->assertGreaterThan(0, strpos($output, 'foo')); + $this->assertGreaterThan(0, strpos($output, 'Spain')); + $this->assertGreaterThan(0, strpos($output, 'bar')); } } diff --git a/module/Common/functions/functions.php b/module/Common/functions/functions.php index e28e4fb2..bd851351 100644 --- a/module/Common/functions/functions.php +++ b/module/Common/functions/functions.php @@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Common; use const JSON_ERROR_NONE; use function getenv; use function in_array; +use function json_decode as spl_json_decode; use function json_last_error; use function json_last_error_msg; use function strtolower; @@ -50,11 +51,14 @@ function contains($needle, array $haystack): bool return in_array($needle, $haystack, true); } +/** + * @throws Exception\InvalidArgumentException + */ function json_decode(string $json, int $depth = 512, int $options = 0): array { - $data = \json_decode($json, true, $depth, $options); + $data = spl_json_decode($json, true, $depth, $options); if (JSON_ERROR_NONE !== json_last_error()) { - throw new Exception\InvalidArgumentException('Error decoding JSON: ' . json_last_error_msg()); + throw new Exception\InvalidArgumentException(sprintf('Error decoding JSON: %s', json_last_error_msg())); } return $data; diff --git a/module/Common/src/Exception/ExceptionInterface.php b/module/Common/src/Exception/ExceptionInterface.php index 349f3f4b..9f2eca48 100644 --- a/module/Common/src/Exception/ExceptionInterface.php +++ b/module/Common/src/Exception/ExceptionInterface.php @@ -3,6 +3,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Exception; -interface ExceptionInterface extends \Throwable +use Throwable; + +interface ExceptionInterface extends Throwable { } diff --git a/module/Common/src/Exception/InvalidArgumentException.php b/module/Common/src/Exception/InvalidArgumentException.php index 42a0c33f..52e6b365 100644 --- a/module/Common/src/Exception/InvalidArgumentException.php +++ b/module/Common/src/Exception/InvalidArgumentException.php @@ -3,6 +3,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Exception; -class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +use InvalidArgumentException as SplInvalidArgumentException; + +class InvalidArgumentException extends SplInvalidArgumentException implements ExceptionInterface { } diff --git a/module/Common/src/Exception/RuntimeException.php b/module/Common/src/Exception/RuntimeException.php index aa70777e..6fad16aa 100644 --- a/module/Common/src/Exception/RuntimeException.php +++ b/module/Common/src/Exception/RuntimeException.php @@ -3,6 +3,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Exception; -class RuntimeException extends \RuntimeException implements ExceptionInterface +use RuntimeException as SplRuntimeException; + +class RuntimeException extends SplRuntimeException implements ExceptionInterface { } diff --git a/module/Common/src/Exception/WrongIpException.php b/module/Common/src/Exception/WrongIpException.php index 2d98f1ea..b4db7186 100644 --- a/module/Common/src/Exception/WrongIpException.php +++ b/module/Common/src/Exception/WrongIpException.php @@ -3,11 +3,12 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Exception; +use Throwable; use function sprintf; class WrongIpException extends RuntimeException { - public static function fromIpAddress($ipAddress, \Throwable $prev = null): self + public static function fromIpAddress($ipAddress, Throwable $prev = null): self { return new self(sprintf('Provided IP "%s" is invalid', $ipAddress), 0, $prev); } diff --git a/module/Common/src/Factory/DottedAccessConfigAbstractFactory.php b/module/Common/src/Factory/DottedAccessConfigAbstractFactory.php index 71fd2e56..b3080375 100644 --- a/module/Common/src/Factory/DottedAccessConfigAbstractFactory.php +++ b/module/Common/src/Factory/DottedAccessConfigAbstractFactory.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Factory; +use ArrayAccess; use Interop\Container\ContainerInterface; use Interop\Container\Exception\ContainerException; use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; @@ -72,7 +73,7 @@ class DottedAccessConfigAbstractFactory implements AbstractFactoryInterface } $value = $array[$key]; - if (! empty($keys) && (is_array($value) || $value instanceof \ArrayAccess)) { + if (! empty($keys) && (is_array($value) || $value instanceof ArrayAccess)) { $value = $this->readKeysFromArray($keys, $value); } diff --git a/module/Common/src/Paginator/Adapter/PaginableRepositoryAdapter.php b/module/Common/src/Paginator/Adapter/PaginableRepositoryAdapter.php index c83fa5a7..78ce7b53 100644 --- a/module/Common/src/Paginator/Adapter/PaginableRepositoryAdapter.php +++ b/module/Common/src/Paginator/Adapter/PaginableRepositoryAdapter.php @@ -5,6 +5,8 @@ namespace Shlinkio\Shlink\Common\Paginator\Adapter; use Shlinkio\Shlink\Common\Repository\PaginableRepositoryInterface; use Zend\Paginator\Adapter\AdapterInterface; +use function strip_tags; +use function trim; class PaginableRepositoryAdapter implements AdapterInterface { @@ -34,7 +36,7 @@ class PaginableRepositoryAdapter implements AdapterInterface $orderBy = null ) { $this->paginableRepository = $paginableRepository; - $this->searchTerm = $searchTerm !== null ? \trim(\strip_tags($searchTerm)) : null; + $this->searchTerm = $searchTerm !== null ? trim(strip_tags($searchTerm)) : null; $this->orderBy = $orderBy; $this->tags = $tags; } diff --git a/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php b/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php index 1b01de42..85fcc861 100644 --- a/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php +++ b/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php @@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Common\Paginator\Util; use Shlinkio\Shlink\Common\Rest\DataTransformerInterface; use Zend\Paginator\Paginator; use Zend\Stdlib\ArrayUtils; +use function array_map; trait PaginatorUtilsTrait { @@ -25,7 +26,7 @@ trait PaginatorUtilsTrait private function serializeItems(array $items, ?DataTransformerInterface $transformer = null): array { - return $transformer === null ? $items : \array_map([$transformer, 'transform'], $items); + return $transformer === null ? $items : array_map([$transformer, 'transform'], $items); } /** diff --git a/module/Common/src/Response/PixelResponse.php b/module/Common/src/Response/PixelResponse.php index cfd44ab1..37b3bbbd 100644 --- a/module/Common/src/Response/PixelResponse.php +++ b/module/Common/src/Response/PixelResponse.php @@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Common\Response; use Psr\Http\Message\StreamInterface; use Zend\Diactoros\Response; use Zend\Diactoros\Stream; +use function base64_decode; class PixelResponse extends Response { @@ -26,7 +27,7 @@ class PixelResponse extends Response private function createBody(): StreamInterface { $body = new Stream('php://temp', 'wb+'); - $body->write((string) \base64_decode(self::BASE_64_IMAGE)); + $body->write((string) base64_decode(self::BASE_64_IMAGE)); $body->rewind(); return $body; } diff --git a/module/Common/src/Type/ChronosDateTimeType.php b/module/Common/src/Type/ChronosDateTimeType.php index 9771ecfe..a400106e 100644 --- a/module/Common/src/Type/ChronosDateTimeType.php +++ b/module/Common/src/Type/ChronosDateTimeType.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Type; use Cake\Chronos\Chronos; +use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeImmutableType; @@ -39,14 +40,14 @@ class ChronosDateTimeType extends DateTimeImmutableType return $value; } - if ($value instanceof \DateTimeInterface) { + if ($value instanceof DateTimeInterface) { return $value->format($platform->getDateTimeFormatString()); } throw ConversionException::conversionFailedInvalidType( $value, $this->getName(), - ['null', \DateTimeInterface::class] + ['null', DateTimeInterface::class] ); } } diff --git a/module/Common/src/Util/ResponseUtilsTrait.php b/module/Common/src/Util/ResponseUtilsTrait.php index 90e76c56..f73c163e 100644 --- a/module/Common/src/Util/ResponseUtilsTrait.php +++ b/module/Common/src/Util/ResponseUtilsTrait.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Util; +use finfo; use Psr\Http\Message\ResponseInterface; use Zend\Diactoros\Response; use Zend\Diactoros\Stream; @@ -31,7 +32,7 @@ trait ResponseUtilsTrait { $body = new Stream($path); return new Response($body, 200, ArrayUtils::merge([ - 'Content-Type' => (new \finfo(FILEINFO_MIME))->file($path), + 'Content-Type' => (new finfo(FILEINFO_MIME))->file($path), 'Content-Length' => (string) $body->getSize(), ], $extraHeaders)); } diff --git a/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php b/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php index 8e6b17b7..a9d6c4c4 100644 --- a/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php +++ b/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Common\Factory; use PHPUnit\Framework\TestCase; +use ReflectionObject; use Shlinkio\Shlink\Common\Factory\EmptyResponseImplicitOptionsMiddlewareFactory; use Zend\Diactoros\Response\EmptyResponse; use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware; @@ -37,7 +38,7 @@ class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase { $instance = $this->factory->__invoke(new ServiceManager(), ''); - $ref = new \ReflectionObject($instance); + $ref = new ReflectionObject($instance); $prop = $ref->getProperty('responseFactory'); $prop->setAccessible(true); $this->assertInstanceOf(EmptyResponse::class, $prop->getValue($instance)()); diff --git a/module/Common/test/Image/ImageFactoryTest.php b/module/Common/test/Image/ImageFactoryTest.php index 998817bc..7ccd5bf9 100644 --- a/module/Common/test/Image/ImageFactoryTest.php +++ b/module/Common/test/Image/ImageFactoryTest.php @@ -5,6 +5,7 @@ namespace ShlinkioTest\Shlink\Common\Image; use mikehaertl\wkhtmlto\Image; use PHPUnit\Framework\TestCase; +use ReflectionObject; use Shlinkio\Shlink\Common\Image\ImageFactory; use Zend\ServiceManager\ServiceManager; @@ -31,7 +32,7 @@ class ImageFactoryTest extends TestCase ]]), ''); $this->assertInstanceOf(Image::class, $image); - $ref = new \ReflectionObject($image); + $ref = new ReflectionObject($image); $page = $ref->getProperty('_page'); $page->setAccessible(true); $this->assertNull($page->getValue($image)); @@ -50,7 +51,7 @@ class ImageFactoryTest extends TestCase ]]), '', ['url' => $expectedPage]); $this->assertInstanceOf(Image::class, $image); - $ref = new \ReflectionObject($image); + $ref = new ReflectionObject($image); $page = $ref->getProperty('_page'); $page->setAccessible(true); $this->assertEquals($expectedPage, $page->getValue($image)); diff --git a/module/Common/test/Service/IpApiLocationResolverTest.php b/module/Common/test/Service/IpApiLocationResolverTest.php index 84012e73..27c43895 100644 --- a/module/Common/test/Service/IpApiLocationResolverTest.php +++ b/module/Common/test/Service/IpApiLocationResolverTest.php @@ -9,6 +9,7 @@ use GuzzleHttp\Psr7\Response; use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Common\Service\IpApiLocationResolver; +use function json_encode; class IpApiLocationResolverTest extends TestCase { @@ -47,7 +48,7 @@ class IpApiLocationResolverTest extends TestCase 'time_zone' => '', ]; $response = new Response(); - $response->getBody()->write(\json_encode($actual)); + $response->getBody()->write(json_encode($actual)); $response->getBody()->rewind(); $this->client->get('http://ip-api.com/json/1.2.3.4')->willReturn($response) diff --git a/module/Common/test/Type/ChronosDateTimeTypeTest.php b/module/Common/test/Type/ChronosDateTimeTypeTest.php index 4b7123bb..2512cab6 100644 --- a/module/Common/test/Type/ChronosDateTimeTypeTest.php +++ b/module/Common/test/Type/ChronosDateTimeTypeTest.php @@ -4,11 +4,15 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Common\Type; use Cake\Chronos\Chronos; +use DateTime; +use DateTimeImmutable; +use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Common\Type\ChronosDateTimeType; +use stdClass; class ChronosDateTimeTypeTest extends TestCase { @@ -65,7 +69,7 @@ class ChronosDateTimeTypeTest extends TestCase * @test * @dataProvider providePhpValues */ - public function valueIsConvertedToDatabaseFormat(?\DateTimeInterface $value, ?string $expected) + public function valueIsConvertedToDatabaseFormat(?DateTimeInterface $value, ?string $expected) { $platform = $this->prophesize(AbstractPlatform::class); $platform->getDateTimeFormatString()->willReturn('Y-m-d'); @@ -77,9 +81,9 @@ class ChronosDateTimeTypeTest extends TestCase { return [ [null, null], - [new \DateTimeImmutable('2017-01-01'), '2017-01-01'], + [new DateTimeImmutable('2017-01-01'), '2017-01-01'], [Chronos::parse('2017-02-01'), '2017-02-01'], - [new \DateTime('2017-03-01'), '2017-03-01'], + [new DateTime('2017-03-01'), '2017-03-01'], ]; } @@ -89,6 +93,6 @@ class ChronosDateTimeTypeTest extends TestCase public function exceptionIsThrownIfInvalidValueIsParsedToDatabase() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \stdClass(), $this->prophesize(AbstractPlatform::class)->reveal()); + $this->type->convertToDatabaseValue(new stdClass(), $this->prophesize(AbstractPlatform::class)->reveal()); } } diff --git a/module/Core/src/Action/AbstractTrackingAction.php b/module/Core/src/Action/AbstractTrackingAction.php index 34b55aba..670aa908 100644 --- a/module/Core/src/Action/AbstractTrackingAction.php +++ b/module/Core/src/Action/AbstractTrackingAction.php @@ -16,6 +16,7 @@ use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Options\AppOptions; use Shlinkio\Shlink\Core\Service\UrlShortenerInterface; use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface; +use function array_key_exists; abstract class AbstractTrackingAction implements MiddlewareInterface { @@ -69,7 +70,7 @@ abstract class AbstractTrackingAction implements MiddlewareInterface $url = $this->urlShortener->shortCodeToUrl($shortCode); // Track visit to this short code - if ($disableTrackParam === null || ! \array_key_exists($disableTrackParam, $query)) { + if ($disableTrackParam === null || ! array_key_exists($disableTrackParam, $query)) { $this->visitTracker->track($shortCode, Visitor::fromRequest($request)); } diff --git a/module/Core/src/Entity/ShortUrl.php b/module/Core/src/Entity/ShortUrl.php index 635db67b..12a0e23b 100644 --- a/module/Core/src/Entity/ShortUrl.php +++ b/module/Core/src/Entity/ShortUrl.php @@ -9,6 +9,7 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Shlinkio\Shlink\Common\Entity\AbstractEntity; use Shlinkio\Shlink\Core\Repository\ShortUrlRepository; +use function count; /** * Class ShortUrl @@ -176,7 +177,7 @@ class ShortUrl extends AbstractEntity public function getVisitsCount(): int { - return \count($this->visits); + return count($this->visits); } /** diff --git a/module/Core/src/Entity/Tag.php b/module/Core/src/Entity/Tag.php index aad6b713..0148421a 100644 --- a/module/Core/src/Entity/Tag.php +++ b/module/Core/src/Entity/Tag.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Entity; use Doctrine\ORM\Mapping as ORM; +use JsonSerializable; use Shlinkio\Shlink\Common\Entity\AbstractEntity; use Shlinkio\Shlink\Core\Repository\TagRepository; @@ -15,7 +16,7 @@ use Shlinkio\Shlink\Core\Repository\TagRepository; * @ORM\Entity(repositoryClass=TagRepository::class) * @ORM\Table(name="tags") */ -class Tag extends AbstractEntity implements \JsonSerializable +class Tag extends AbstractEntity implements JsonSerializable { /** * @var string diff --git a/module/Core/src/Entity/Visit.php b/module/Core/src/Entity/Visit.php index bad18bfe..126d6ff2 100644 --- a/module/Core/src/Entity/Visit.php +++ b/module/Core/src/Entity/Visit.php @@ -5,6 +5,7 @@ namespace Shlinkio\Shlink\Core\Entity; use Cake\Chronos\Chronos; use Doctrine\ORM\Mapping as ORM; +use JsonSerializable; use Shlinkio\Shlink\Common\Entity\AbstractEntity; use Shlinkio\Shlink\Common\Exception\WrongIpException; use Shlinkio\Shlink\Common\Util\IpAddress; @@ -18,7 +19,7 @@ use Shlinkio\Shlink\Core\Repository\VisitRepository; * @ORM\Entity(repositoryClass=VisitRepository::class) * @ORM\Table(name="visits") */ -class Visit extends AbstractEntity implements \JsonSerializable +class Visit extends AbstractEntity implements JsonSerializable { /** * @var string diff --git a/module/Core/src/Entity/VisitLocation.php b/module/Core/src/Entity/VisitLocation.php index af75b8d6..daeb9678 100644 --- a/module/Core/src/Entity/VisitLocation.php +++ b/module/Core/src/Entity/VisitLocation.php @@ -4,8 +4,10 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Entity; use Doctrine\ORM\Mapping as ORM; +use JsonSerializable; use Shlinkio\Shlink\Common\Entity\AbstractEntity; use Zend\Stdlib\ArraySerializableInterface; +use function array_key_exists; /** * Class VisitLocation @@ -15,7 +17,7 @@ use Zend\Stdlib\ArraySerializableInterface; * @ORM\Entity() * @ORM\Table(name="visit_locations") */ -class VisitLocation extends AbstractEntity implements ArraySerializableInterface, \JsonSerializable +class VisitLocation extends AbstractEntity implements ArraySerializableInterface, JsonSerializable { /** * @var string @@ -135,25 +137,25 @@ class VisitLocation extends AbstractEntity implements ArraySerializableInterface */ public function exchangeArray(array $array): void { - if (\array_key_exists('country_code', $array)) { + if (array_key_exists('country_code', $array)) { $this->setCountryCode((string) $array['country_code']); } - if (\array_key_exists('country_name', $array)) { + if (array_key_exists('country_name', $array)) { $this->setCountryName((string) $array['country_name']); } - if (\array_key_exists('region_name', $array)) { + if (array_key_exists('region_name', $array)) { $this->setRegionName((string) $array['region_name']); } - if (\array_key_exists('city', $array)) { + if (array_key_exists('city', $array)) { $this->setCityName((string) $array['city']); } - if (\array_key_exists('latitude', $array)) { + if (array_key_exists('latitude', $array)) { $this->setLatitude((string) $array['latitude']); } - if (\array_key_exists('longitude', $array)) { + if (array_key_exists('longitude', $array)) { $this->setLongitude((string) $array['longitude']); } - if (\array_key_exists('time_zone', $array)) { + if (array_key_exists('time_zone', $array)) { $this->setTimezone((string) $array['time_zone']); } } diff --git a/module/Core/src/Exception/DeleteShortUrlException.php b/module/Core/src/Exception/DeleteShortUrlException.php index 8e2914d7..d5d9da85 100644 --- a/module/Core/src/Exception/DeleteShortUrlException.php +++ b/module/Core/src/Exception/DeleteShortUrlException.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Exception; use Throwable; +use function sprintf; class DeleteShortUrlException extends RuntimeException { @@ -20,7 +21,7 @@ class DeleteShortUrlException extends RuntimeException public static function fromVisitsThreshold(int $threshold, string $shortCode): self { - return new self($threshold, \sprintf( + return new self($threshold, sprintf( 'Impossible to delete short URL with short code "%s" since it has more than "%s" visits.', $shortCode, $threshold diff --git a/module/Core/src/Exception/ExceptionInterface.php b/module/Core/src/Exception/ExceptionInterface.php index 2901b7cb..ac2508c6 100644 --- a/module/Core/src/Exception/ExceptionInterface.php +++ b/module/Core/src/Exception/ExceptionInterface.php @@ -3,6 +3,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Exception; -interface ExceptionInterface extends \Throwable +use Throwable; + +interface ExceptionInterface extends Throwable { } diff --git a/module/Core/src/Exception/InvalidArgumentException.php b/module/Core/src/Exception/InvalidArgumentException.php index ef3fedf9..3ed4714b 100644 --- a/module/Core/src/Exception/InvalidArgumentException.php +++ b/module/Core/src/Exception/InvalidArgumentException.php @@ -3,6 +3,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Exception; -class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +use InvalidArgumentException as SplInvalidArgumentException; + +class InvalidArgumentException extends SplInvalidArgumentException implements ExceptionInterface { } diff --git a/module/Core/src/Exception/InvalidShortCodeException.php b/module/Core/src/Exception/InvalidShortCodeException.php index c8123a74..a4e68cea 100644 --- a/module/Core/src/Exception/InvalidShortCodeException.php +++ b/module/Core/src/Exception/InvalidShortCodeException.php @@ -3,13 +3,16 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Exception; +use Exception; +use function sprintf; + class InvalidShortCodeException extends RuntimeException { - public static function fromCharset($shortCode, $charSet, \Exception $previous = null) + public static function fromCharset($shortCode, $charSet, Exception $previous = null) { $code = $previous !== null ? $previous->getCode() : -1; return new static( - \sprintf('Provided short code "%s" does not match the char set "%s"', $shortCode, $charSet), + sprintf('Provided short code "%s" does not match the char set "%s"', $shortCode, $charSet), $code, $previous ); @@ -17,6 +20,6 @@ class InvalidShortCodeException extends RuntimeException public static function fromNotFoundShortCode($shortCode) { - return new static(\sprintf('Provided short code "%s" does not belong to a short URL', $shortCode)); + return new static(sprintf('Provided short code "%s" does not belong to a short URL', $shortCode)); } } diff --git a/module/Core/src/Exception/InvalidUrlException.php b/module/Core/src/Exception/InvalidUrlException.php index 1fa6fe19..cbedb4b5 100644 --- a/module/Core/src/Exception/InvalidUrlException.php +++ b/module/Core/src/Exception/InvalidUrlException.php @@ -3,9 +3,11 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Exception; +use Throwable; + class InvalidUrlException extends RuntimeException { - public static function fromUrl($url, \Throwable $previous = null) + public static function fromUrl($url, Throwable $previous = null) { $code = isset($previous) ? $previous->getCode() : -1; return new static(sprintf('Provided URL "%s" is not an existing and valid URL', $url), $code, $previous); diff --git a/module/Core/src/Exception/RuntimeException.php b/module/Core/src/Exception/RuntimeException.php index 70ee4cc5..d256a49c 100644 --- a/module/Core/src/Exception/RuntimeException.php +++ b/module/Core/src/Exception/RuntimeException.php @@ -3,6 +3,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Exception; -class RuntimeException extends \RuntimeException implements ExceptionInterface +use RuntimeException as SplRuntimeException; + +class RuntimeException extends SplRuntimeException implements ExceptionInterface { } diff --git a/module/Core/src/Exception/ValidationException.php b/module/Core/src/Exception/ValidationException.php index 5c6a95bc..2f2dd1e6 100644 --- a/module/Core/src/Exception/ValidationException.php +++ b/module/Core/src/Exception/ValidationException.php @@ -3,7 +3,11 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Exception; +use Throwable; use Zend\InputFilter\InputFilterInterface; +use function is_array; +use function print_r; +use function sprintf; class ValidationException extends RuntimeException { @@ -16,7 +20,7 @@ class ValidationException extends RuntimeException string $message = '', array $invalidElements = [], int $code = 0, - \Throwable $previous = null + Throwable $previous = null ) { $this->invalidElements = $invalidElements; parent::__construct($message, $code, $previous); @@ -27,7 +31,7 @@ class ValidationException extends RuntimeException * @param \Throwable|null $prev * @return ValidationException */ - public static function fromInputFilter(InputFilterInterface $inputFilter, \Throwable $prev = null): self + public static function fromInputFilter(InputFilterInterface $inputFilter, Throwable $prev = null): self { return static::fromArray($inputFilter->getMessages(), $prev); } @@ -37,10 +41,10 @@ class ValidationException extends RuntimeException * @param \Throwable|null $prev * @return ValidationException */ - public static function fromArray(array $invalidData, \Throwable $prev = null): self + public static function fromArray(array $invalidData, Throwable $prev = null): self { return new self( - \sprintf( + sprintf( 'Provided data is not valid. These are the messages:%s%s%s', PHP_EOL, self::formMessagesToString($invalidData), @@ -56,10 +60,10 @@ class ValidationException extends RuntimeException { $text = ''; foreach ($messages as $name => $messageSet) { - $text .= \sprintf( + $text .= sprintf( "\n\t'%s' => %s", $name, - \is_array($messageSet) ? \print_r($messageSet, true) : $messageSet + is_array($messageSet) ? print_r($messageSet, true) : $messageSet ); } diff --git a/module/Core/src/Transformer/ShortUrlDataTransformer.php b/module/Core/src/Transformer/ShortUrlDataTransformer.php index 52965213..d6c9046e 100644 --- a/module/Core/src/Transformer/ShortUrlDataTransformer.php +++ b/module/Core/src/Transformer/ShortUrlDataTransformer.php @@ -7,6 +7,7 @@ use Shlinkio\Shlink\Common\Rest\DataTransformerInterface; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Util\ShortUrlBuilderTrait; +use function array_map; class ShortUrlDataTransformer implements DataTransformerInterface { @@ -37,7 +38,7 @@ class ShortUrlDataTransformer implements DataTransformerInterface 'longUrl' => $longUrl, 'dateCreated' => $dateCreated !== null ? $dateCreated->toAtomString() : null, 'visitsCount' => $value->getVisitsCount(), - 'tags' => \array_map([$this, 'serializeTag'], $value->getTags()->toArray()), + 'tags' => array_map([$this, 'serializeTag'], $value->getTags()->toArray()), // Deprecated 'originalUrl' => $longUrl, diff --git a/module/Core/src/Util/TagManagerTrait.php b/module/Core/src/Util/TagManagerTrait.php index d9366463..614dac3a 100644 --- a/module/Core/src/Util/TagManagerTrait.php +++ b/module/Core/src/Util/TagManagerTrait.php @@ -6,6 +6,9 @@ namespace Shlinkio\Shlink\Core\Util; use Doctrine\Common\Collections; use Doctrine\ORM\EntityManagerInterface; use Shlinkio\Shlink\Core\Entity\Tag; +use function str_replace; +use function strtolower; +use function trim; trait TagManagerTrait { @@ -35,6 +38,6 @@ trait TagManagerTrait */ private function normalizeTagName($tagName): string { - return \str_replace(' ', '-', \strtolower(\trim($tagName))); + return str_replace(' ', '-', strtolower(trim($tagName))); } } diff --git a/module/Core/src/Validation/ShortUrlMetaInputFilter.php b/module/Core/src/Validation/ShortUrlMetaInputFilter.php index 5bdb20ee..80e14953 100644 --- a/module/Core/src/Validation/ShortUrlMetaInputFilter.php +++ b/module/Core/src/Validation/ShortUrlMetaInputFilter.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Validation; +use DateTime; use Zend\I18n\Validator\IsInt; use Zend\InputFilter\InputFilter; use Zend\Validator\Date; @@ -28,11 +29,11 @@ class ShortUrlMetaInputFilter extends InputFilter private function initialize(): void { $validSince = $this->createInput(self::VALID_SINCE, false); - $validSince->getValidatorChain()->attach(new Date(['format' => \DateTime::ATOM])); + $validSince->getValidatorChain()->attach(new Date(['format' => DateTime::ATOM])); $this->add($validSince); $validUntil = $this->createInput(self::VALID_UNTIL, false); - $validUntil->getValidatorChain()->attach(new Date(['format' => \DateTime::ATOM])); + $validUntil->getValidatorChain()->attach(new Date(['format' => DateTime::ATOM])); $this->add($validUntil); $this->add($this->createInput(self::CUSTOM_SLUG, false)); diff --git a/module/Core/test-func/Repository/ShortUrlRepositoryTest.php b/module/Core/test-func/Repository/ShortUrlRepositoryTest.php index c6766e43..311db98e 100644 --- a/module/Core/test-func/Repository/ShortUrlRepositoryTest.php +++ b/module/Core/test-func/Repository/ShortUrlRepositoryTest.php @@ -10,6 +10,7 @@ use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Repository\ShortUrlRepository; use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase; +use function count; class ShortUrlRepositoryTest extends DatabaseTestCase { @@ -131,7 +132,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase $result = $this->repo->findList(null, null, null, [], ['longUrl' => 'ASC']); - $this->assertCount(\count($urls), $result); + $this->assertCount(count($urls), $result); $this->assertEquals('a', $result[0]->getLongUrl()); $this->assertEquals('b', $result[1]->getLongUrl()); $this->assertEquals('c', $result[2]->getLongUrl()); diff --git a/module/Core/test/Action/PreviewActionTest.php b/module/Core/test/Action/PreviewActionTest.php index d1c0a23d..e49a6d72 100644 --- a/module/Core/test/Action/PreviewActionTest.php +++ b/module/Core/test/Action/PreviewActionTest.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Core\Action; +use finfo; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\MethodProphecy; @@ -76,7 +77,7 @@ class PreviewActionTest extends TestCase ); $this->assertEquals(filesize($path), $resp->getHeaderLine('Content-length')); - $this->assertEquals((new \finfo(FILEINFO_MIME))->file($path), $resp->getHeaderLine('Content-type')); + $this->assertEquals((new finfo(FILEINFO_MIME))->file($path), $resp->getHeaderLine('Content-type')); } /** diff --git a/module/Core/test/Exception/DeleteShortUrlExceptionTest.php b/module/Core/test/Exception/DeleteShortUrlExceptionTest.php index 6412233e..97f330ce 100644 --- a/module/Core/test/Exception/DeleteShortUrlExceptionTest.php +++ b/module/Core/test/Exception/DeleteShortUrlExceptionTest.php @@ -5,6 +5,8 @@ namespace ShlinkioTest\Shlink\Core\Exception; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException; +use function array_map; +use function range; class DeleteShortUrlExceptionTest extends TestCase { @@ -54,8 +56,8 @@ class DeleteShortUrlExceptionTest extends TestCase public function provideThresholds(): array { - return \array_map(function (int $number) { + return array_map(function (int $number) { return [$number]; - }, \range(5, 50, 5)); + }, range(5, 50, 5)); } } diff --git a/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php b/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php index d79ce44d..54f75bcb 100644 --- a/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php +++ b/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php @@ -14,6 +14,8 @@ use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException; use Shlinkio\Shlink\Core\Options\DeleteShortUrlsOptions; use Shlinkio\Shlink\Core\Repository\ShortUrlRepositoryInterface; use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlService; +use function array_map; +use function range; class DeleteShortUrlServiceTest extends TestCase { @@ -29,9 +31,9 @@ class DeleteShortUrlServiceTest extends TestCase public function setUp() { $shortUrl = (new ShortUrl())->setShortCode('abc123') - ->setVisits(new ArrayCollection(\array_map(function () { + ->setVisits(new ArrayCollection(array_map(function () { return new Visit(); - }, \range(0, 10)))); + }, range(0, 10)))); $this->em = $this->prophesize(EntityManagerInterface::class); diff --git a/module/Installer/src/Model/CustomizableAppConfig.php b/module/Installer/src/Model/CustomizableAppConfig.php index a882446c..2e307f3f 100644 --- a/module/Installer/src/Model/CustomizableAppConfig.php +++ b/module/Installer/src/Model/CustomizableAppConfig.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Installer\Model; +use PDO; use Shlinkio\Shlink\Common\Collection\PathCollection; use Shlinkio\Shlink\Installer\Config\Plugin\ApplicationConfigCustomizer; use Shlinkio\Shlink\Installer\Config\Plugin\DatabaseConfigCustomizer; @@ -206,7 +207,7 @@ final class CustomizableAppConfig implements ArraySerializableInterface if ($dbDriver === 'pdo_mysql') { $config['entity_manager']['connection']['driverOptions'] = [ - \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', ]; } } diff --git a/module/Installer/test/Command/InstallCommandTest.php b/module/Installer/test/Command/InstallCommandTest.php index bb2ce730..60115337 100644 --- a/module/Installer/test/Command/InstallCommandTest.php +++ b/module/Installer/test/Command/InstallCommandTest.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\ObjectProphecy; +use ReflectionObject; use Shlinkio\Shlink\Installer\Command\InstallCommand; use Shlinkio\Shlink\Installer\Config\ConfigCustomizerManagerInterface; use Shlinkio\Shlink\Installer\Config\Plugin\ConfigCustomizerInterface; @@ -124,7 +125,7 @@ class InstallCommandTest extends TestCase */ public function whenCommandIsUpdatePreviousConfigCanBeImported() { - $ref = new \ReflectionObject($this->command); + $ref = new ReflectionObject($this->command); $prop = $ref->getProperty('isUpdate'); $prop->setAccessible(true); $prop->setValue($this->command, true); diff --git a/module/Rest/src/Action/AbstractRestAction.php b/module/Rest/src/Action/AbstractRestAction.php index caf4f459..10b9de2a 100644 --- a/module/Rest/src/Action/AbstractRestAction.php +++ b/module/Rest/src/Action/AbstractRestAction.php @@ -8,6 +8,7 @@ use Fig\Http\Message\StatusCodeInterface; use Psr\Http\Server\RequestHandlerInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; +use function array_merge; abstract class AbstractRestAction implements RequestHandlerInterface, RequestMethodInterface, StatusCodeInterface { @@ -28,7 +29,7 @@ abstract class AbstractRestAction implements RequestHandlerInterface, RequestMet { return [ 'name' => static::class, - 'middleware' => \array_merge($prevMiddleware, [static::class], $postMiddleware), + 'middleware' => array_merge($prevMiddleware, [static::class], $postMiddleware), 'path' => static::ROUTE_PATH, 'allowed_methods' => static::ROUTE_ALLOWED_METHODS, ]; diff --git a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php index b34c1bac..5fd33714 100644 --- a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php @@ -14,8 +14,10 @@ use Shlinkio\Shlink\Core\Service\UrlShortenerInterface; use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; use Shlinkio\Shlink\Rest\Util\RestUtils; +use Throwable; use Zend\Diactoros\Response\JsonResponse; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; abstract class AbstractCreateShortUrlAction extends AbstractRestAction { @@ -80,7 +82,7 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction $this->logger->warning('Provided Invalid URL. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), - 'message' => \sprintf( + 'message' => sprintf( $this->translator->translate('Provided URL %s is invalid. Try with a different one.'), $longUrl ), @@ -89,12 +91,12 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction $this->logger->warning('Provided non-unique slug. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), - 'message' => \sprintf( + 'message' => sprintf( $this->translator->translate('Provided slug %s is already in use. Try with a different one.'), $customSlug ), ], self::STATUS_BAD_REQUEST); - } catch (\Throwable $e) { + } catch (Throwable $e) { $this->logger->error('Unexpected error creating short url. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, diff --git a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php index 01d6983b..e5c62e9b 100644 --- a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php @@ -13,6 +13,7 @@ use Shlinkio\Shlink\Rest\Util\RestUtils; use Zend\Diactoros\Response\EmptyResponse; use Zend\Diactoros\Response\JsonResponse; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; class DeleteShortUrlAction extends AbstractRestAction { @@ -55,7 +56,7 @@ class DeleteShortUrlAction extends AbstractRestAction ); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), - 'message' => \sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), + 'message' => sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), ], self::STATUS_NOT_FOUND); } catch (Exception\DeleteShortUrlException $e) { $this->logger->warning('Provided data is invalid. {e}', ['e' => $e]); @@ -65,7 +66,7 @@ class DeleteShortUrlAction extends AbstractRestAction return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), - 'message' => \sprintf($messagePlaceholder, $shortCode, $e->getVisitsThreshold()), + 'message' => sprintf($messagePlaceholder, $shortCode, $e->getVisitsThreshold()), ], self::STATUS_BAD_REQUEST); } } diff --git a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php index cbdb8a21..414dcb73 100644 --- a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php @@ -14,6 +14,7 @@ use Shlinkio\Shlink\Rest\Util\RestUtils; use Zend\Diactoros\Response\EmptyResponse; use Zend\Diactoros\Response\JsonResponse; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; class EditShortUrlAction extends AbstractRestAction { @@ -63,7 +64,7 @@ class EditShortUrlAction extends AbstractRestAction $this->logger->warning('Provided data is invalid. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), - 'message' => \sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), + 'message' => sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), ], self::STATUS_NOT_FOUND); } catch (Exception\ValidationException $e) { $this->logger->warning('Provided data is invalid. {e}', ['e' => $e]); diff --git a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php index cf28407a..88267cf9 100644 --- a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php +++ b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Rest\Action\ShortUrl; +use Exception; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Log\LoggerInterface; @@ -59,7 +60,7 @@ class ListShortUrlsAction extends AbstractRestAction return new JsonResponse(['shortUrls' => $this->serializePaginator($shortUrls, new ShortUrlDataTransformer( $this->domainConfig ))]); - } catch (\Exception $e) { + } catch (Exception $e) { $this->logger->error('Unexpected error while listing short URLs. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, diff --git a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php index 3052e662..b2c94858 100644 --- a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Rest\Action\ShortUrl; +use Exception; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Log\LoggerInterface; @@ -14,6 +15,7 @@ use Shlinkio\Shlink\Rest\Action\AbstractRestAction; use Shlinkio\Shlink\Rest\Util\RestUtils; use Zend\Diactoros\Response\JsonResponse; use Zend\I18n\Translator\TranslatorInterface; +use function sprintf; class ResolveShortUrlAction extends AbstractRestAction { @@ -62,7 +64,7 @@ class ResolveShortUrlAction extends AbstractRestAction $this->logger->warning('Provided short code with invalid format. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), - 'message' => \sprintf( + 'message' => sprintf( $this->translator->translate('Provided short code "%s" has an invalid format'), $shortCode ), @@ -71,9 +73,9 @@ class ResolveShortUrlAction extends AbstractRestAction $this->logger->warning('Provided short code couldn\'t be found. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::INVALID_ARGUMENT_ERROR, - 'message' => \sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), + 'message' => sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), ], self::STATUS_NOT_FOUND); - } catch (\Exception $e) { + } catch (Exception $e) { $this->logger->error('Unexpected error while resolving the URL behind a short code. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, diff --git a/module/Rest/src/Action/Visit/GetVisitsAction.php b/module/Rest/src/Action/Visit/GetVisitsAction.php index 67ff5fa1..f0cdba80 100644 --- a/module/Rest/src/Action/Visit/GetVisitsAction.php +++ b/module/Rest/src/Action/Visit/GetVisitsAction.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Rest\Action\Visit; use Cake\Chronos\Chronos; +use Exception; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Log\LoggerInterface; @@ -67,7 +68,7 @@ class GetVisitsAction extends AbstractRestAction $shortCode ), ], self::STATUS_NOT_FOUND); - } catch (\Exception $e) { + } catch (Exception $e) { $this->logger->error('Unexpected error while parsing short code {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, diff --git a/module/Rest/src/Authentication/JWTService.php b/module/Rest/src/Authentication/JWTService.php index 40b394b5..cf597445 100644 --- a/module/Rest/src/Authentication/JWTService.php +++ b/module/Rest/src/Authentication/JWTService.php @@ -7,6 +7,7 @@ use Firebase\JWT\JWT; use Shlinkio\Shlink\Core\Options\AppOptions; use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Exception\AuthenticationException; +use UnexpectedValueException; use function time; class JWTService implements JWTServiceInterface @@ -68,7 +69,7 @@ class JWTService implements JWTServiceInterface // If no exception is thrown while decoding the token, it is considered valid $this->decode($jwt); return true; - } catch (\UnexpectedValueException $e) { + } catch (UnexpectedValueException $e) { return false; } } @@ -84,7 +85,7 @@ class JWTService implements JWTServiceInterface { try { return $this->decode($jwt); - } catch (\UnexpectedValueException $e) { + } catch (UnexpectedValueException $e) { throw AuthenticationException::expiredJWT($e); } } diff --git a/module/Rest/src/ErrorHandler/JsonErrorResponseGenerator.php b/module/Rest/src/ErrorHandler/JsonErrorResponseGenerator.php index 035099c8..8b580efd 100644 --- a/module/Rest/src/ErrorHandler/JsonErrorResponseGenerator.php +++ b/module/Rest/src/ErrorHandler/JsonErrorResponseGenerator.php @@ -7,7 +7,10 @@ use Acelaya\ExpressiveErrorHandler\ErrorHandler\ErrorResponseGeneratorInterface; use Fig\Http\Message\StatusCodeInterface; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; +use Throwable; use Zend\Diactoros\Response\JsonResponse; +use function str_replace; +use function strtoupper; class JsonErrorResponseGenerator implements ErrorResponseGeneratorInterface, StatusCodeInterface { @@ -20,7 +23,7 @@ class JsonErrorResponseGenerator implements ErrorResponseGeneratorInterface, Sta * @return Response * @throws \InvalidArgumentException */ - public function __invoke(?\Throwable $e, Request $request, Response $response) + public function __invoke(?Throwable $e, Request $request, Response $response) { $status = $response->getStatusCode(); $responsePhrase = $status < 400 ? 'Internal Server Error' : $response->getReasonPhrase(); @@ -34,6 +37,6 @@ class JsonErrorResponseGenerator implements ErrorResponseGeneratorInterface, Sta private function responsePhraseToCode(string $responsePhrase): string { - return \strtoupper(\str_replace(' ', '_', $responsePhrase)); + return strtoupper(str_replace(' ', '_', $responsePhrase)); } } diff --git a/module/Rest/src/Exception/AuthenticationException.php b/module/Rest/src/Exception/AuthenticationException.php index 9bb29123..e1e0c9e4 100644 --- a/module/Rest/src/Exception/AuthenticationException.php +++ b/module/Rest/src/Exception/AuthenticationException.php @@ -3,9 +3,11 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Rest\Exception; +use Exception; + class AuthenticationException extends RuntimeException { - public static function expiredJWT(\Exception $prev = null): self + public static function expiredJWT(Exception $prev = null): self { return new self('The token has expired.', -1, $prev); } diff --git a/module/Rest/src/Exception/ExceptionInterface.php b/module/Rest/src/Exception/ExceptionInterface.php index 45df3e09..a0b9723c 100644 --- a/module/Rest/src/Exception/ExceptionInterface.php +++ b/module/Rest/src/Exception/ExceptionInterface.php @@ -3,6 +3,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Rest\Exception; -interface ExceptionInterface extends \Throwable +use Throwable; + +interface ExceptionInterface extends Throwable { } diff --git a/module/Rest/src/Exception/RuntimeException.php b/module/Rest/src/Exception/RuntimeException.php index e0a938ad..a2f3b8d2 100644 --- a/module/Rest/src/Exception/RuntimeException.php +++ b/module/Rest/src/Exception/RuntimeException.php @@ -3,6 +3,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Rest\Exception; -class RuntimeException extends \RuntimeException implements ExceptionInterface +use RuntimeException as SplRuntimeException; + +class RuntimeException extends SplRuntimeException implements ExceptionInterface { } diff --git a/module/Rest/src/Middleware/PathVersionMiddleware.php b/module/Rest/src/Middleware/PathVersionMiddleware.php index 40de9af1..cc28be0b 100644 --- a/module/Rest/src/Middleware/PathVersionMiddleware.php +++ b/module/Rest/src/Middleware/PathVersionMiddleware.php @@ -7,6 +7,7 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use function strpos; class PathVersionMiddleware implements MiddlewareInterface { @@ -26,7 +27,7 @@ class PathVersionMiddleware implements MiddlewareInterface $path = $uri->getPath(); // If the path does not begin with the version number, prepend v1 by default for BC compatibility purposes - if (\strpos($path, '/v') !== 0) { + if (strpos($path, '/v') !== 0) { $request = $request->withUri($uri->withPath('/v1' . $uri->getPath())); } diff --git a/module/Rest/src/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddleware.php b/module/Rest/src/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddleware.php index 8ea8f259..f5a9c956 100644 --- a/module/Rest/src/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddleware.php +++ b/module/Rest/src/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddleware.php @@ -9,6 +9,10 @@ use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use Zend\Diactoros\Response; use Zend\Diactoros\Response\JsonResponse; +use function array_shift; +use function explode; +use function strpos; +use function strtolower; class CreateShortUrlContentNegotiationMiddleware implements MiddlewareInterface { @@ -54,15 +58,15 @@ class CreateShortUrlContentNegotiationMiddleware implements MiddlewareInterface return self::JSON; } - $format = \strtolower((string) $query['format']); + $format = strtolower((string) $query['format']); return $format === 'txt' ? self::PLAIN_TEXT : self::JSON; } private function determineAcceptTypeFromHeader(string $acceptValue): string { - $accepts = \explode(',', $acceptValue); - $accept = \strtolower(\array_shift($accepts)); - return \strpos($accept, 'text/plain') !== false ? self::PLAIN_TEXT : self::JSON; + $accepts = explode(',', $acceptValue); + $accept = strtolower(array_shift($accepts)); + return strpos($accept, 'text/plain') !== false ? self::PLAIN_TEXT : self::JSON; } private function determineBody(JsonResponse $resp): string diff --git a/module/Rest/src/Middleware/ShortUrl/ShortCodePathMiddleware.php b/module/Rest/src/Middleware/ShortUrl/ShortCodePathMiddleware.php index a04a50b3..64c457c9 100644 --- a/module/Rest/src/Middleware/ShortUrl/ShortCodePathMiddleware.php +++ b/module/Rest/src/Middleware/ShortUrl/ShortCodePathMiddleware.php @@ -7,6 +7,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use function str_replace; class ShortCodePathMiddleware implements MiddlewareInterface { @@ -24,7 +25,7 @@ class ShortCodePathMiddleware implements MiddlewareInterface // If the path starts with the old prefix, replace it by the new one return $handler->handle( - $request->withUri($uri->withPath(\str_replace(self::OLD_PATH_PREFIX, self::NEW_PATH_PREFIX, $path))) + $request->withUri($uri->withPath(str_replace(self::OLD_PATH_PREFIX, self::NEW_PATH_PREFIX, $path))) ); } } diff --git a/module/Rest/src/Util/RestUtils.php b/module/Rest/src/Util/RestUtils.php index 35b6cbc9..848e5fcc 100644 --- a/module/Rest/src/Util/RestUtils.php +++ b/module/Rest/src/Util/RestUtils.php @@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Rest\Util; use Shlinkio\Shlink\Common\Exception as Common; use Shlinkio\Shlink\Core\Exception as Core; use Shlinkio\Shlink\Rest\Exception as Rest; +use Throwable; class RestUtils { @@ -22,7 +23,7 @@ class RestUtils public const NOT_FOUND_ERROR = 'NOT_FOUND'; public const UNKNOWN_ERROR = 'UNKNOWN_ERROR'; - public static function getRestErrorCodeFromException(\Throwable $e) + public static function getRestErrorCodeFromException(Throwable $e) { switch (true) { case $e instanceof Core\InvalidShortCodeException: diff --git a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php index d4d4e63c..15c9abfe 100644 --- a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl; +use Exception; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -111,7 +112,7 @@ class CreateShortUrlActionTest extends TestCase public function aGenericExceptionWillReturnError() { $this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'), Argument::cetera()) - ->willThrow(\Exception::class) + ->willThrow(Exception::class) ->shouldBeCalledTimes(1); $request = ServerRequestFactory::fromGlobals()->withParsedBody([ diff --git a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php index abcd61cf..7d0ef3b1 100644 --- a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php @@ -10,6 +10,7 @@ use Shlinkio\Shlink\Core\Exception; use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface; use Shlinkio\Shlink\Rest\Action\ShortUrl\DeleteShortUrlAction; use Shlinkio\Shlink\Rest\Util\RestUtils; +use Throwable; use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\ServerRequestFactory; use Zend\I18n\Translator\Translator; @@ -49,7 +50,7 @@ class DeleteShortUrlActionTest extends TestCase * @test * @dataProvider provideExceptions */ - public function returnsErrorResponseInCaseOfException(\Throwable $e, string $error, int $statusCode) + public function returnsErrorResponseInCaseOfException(Throwable $e, string $error, int $statusCode) { $deleteByShortCode = $this->service->deleteByShortCode(Argument::any())->willThrow($e); diff --git a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php index eecbb8d8..1e6ca82d 100644 --- a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl; +use Exception; use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\Service\ShortUrlService; @@ -53,7 +54,7 @@ class ListShortUrlsActionTest extends TestCase public function anExceptionsReturnsErrorResponse() { $page = 3; - $this->service->listShortUrls($page, null, [], null)->willThrow(\Exception::class) + $this->service->listShortUrls($page, null, [], null)->willThrow(Exception::class) ->shouldBeCalledTimes(1); $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([ diff --git a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php index a6159ec1..ba7c2dfa 100644 --- a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl; +use Exception; use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\Entity\ShortUrl; @@ -83,7 +84,7 @@ class ResolveShortUrlActionTest extends TestCase public function unexpectedExceptionWillReturnError() { $shortCode = 'abc123'; - $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(\Exception::class) + $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(Exception::class) ->shouldBeCalledTimes(1); $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); diff --git a/module/Rest/test/Action/Visit/GetVisitsActionTest.php b/module/Rest/test/Action/Visit/GetVisitsActionTest.php index ae9c518c..d5cff5fd 100644 --- a/module/Rest/test/Action/Visit/GetVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/GetVisitsActionTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Rest\Action\Visit; use Cake\Chronos\Chronos; +use Exception; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -65,7 +66,7 @@ class GetVisitsActionTest extends TestCase { $shortCode = 'abc123'; $this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willThrow( - \Exception::class + Exception::class )->shouldBeCalledTimes(1); $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)); diff --git a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php index ae483abf..3b0e8894 100644 --- a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php +++ b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php @@ -12,6 +12,7 @@ use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware; use Zend\Diactoros\Response; use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\Uri; +use function array_shift; class PathVersionMiddlewareTest extends TestCase { @@ -49,7 +50,7 @@ class PathVersionMiddlewareTest extends TestCase $delegate = $this->prophesize(RequestHandlerInterface::class); $delegate->handle(Argument::type(Request::class))->will(function (array $args) use ($request) { - $req = \array_shift($args); + $req = array_shift($args); Assert::assertNotSame($request, $req); Assert::assertEquals('/v1/bar/baz', $req->getUri()->getPath()); diff --git a/phpcs.xml b/phpcs.xml index 99e8af46..1e1fcda9 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -39,6 +39,8 @@ + + bin