From c01121d61a0a606bd4f8064423213f7e66243075 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 May 2021 12:31:10 +0200 Subject: [PATCH] Added nullsafe operator to simplify conditions --- module/CLI/src/Command/Api/ListKeysCommand.php | 2 +- module/CLI/src/Command/BaseCommand.php | 2 +- .../src/Command/ShortUrl/ListShortUrlsCommand.php | 15 ++++++--------- module/CLI/test/ApiKey/RoleResolverTest.php | 2 +- .../ShortUrl/DeleteShortUrlCommandTest.php | 2 +- .../Command/ShortUrl/ListShortUrlsCommandTest.php | 4 ++-- .../Visit/DownloadGeoLiteDbCommandTest.php | 2 +- .../Command/Visit/LocateVisitsCommandTest.php | 2 +- module/Core/src/Action/AbstractTrackingAction.php | 2 +- module/Core/src/Action/PixelAction.php | 2 +- module/Core/src/Domain/DomainService.php | 2 +- module/Core/src/Entity/ShortUrl.php | 6 +++--- .../CloseDbConnectionEventListenerDelegator.php | 2 +- .../Core/src/Importer/ImportedLinksProcessor.php | 4 ++-- module/Core/src/Importer/ShortUrlImporting.php | 5 +---- module/Core/src/Model/ShortUrlIdentifier.php | 2 +- .../Adapter/ShortUrlRepositoryAdapter.php | 10 ++-------- .../Adapter/VisitsForTagPaginatorAdapter.php | 10 ++-------- module/Core/src/Repository/ShortUrlRepository.php | 12 ++++++------ .../Repository/ShortUrlRepositoryInterface.php | 4 ++-- module/Core/src/Repository/VisitRepository.php | 12 ++++++------ .../Service/ShortUrl/DeleteShortUrlService.php | 2 +- .../ShortUrl/DeleteShortUrlServiceInterface.php | 2 +- .../src/Service/ShortUrl/ShortUrlResolver.php | 4 ++-- module/Core/src/Service/ShortUrlService.php | 2 +- .../Core/src/Service/ShortUrlServiceInterface.php | 2 +- module/Core/src/Service/UrlShortener.php | 2 +- module/Core/src/Spec/InDateRange.php | 4 ++-- module/Core/src/Visit/VisitsStatsHelper.php | 4 ++-- .../Core/src/Visit/VisitsStatsHelperInterface.php | 2 +- module/Core/test/Action/QrCodeActionTest.php | 2 +- module/Core/test/Config/BasePathPrefixerTest.php | 2 +- module/Core/test/Domain/DomainServiceTest.php | 2 +- module/Core/test/Entity/ShortUrlTest.php | 2 +- .../ErrorHandler/NotFoundRedirectHandlerTest.php | 2 +- .../test/EventDispatcher/UpdateGeoLiteDbTest.php | 2 +- .../Exception/DeleteShortUrlExceptionTest.php | 2 +- .../ForbiddenTagOperationExceptionTest.php | 2 +- .../Exception/ShortUrlNotFoundExceptionTest.php | 2 +- .../test/Importer/ImportedLinksProcessorTest.php | 2 +- .../Adapter/ShortUrlRepositoryAdapterTest.php | 4 ++-- .../Adapter/VisitsPaginatorAdapterTest.php | 2 +- .../Service/ShortUrl/ShortUrlResolverTest.php | 4 ++-- module/Core/test/Service/ShortUrlServiceTest.php | 2 +- .../ShortUrl/Helper/ShortUrlStringifierTest.php | 2 +- module/Core/test/Util/DoctrineBatchHelperTest.php | 2 +- .../Core/test/Util/RedirectResponseHelperTest.php | 2 +- module/Core/test/Util/UrlValidatorTest.php | 2 +- module/Core/test/Visit/VisitLocatorTest.php | 4 ++-- module/Core/test/Visit/VisitsStatsHelperTest.php | 2 +- module/Rest/src/Entity/ApiKey.php | 2 +- module/Rest/src/Service/ApiKeyService.php | 2 +- .../Rest/src/Service/ApiKeyServiceInterface.php | 2 +- .../Rest/test-api/Action/DeleteShortUrlTest.php | 2 +- .../Rest/test-api/Action/EditShortUrlTagsTest.php | 2 +- module/Rest/test-api/Action/EditShortUrlTest.php | 6 +++--- module/Rest/test-api/Action/OrphanVisitsTest.php | 2 +- .../Rest/test-api/Action/ResolveShortUrlTest.php | 2 +- .../Rest/test-api/Action/ShortUrlVisitsTest.php | 2 +- module/Rest/test-api/Action/TagVisitsTest.php | 2 +- module/Rest/test-api/Middleware/CorsTest.php | 2 +- .../Action/ShortUrl/ListShortUrlsActionTest.php | 2 +- .../Middleware/AuthenticationMiddlewareTest.php | 2 +- .../test/Middleware/CrossDomainMiddlewareTest.php | 4 ++-- 64 files changed, 95 insertions(+), 113 deletions(-) diff --git a/module/CLI/src/Command/Api/ListKeysCommand.php b/module/CLI/src/Command/Api/ListKeysCommand.php index 6a7124e3..f435f1ea 100644 --- a/module/CLI/src/Command/Api/ListKeysCommand.php +++ b/module/CLI/src/Command/Api/ListKeysCommand.php @@ -58,7 +58,7 @@ class ListKeysCommand extends BaseCommand if (! $enabledOnly) { $rowData[] = sprintf($messagePattern, $this->getEnabledSymbol($apiKey)); } - $rowData[] = $expiration !== null ? $expiration->toAtomString() : '-'; + $rowData[] = $expiration?->toAtomString() ?? '-'; $rowData[] = $apiKey->isAdmin() ? 'Admin' : implode("\n", $apiKey->mapRoles( fn (string $roleName, array $meta) => empty($meta) diff --git a/module/CLI/src/Command/BaseCommand.php b/module/CLI/src/Command/BaseCommand.php index 443b37ec..ef6b5435 100644 --- a/module/CLI/src/Command/BaseCommand.php +++ b/module/CLI/src/Command/BaseCommand.php @@ -22,7 +22,7 @@ abstract class BaseCommand extends Command ?string $shortcut = null, ?int $mode = null, string $description = '', - $default = null + $default = null, ): self { $this->addOption($name, $shortcut, $mode, $description, $default); diff --git a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php index 9673641d..b5d242dc 100644 --- a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php @@ -126,8 +126,8 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand ShortUrlsParamsInputFilter::SEARCH_TERM => $searchTerm, ShortUrlsParamsInputFilter::TAGS => $tags, ShortUrlsOrdering::ORDER_BY => $orderBy, - ShortUrlsParamsInputFilter::START_DATE => $startDate !== null ? $startDate->toAtomString() : null, - ShortUrlsParamsInputFilter::END_DATE => $endDate !== null ? $endDate->toAtomString() : null, + ShortUrlsParamsInputFilter::START_DATE => $startDate?->toAtomString(), + ShortUrlsParamsInputFilter::END_DATE => $endDate?->toAtomString(), ]; if ($all) { @@ -155,7 +155,7 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand OutputInterface $output, array $columnsMap, ShortUrlsParams $params, - bool $all + bool $all, ): Paginator { $shortUrls = $this->shortUrlService->listShortUrls($params); @@ -200,14 +200,11 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand } if ($input->getOption('show-api-key')) { $columnsMap['API Key'] = static fn (array $_, ShortUrl $shortUrl): string => - (string) $shortUrl->authorApiKey(); + (string) $shortUrl->authorApiKey(); } if ($input->getOption('show-api-key-name')) { - $columnsMap['API Key Name'] = static function (array $_, ShortUrl $shortUrl): ?string { - $apiKey = $shortUrl->authorApiKey(); - - return $apiKey !== null ? $apiKey->name() : null; - }; + $columnsMap['API Key Name'] = static fn (array $_, ShortUrl $shortUrl): ?string => + $shortUrl->authorApiKey()?->name(); } return $columnsMap; diff --git a/module/CLI/test/ApiKey/RoleResolverTest.php b/module/CLI/test/ApiKey/RoleResolverTest.php index a50c2b12..5e4de2c3 100644 --- a/module/CLI/test/ApiKey/RoleResolverTest.php +++ b/module/CLI/test/ApiKey/RoleResolverTest.php @@ -33,7 +33,7 @@ class RoleResolverTest extends TestCase public function properRolesAreResolvedBasedOnInput( InputInterface $input, array $expectedRoles, - int $expectedDomainCalls + int $expectedDomainCalls, ): void { $getDomain = $this->domainService->getOrCreate('example.com')->willReturn( (new Domain('example.com'))->setId('1'), diff --git a/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php index a6b6fc78..765a1c4b 100644 --- a/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php @@ -74,7 +74,7 @@ class DeleteShortUrlCommandTest extends TestCase public function deleteIsRetriedWhenThresholdIsReachedAndQuestionIsAccepted( array $retryAnswer, int $expectedDeleteCalls, - string $expectedMessage + string $expectedMessage, ): void { $shortCode = 'abc123'; $identifier = new ShortUrlIdentifier($shortCode); diff --git a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php index 6f7b11a6..f4ba2bb1 100644 --- a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php @@ -110,7 +110,7 @@ class ListShortUrlsCommandTest extends TestCase array $input, array $expectedContents, array $notExpectedContents, - ApiKey $apiKey + ApiKey $apiKey, ): void { $this->shortUrlService->listShortUrls(ShortUrlsParams::emptyInstance()) ->willReturn(new Paginator(new ArrayAdapter([ @@ -185,7 +185,7 @@ class ListShortUrlsCommandTest extends TestCase ?string $searchTerm, array $tags, ?string $startDate = null, - ?string $endDate = null + ?string $endDate = null, ): void { $listShortUrls = $this->shortUrlService->listShortUrls(ShortUrlsParams::fromRawData([ 'page' => $page, diff --git a/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php b/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php index 7ead517d..62ea161a 100644 --- a/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php +++ b/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php @@ -36,7 +36,7 @@ class DownloadGeoLiteDbCommandTest extends TestCase public function showsProperMessageWhenGeoLiteUpdateFails( bool $olderDbExists, string $expectedMessage, - int $expectedExitCode + int $expectedExitCode, ): void { $checkDbUpdate = $this->dbUpdater->checkDbUpdate(Argument::cetera())->will( function (array $args) use ($olderDbExists): void { diff --git a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php index 74148f9c..fa666516 100644 --- a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php @@ -73,7 +73,7 @@ class LocateVisitsCommandTest extends TestCase int $expectedEmptyCalls, int $expectedAllCalls, bool $expectWarningPrint, - array $args + array $args, ): void { $visit = Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('', '', '1.2.3.4', '')); $location = VisitLocation::fromGeolocation(Location::emptyInstance()); diff --git a/module/Core/src/Action/AbstractTrackingAction.php b/module/Core/src/Action/AbstractTrackingAction.php index 582b7bce..7de21fa8 100644 --- a/module/Core/src/Action/AbstractTrackingAction.php +++ b/module/Core/src/Action/AbstractTrackingAction.php @@ -84,6 +84,6 @@ abstract class AbstractTrackingAction implements MiddlewareInterface, RequestMet abstract protected function createErrorResp( ServerRequestInterface $request, - RequestHandlerInterface $handler + RequestHandlerInterface $handler, ): ResponseInterface; } diff --git a/module/Core/src/Action/PixelAction.php b/module/Core/src/Action/PixelAction.php index 5435c582..3f67bdec 100644 --- a/module/Core/src/Action/PixelAction.php +++ b/module/Core/src/Action/PixelAction.php @@ -18,7 +18,7 @@ class PixelAction extends AbstractTrackingAction protected function createErrorResp( ServerRequestInterface $request, - RequestHandlerInterface $handler + RequestHandlerInterface $handler, ): ResponseInterface { return new PixelResponse(); } diff --git a/module/Core/src/Domain/DomainService.php b/module/Core/src/Domain/DomainService.php index 3a582ee6..95ba05c5 100644 --- a/module/Core/src/Domain/DomainService.php +++ b/module/Core/src/Domain/DomainService.php @@ -30,7 +30,7 @@ class DomainService implements DomainServiceInterface $domains = $repo->findDomainsWithout($this->defaultDomain, $apiKey); $mappedDomains = map($domains, fn (Domain $domain) => new DomainItem($domain->getAuthority(), false)); - if ($apiKey !== null && $apiKey->hasRole(Role::DOMAIN_SPECIFIC)) { + if ($apiKey?->hasRole(Role::DOMAIN_SPECIFIC)) { return $mappedDomains; } diff --git a/module/Core/src/Entity/ShortUrl.php b/module/Core/src/Entity/ShortUrl.php index 6f502da3..78527115 100644 --- a/module/Core/src/Entity/ShortUrl.php +++ b/module/Core/src/Entity/ShortUrl.php @@ -60,7 +60,7 @@ class ShortUrl extends AbstractEntity public static function fromMeta( ShortUrlMeta $meta, - ?ShortUrlRelationResolverInterface $relationResolver = null + ?ShortUrlRelationResolverInterface $relationResolver = null, ): self { $instance = new self(); $relationResolver = $relationResolver ?? new SimpleShortUrlRelationResolver(); @@ -87,7 +87,7 @@ class ShortUrl extends AbstractEntity public static function fromImport( ImportedShlinkUrl $url, bool $importShortCode, - ?ShortUrlRelationResolverInterface $relationResolver = null + ?ShortUrlRelationResolverInterface $relationResolver = null, ): self { $meta = [ ShortUrlInputFilter::VALIDATE_URL => false, @@ -209,7 +209,7 @@ class ShortUrl extends AbstractEntity public function update( ShortUrlEdit $shortUrlEdit, - ?ShortUrlRelationResolverInterface $relationResolver = null + ?ShortUrlRelationResolverInterface $relationResolver = null, ): void { if ($shortUrlEdit->validSinceWasProvided()) { $this->validSince = $shortUrlEdit->validSince(); diff --git a/module/Core/src/EventDispatcher/CloseDbConnectionEventListenerDelegator.php b/module/Core/src/EventDispatcher/CloseDbConnectionEventListenerDelegator.php index cbfc7208..6f8f00d1 100644 --- a/module/Core/src/EventDispatcher/CloseDbConnectionEventListenerDelegator.php +++ b/module/Core/src/EventDispatcher/CloseDbConnectionEventListenerDelegator.php @@ -12,7 +12,7 @@ class CloseDbConnectionEventListenerDelegator public function __invoke( ContainerInterface $container, string $name, - callable $callback + callable $callback, ): CloseDbConnectionEventListener { /** @var callable $wrapped */ $wrapped = $callback(); diff --git a/module/Core/src/Importer/ImportedLinksProcessor.php b/module/Core/src/Importer/ImportedLinksProcessor.php index 7427057f..6073dd26 100644 --- a/module/Core/src/Importer/ImportedLinksProcessor.php +++ b/module/Core/src/Importer/ImportedLinksProcessor.php @@ -69,7 +69,7 @@ class ImportedLinksProcessor implements ImportedLinksProcessorInterface private function resolveShortUrl( ImportedShlinkUrl $importedUrl, bool $importShortCodes, - callable $skipOnShortCodeConflict + callable $skipOnShortCodeConflict, ): ShortUrlImporting { $alreadyImportedShortUrl = $this->shortUrlRepo->findOneByImportedUrl($importedUrl); if ($alreadyImportedShortUrl !== null) { @@ -88,7 +88,7 @@ class ImportedLinksProcessor implements ImportedLinksProcessorInterface private function handleShortCodeUniqueness( ShortUrl $shortUrl, bool $importShortCodes, - callable $skipOnShortCodeConflict + callable $skipOnShortCodeConflict, ): bool { if ($this->shortCodeHelper->ensureShortCodeUniqueness($shortUrl, $importShortCodes)) { return true; diff --git a/module/Core/src/Importer/ShortUrlImporting.php b/module/Core/src/Importer/ShortUrlImporting.php index 9b3fa998..a925c5d5 100644 --- a/module/Core/src/Importer/ShortUrlImporting.php +++ b/module/Core/src/Importer/ShortUrlImporting.php @@ -38,10 +38,7 @@ final class ShortUrlImporting $importedVisits = 0; foreach ($visits as $importedVisit) { // Skip visits which are older than the most recent already imported visit's date - if ( - $mostRecentImportedDate !== null - && $mostRecentImportedDate->gte(Chronos::instance($importedVisit->date())) - ) { + if ($mostRecentImportedDate?->gte(Chronos::instance($importedVisit->date()))) { continue; } diff --git a/module/Core/src/Model/ShortUrlIdentifier.php b/module/Core/src/Model/ShortUrlIdentifier.php index cf7c17d3..e0d6c9b4 100644 --- a/module/Core/src/Model/ShortUrlIdentifier.php +++ b/module/Core/src/Model/ShortUrlIdentifier.php @@ -41,7 +41,7 @@ final class ShortUrlIdentifier public static function fromShortUrl(ShortUrl $shortUrl): self { $domain = $shortUrl->getDomain(); - $domainAuthority = $domain !== null ? $domain->getAuthority() : null; + $domainAuthority = $domain?->getAuthority(); return new self($shortUrl->getShortCode(), $domainAuthority); } diff --git a/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php b/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php index a0d4305f..e297b6c0 100644 --- a/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php +++ b/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Paginator\Adapter; -use Happyr\DoctrineSpecification\Specification\Specification; use Pagerfanta\Adapter\AdapterInterface; use Shlinkio\Shlink\Core\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\Repository\ShortUrlRepositoryInterface; @@ -28,7 +27,7 @@ class ShortUrlRepositoryAdapter implements AdapterInterface $this->params->tags(), $this->params->orderBy(), $this->params->dateRange(), - $this->resolveSpec(), + $this->apiKey?->spec(), ); } @@ -38,12 +37,7 @@ class ShortUrlRepositoryAdapter implements AdapterInterface $this->params->searchTerm(), $this->params->tags(), $this->params->dateRange(), - $this->resolveSpec(), + $this->apiKey?->spec(), ); } - - private function resolveSpec(): ?Specification - { - return $this->apiKey !== null ? $this->apiKey->spec() : null; - } } diff --git a/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php b/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php index 2dfdc618..dbbf8bb9 100644 --- a/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php +++ b/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Paginator\Adapter; -use Happyr\DoctrineSpecification\Specification\Specification; use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Repository\VisitRepositoryInterface; use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering; @@ -28,7 +27,7 @@ class VisitsForTagPaginatorAdapter extends AbstractCacheableCountPaginatorAdapte new VisitsListFiltering( $this->params->getDateRange(), $this->params->excludeBots(), - $this->resolveSpec(), + $this->apiKey?->spec(true), $length, $offset, ), @@ -42,13 +41,8 @@ class VisitsForTagPaginatorAdapter extends AbstractCacheableCountPaginatorAdapte new VisitsCountFiltering( $this->params->getDateRange(), $this->params->excludeBots(), - $this->resolveSpec(), + $this->apiKey?->spec(true), ), ); } - - private function resolveSpec(): ?Specification - { - return $this->apiKey !== null ? $this->apiKey->spec(true) : null; - } } diff --git a/module/Core/src/Repository/ShortUrlRepository.php b/module/Core/src/Repository/ShortUrlRepository.php index c658d478..c4ccedbf 100644 --- a/module/Core/src/Repository/ShortUrlRepository.php +++ b/module/Core/src/Repository/ShortUrlRepository.php @@ -35,7 +35,7 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU array $tags = [], ?ShortUrlsOrdering $orderBy = null, ?DateRange $dateRange = null, - ?Specification $spec = null + ?Specification $spec = null, ): array { $qb = $this->createListQueryBuilder($searchTerm, $tags, $dateRange, $spec); $qb->select('DISTINCT s') @@ -43,7 +43,7 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU ->setFirstResult($offset); // In case the ordering has been specified, the query could be more complex. Process it - if ($orderBy !== null && $orderBy->hasOrderField()) { + if ($orderBy?->hasOrderField()) { return $this->processOrderByForList($qb, $orderBy); } @@ -85,7 +85,7 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU ?string $searchTerm = null, array $tags = [], ?DateRange $dateRange = null, - ?Specification $spec = null + ?Specification $spec = null, ): int { $qb = $this->createListQueryBuilder($searchTerm, $tags, $dateRange, $spec); $qb->select('COUNT(DISTINCT s)'); @@ -97,17 +97,17 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU ?string $searchTerm, array $tags, ?DateRange $dateRange, - ?Specification $spec + ?Specification $spec, ): QueryBuilder { $qb = $this->getEntityManager()->createQueryBuilder(); $qb->from(ShortUrl::class, 's') ->where('1=1'); - if ($dateRange !== null && $dateRange->getStartDate() !== null) { + if ($dateRange?->getStartDate() !== null) { $qb->andWhere($qb->expr()->gte('s.dateCreated', ':startDate')); $qb->setParameter('startDate', $dateRange->getStartDate(), ChronosDateTimeType::CHRONOS_DATETIME); } - if ($dateRange !== null && $dateRange->getEndDate() !== null) { + if ($dateRange?->getEndDate() !== null) { $qb->andWhere($qb->expr()->lte('s.dateCreated', ':endDate')); $qb->setParameter('endDate', $dateRange->getEndDate(), ChronosDateTimeType::CHRONOS_DATETIME); } diff --git a/module/Core/src/Repository/ShortUrlRepositoryInterface.php b/module/Core/src/Repository/ShortUrlRepositoryInterface.php index 7489f2a0..e2927286 100644 --- a/module/Core/src/Repository/ShortUrlRepositoryInterface.php +++ b/module/Core/src/Repository/ShortUrlRepositoryInterface.php @@ -23,14 +23,14 @@ interface ShortUrlRepositoryInterface extends ObjectRepository, EntitySpecificat array $tags = [], ?ShortUrlsOrdering $orderBy = null, ?DateRange $dateRange = null, - ?Specification $spec = null + ?Specification $spec = null, ): array; public function countList( ?string $searchTerm = null, array $tags = [], ?DateRange $dateRange = null, - ?Specification $spec = null + ?Specification $spec = null, ): int; public function findOneWithDomainFallback(string $shortCode, ?string $domain = null): ?ShortUrl; diff --git a/module/Core/src/Repository/VisitRepository.php b/module/Core/src/Repository/VisitRepository.php index 61cd108e..6adba193 100644 --- a/module/Core/src/Repository/VisitRepository.php +++ b/module/Core/src/Repository/VisitRepository.php @@ -71,14 +71,14 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo $iterator = $qb->getQuery()->toIterable(); $resultsFound = false; - /** @var Visit $visit */ foreach ($iterator as $key => $visit) { $resultsFound = true; yield $key => $visit; } // As the query is ordered by ID, we can take the last one every time in order to exclude the whole list - $lastId = isset($visit) ? $visit->getId() : $lastId; + /** @var Visit|null $visit */ + $lastId = $visit?->getId() ?? $lastId; } while ($resultsFound); } @@ -101,12 +101,12 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo private function createVisitsByShortCodeQueryBuilder( ShortUrlIdentifier $identifier, - VisitsCountFiltering $filtering + VisitsCountFiltering $filtering, ): QueryBuilder { /** @var ShortUrlRepositoryInterface $shortUrlRepo */ $shortUrlRepo = $this->getEntityManager()->getRepository(ShortUrl::class); $shortUrl = $shortUrlRepo->findOne($identifier, $filtering->spec()); - $shortUrlId = $shortUrl !== null ? $shortUrl->getId() : -1; + $shortUrlId = $shortUrl?->getId() ?? '-1'; // Parameters in this query need to be part of the query itself, as we need to use it a sub-query later // Since they are not strictly provided by the caller, it's reasonably safe @@ -187,10 +187,10 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo private function applyDatesInline(QueryBuilder $qb, ?DateRange $dateRange): void { - if ($dateRange !== null && $dateRange->getStartDate() !== null) { + if ($dateRange?->getStartDate() !== null) { $qb->andWhere($qb->expr()->gte('v.date', '\'' . $dateRange->getStartDate()->toDateTimeString() . '\'')); } - if ($dateRange !== null && $dateRange->getEndDate() !== null) { + if ($dateRange?->getEndDate() !== null) { $qb->andWhere($qb->expr()->lte('v.date', '\'' . $dateRange->getEndDate()->toDateTimeString() . '\'')); } } diff --git a/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php b/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php index 53d0db61..1bcd5ccb 100644 --- a/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php +++ b/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php @@ -27,7 +27,7 @@ class DeleteShortUrlService implements DeleteShortUrlServiceInterface public function deleteByShortCode( ShortUrlIdentifier $identifier, bool $ignoreThreshold = false, - ?ApiKey $apiKey = null + ?ApiKey $apiKey = null, ): void { $shortUrl = $this->urlResolver->resolveShortUrl($identifier, $apiKey); if (! $ignoreThreshold && $this->isThresholdReached($shortUrl)) { diff --git a/module/Core/src/Service/ShortUrl/DeleteShortUrlServiceInterface.php b/module/Core/src/Service/ShortUrl/DeleteShortUrlServiceInterface.php index b1f01839..0767c723 100644 --- a/module/Core/src/Service/ShortUrl/DeleteShortUrlServiceInterface.php +++ b/module/Core/src/Service/ShortUrl/DeleteShortUrlServiceInterface.php @@ -17,6 +17,6 @@ interface DeleteShortUrlServiceInterface public function deleteByShortCode( ShortUrlIdentifier $identifier, bool $ignoreThreshold = false, - ?ApiKey $apiKey = null + ?ApiKey $apiKey = null, ): void; } diff --git a/module/Core/src/Service/ShortUrl/ShortUrlResolver.php b/module/Core/src/Service/ShortUrl/ShortUrlResolver.php index 09cd2005..61c57d36 100644 --- a/module/Core/src/Service/ShortUrl/ShortUrlResolver.php +++ b/module/Core/src/Service/ShortUrl/ShortUrlResolver.php @@ -24,7 +24,7 @@ class ShortUrlResolver implements ShortUrlResolverInterface { /** @var ShortUrlRepository $shortUrlRepo */ $shortUrlRepo = $this->em->getRepository(ShortUrl::class); - $shortUrl = $shortUrlRepo->findOne($identifier, $apiKey !== null ? $apiKey->spec() : null); + $shortUrl = $shortUrlRepo->findOne($identifier, $apiKey?->spec()); if ($shortUrl === null) { throw ShortUrlNotFoundException::fromNotFound($identifier); } @@ -40,7 +40,7 @@ class ShortUrlResolver implements ShortUrlResolverInterface /** @var ShortUrlRepository $shortUrlRepo */ $shortUrlRepo = $this->em->getRepository(ShortUrl::class); $shortUrl = $shortUrlRepo->findOneWithDomainFallback($identifier->shortCode(), $identifier->domain()); - if ($shortUrl === null || ! $shortUrl->isEnabled()) { + if (! $shortUrl?->isEnabled()) { throw ShortUrlNotFoundException::fromNotFound($identifier); } diff --git a/module/Core/src/Service/ShortUrlService.php b/module/Core/src/Service/ShortUrlService.php index f8a144cc..2a576ce9 100644 --- a/module/Core/src/Service/ShortUrlService.php +++ b/module/Core/src/Service/ShortUrlService.php @@ -50,7 +50,7 @@ class ShortUrlService implements ShortUrlServiceInterface public function updateShortUrl( ShortUrlIdentifier $identifier, ShortUrlEdit $shortUrlEdit, - ?ApiKey $apiKey = null + ?ApiKey $apiKey = null, ): ShortUrl { if ($shortUrlEdit->longUrlWasProvided()) { /** @var ShortUrlEdit $shortUrlEdit */ diff --git a/module/Core/src/Service/ShortUrlServiceInterface.php b/module/Core/src/Service/ShortUrlServiceInterface.php index 3884b55e..e0a73981 100644 --- a/module/Core/src/Service/ShortUrlServiceInterface.php +++ b/module/Core/src/Service/ShortUrlServiceInterface.php @@ -27,6 +27,6 @@ interface ShortUrlServiceInterface public function updateShortUrl( ShortUrlIdentifier $identifier, ShortUrlEdit $shortUrlEdit, - ?ApiKey $apiKey = null + ?ApiKey $apiKey = null, ): ShortUrl; } diff --git a/module/Core/src/Service/UrlShortener.php b/module/Core/src/Service/UrlShortener.php index ff2b5f62..24ac2c70 100644 --- a/module/Core/src/Service/UrlShortener.php +++ b/module/Core/src/Service/UrlShortener.php @@ -69,7 +69,7 @@ class UrlShortener implements UrlShortenerInterface if (! $couldBeMadeUnique) { $domain = $shortUrlToBeCreated->getDomain(); - $domainAuthority = $domain !== null ? $domain->getAuthority() : null; + $domainAuthority = $domain?->getAuthority(); throw NonUniqueSlugException::fromSlug($shortUrlToBeCreated->getShortCode(), $domainAuthority); } diff --git a/module/Core/src/Spec/InDateRange.php b/module/Core/src/Spec/InDateRange.php index 7ddcf0a4..81d11b9e 100644 --- a/module/Core/src/Spec/InDateRange.php +++ b/module/Core/src/Spec/InDateRange.php @@ -20,11 +20,11 @@ class InDateRange extends BaseSpecification { $criteria = []; - if ($this->dateRange !== null && $this->dateRange->getStartDate() !== null) { + if ($this->dateRange?->getStartDate() !== null) { $criteria[] = Spec::gte($this->field, $this->dateRange->getStartDate()->toDateTimeString()); } - if ($this->dateRange !== null && $this->dateRange->getEndDate() !== null) { + if ($this->dateRange?->getEndDate() !== null) { $criteria[] = Spec::lte($this->field, $this->dateRange->getEndDate()->toDateTimeString()); } diff --git a/module/Core/src/Visit/VisitsStatsHelper.php b/module/Core/src/Visit/VisitsStatsHelper.php index 06f990f6..8138d170 100644 --- a/module/Core/src/Visit/VisitsStatsHelper.php +++ b/module/Core/src/Visit/VisitsStatsHelper.php @@ -49,9 +49,9 @@ class VisitsStatsHelper implements VisitsStatsHelperInterface public function visitsForShortUrl( ShortUrlIdentifier $identifier, VisitsParams $params, - ?ApiKey $apiKey = null + ?ApiKey $apiKey = null, ): Paginator { - $spec = $apiKey !== null ? $apiKey->spec() : null; + $spec = $apiKey?->spec(); /** @var ShortUrlRepositoryInterface $repo */ $repo = $this->em->getRepository(ShortUrl::class); diff --git a/module/Core/src/Visit/VisitsStatsHelperInterface.php b/module/Core/src/Visit/VisitsStatsHelperInterface.php index d2bf6032..5e15be4f 100644 --- a/module/Core/src/Visit/VisitsStatsHelperInterface.php +++ b/module/Core/src/Visit/VisitsStatsHelperInterface.php @@ -24,7 +24,7 @@ interface VisitsStatsHelperInterface public function visitsForShortUrl( ShortUrlIdentifier $identifier, VisitsParams $params, - ?ApiKey $apiKey = null + ?ApiKey $apiKey = null, ): Paginator; /** diff --git a/module/Core/test/Action/QrCodeActionTest.php b/module/Core/test/Action/QrCodeActionTest.php index aeaec13f..7326c41c 100644 --- a/module/Core/test/Action/QrCodeActionTest.php +++ b/module/Core/test/Action/QrCodeActionTest.php @@ -84,7 +84,7 @@ class QrCodeActionTest extends TestCase */ public function imageIsReturnedWithExpectedContentTypeBasedOnProvidedFormat( array $query, - string $expectedContentType + string $expectedContentType, ): void { $code = 'abc123'; $this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($code, ''))->willReturn( diff --git a/module/Core/test/Config/BasePathPrefixerTest.php b/module/Core/test/Config/BasePathPrefixerTest.php index e0949514..f01b9195 100644 --- a/module/Core/test/Config/BasePathPrefixerTest.php +++ b/module/Core/test/Config/BasePathPrefixerTest.php @@ -24,7 +24,7 @@ class BasePathPrefixerTest extends TestCase array $originalConfig, array $expectedRoutes, array $expectedMiddlewares, - string $expectedHostname + string $expectedHostname, ): void { [ 'routes' => $routes, diff --git a/module/Core/test/Domain/DomainServiceTest.php b/module/Core/test/Domain/DomainServiceTest.php index 0306f387..80326b3c 100644 --- a/module/Core/test/Domain/DomainServiceTest.php +++ b/module/Core/test/Domain/DomainServiceTest.php @@ -126,7 +126,7 @@ class DomainServiceTest extends TestCase $repo = $this->prophesize(DomainRepositoryInterface::class); $repo->findOneBy(['authority' => $authority])->willReturn($foundDomain); $getRepo = $this->em->getRepository(Domain::class)->willReturn($repo->reveal()); - $persist = $this->em->persist($foundDomain !== null ? $foundDomain : Argument::type(Domain::class)); + $persist = $this->em->persist($foundDomain ?? Argument::type(Domain::class)); $flush = $this->em->flush(); $result = $this->domainService->getOrCreate($authority); diff --git a/module/Core/test/Entity/ShortUrlTest.php b/module/Core/test/Entity/ShortUrlTest.php index fceba3e2..89ccc805 100644 --- a/module/Core/test/Entity/ShortUrlTest.php +++ b/module/Core/test/Entity/ShortUrlTest.php @@ -26,7 +26,7 @@ class ShortUrlTest extends TestCase */ public function regenerateShortCodeThrowsExceptionIfStateIsInvalid( ShortUrl $shortUrl, - string $expectedMessage + string $expectedMessage, ): void { $this->expectException(ShortCodeCannotBeRegeneratedException::class); $this->expectExceptionMessage($expectedMessage); diff --git a/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php b/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php index 9df49879..f3054f49 100644 --- a/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php +++ b/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php @@ -43,7 +43,7 @@ class NotFoundRedirectHandlerTest extends TestCase */ public function expectedRedirectionIsReturnedDependingOnTheCase( ServerRequestInterface $request, - string $expectedRedirectTo + string $expectedRedirectTo, ): void { $this->redirectOptions->invalidShortUrl = 'invalidShortUrl'; $this->redirectOptions->regular404 = 'regular404'; diff --git a/module/Core/test/EventDispatcher/UpdateGeoLiteDbTest.php b/module/Core/test/EventDispatcher/UpdateGeoLiteDbTest.php index a492f9dd..178a142f 100644 --- a/module/Core/test/EventDispatcher/UpdateGeoLiteDbTest.php +++ b/module/Core/test/EventDispatcher/UpdateGeoLiteDbTest.php @@ -79,7 +79,7 @@ class UpdateGeoLiteDbTest extends TestCase int $total, int $downloaded, bool $oldDbExists, - ?string $expectedMessage + ?string $expectedMessage, ): void { $checkDbUpdate = $this->dbUpdater->checkDbUpdate(Argument::cetera())->will( function (array $args) use ($total, $downloaded, $oldDbExists): void { diff --git a/module/Core/test/Exception/DeleteShortUrlExceptionTest.php b/module/Core/test/Exception/DeleteShortUrlExceptionTest.php index a7028a02..43dcc2e5 100644 --- a/module/Core/test/Exception/DeleteShortUrlExceptionTest.php +++ b/module/Core/test/Exception/DeleteShortUrlExceptionTest.php @@ -21,7 +21,7 @@ class DeleteShortUrlExceptionTest extends TestCase public function fromVisitsThresholdGeneratesMessageProperly( int $threshold, string $shortCode, - string $expectedMessage + string $expectedMessage, ): void { $e = DeleteShortUrlException::fromVisitsThreshold($threshold, $shortCode); diff --git a/module/Core/test/Exception/ForbiddenTagOperationExceptionTest.php b/module/Core/test/Exception/ForbiddenTagOperationExceptionTest.php index c42f864a..40ccd0ee 100644 --- a/module/Core/test/Exception/ForbiddenTagOperationExceptionTest.php +++ b/module/Core/test/Exception/ForbiddenTagOperationExceptionTest.php @@ -15,7 +15,7 @@ class ForbiddenTagOperationExceptionTest extends TestCase */ public function createsExpectedExceptionForDeletion( ForbiddenTagOperationException $e, - string $expectedMessage + string $expectedMessage, ): void { $this->assertExceptionShape($e, $expectedMessage); } diff --git a/module/Core/test/Exception/ShortUrlNotFoundExceptionTest.php b/module/Core/test/Exception/ShortUrlNotFoundExceptionTest.php index e6a48914..ea4e606d 100644 --- a/module/Core/test/Exception/ShortUrlNotFoundExceptionTest.php +++ b/module/Core/test/Exception/ShortUrlNotFoundExceptionTest.php @@ -17,7 +17,7 @@ class ShortUrlNotFoundExceptionTest extends TestCase public function properlyCreatesExceptionFromNotFoundShortCode( string $expectedMessage, string $shortCode, - ?string $domain + ?string $domain, ): void { $expectedAdditional = ['shortCode' => $shortCode]; if ($domain !== null) { diff --git a/module/Core/test/Importer/ImportedLinksProcessorTest.php b/module/Core/test/Importer/ImportedLinksProcessorTest.php index d17c5720..1a4a4de1 100644 --- a/module/Core/test/Importer/ImportedLinksProcessorTest.php +++ b/module/Core/test/Importer/ImportedLinksProcessorTest.php @@ -160,7 +160,7 @@ class ImportedLinksProcessorTest extends TestCase ImportedShlinkUrl $importedUrl, string $expectedOutput, int $amountOfPersistedVisits, - ?ShortUrl $foundShortUrl + ?ShortUrl $foundShortUrl, ): void { $findExisting = $this->repo->findOneByImportedUrl(Argument::cetera())->willReturn($foundShortUrl); $ensureUniqueness = $this->shortCodeHelper->ensureShortCodeUniqueness(Argument::cetera())->willReturn(true); diff --git a/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php b/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php index 5420e4b6..33fdb8f6 100644 --- a/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php +++ b/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php @@ -33,7 +33,7 @@ class ShortUrlRepositoryAdapterTest extends TestCase array $tags = [], ?string $startDate = null, ?string $endDate = null, - ?string $orderBy = null + ?string $orderBy = null, ): void { $params = ShortUrlsParams::fromRawData([ 'searchTerm' => $searchTerm, @@ -58,7 +58,7 @@ class ShortUrlRepositoryAdapterTest extends TestCase ?string $searchTerm = null, array $tags = [], ?string $startDate = null, - ?string $endDate = null + ?string $endDate = null, ): void { $params = ShortUrlsParams::fromRawData([ 'searchTerm' => $searchTerm, diff --git a/module/Core/test/Paginator/Adapter/VisitsPaginatorAdapterTest.php b/module/Core/test/Paginator/Adapter/VisitsPaginatorAdapterTest.php index 2a9e5fc4..97a2c1f0 100644 --- a/module/Core/test/Paginator/Adapter/VisitsPaginatorAdapterTest.php +++ b/module/Core/test/Paginator/Adapter/VisitsPaginatorAdapterTest.php @@ -70,7 +70,7 @@ class VisitsPaginatorAdapterTest extends TestCase $this->repo->reveal(), new ShortUrlIdentifier(''), VisitsParams::fromRawData([]), - $apiKey !== null ? $apiKey->spec() : null, + $apiKey?->spec(), ); } } diff --git a/module/Core/test/Service/ShortUrl/ShortUrlResolverTest.php b/module/Core/test/Service/ShortUrl/ShortUrlResolverTest.php index 73823729..41f2b492 100644 --- a/module/Core/test/Service/ShortUrl/ShortUrlResolverTest.php +++ b/module/Core/test/Service/ShortUrl/ShortUrlResolverTest.php @@ -49,7 +49,7 @@ class ShortUrlResolverTest extends TestCase $identifier = ShortUrlIdentifier::fromShortCodeAndDomain($shortCode); $repo = $this->prophesize(ShortUrlRepositoryInterface::class); - $findOne = $repo->findOne($identifier, $apiKey !== null ? $apiKey->spec() : null)->willReturn($shortUrl); + $findOne = $repo->findOne($identifier, $apiKey?->spec())->willReturn($shortUrl); $getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal()); $result = $this->urlResolver->resolveShortUrl($identifier, $apiKey); @@ -69,7 +69,7 @@ class ShortUrlResolverTest extends TestCase $identifier = ShortUrlIdentifier::fromShortCodeAndDomain($shortCode); $repo = $this->prophesize(ShortUrlRepositoryInterface::class); - $findOne = $repo->findOne($identifier, $apiKey !== null ? $apiKey->spec() : null)->willReturn(null); + $findOne = $repo->findOne($identifier, $apiKey?->spec())->willReturn(null); $getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal(), $apiKey); $this->expectException(ShortUrlNotFoundException::class); diff --git a/module/Core/test/Service/ShortUrlServiceTest.php b/module/Core/test/Service/ShortUrlServiceTest.php index 67420edc..b07d4df9 100644 --- a/module/Core/test/Service/ShortUrlServiceTest.php +++ b/module/Core/test/Service/ShortUrlServiceTest.php @@ -82,7 +82,7 @@ class ShortUrlServiceTest extends TestCase public function updateShortUrlUpdatesProvidedData( int $expectedValidateCalls, ShortUrlEdit $shortUrlEdit, - ?ApiKey $apiKey + ?ApiKey $apiKey, ): void { $originalLongUrl = 'originalLongUrl'; $shortUrl = ShortUrl::withLongUrl($originalLongUrl); diff --git a/module/Core/test/ShortUrl/Helper/ShortUrlStringifierTest.php b/module/Core/test/ShortUrl/Helper/ShortUrlStringifierTest.php index 483fd57d..b4acc417 100644 --- a/module/Core/test/ShortUrl/Helper/ShortUrlStringifierTest.php +++ b/module/Core/test/ShortUrl/Helper/ShortUrlStringifierTest.php @@ -19,7 +19,7 @@ class ShortUrlStringifierTest extends TestCase array $config, string $basePath, ShortUrl $shortUrl, - string $expected + string $expected, ): void { $stringifier = new ShortUrlStringifier($config, $basePath); diff --git a/module/Core/test/Util/DoctrineBatchHelperTest.php b/module/Core/test/Util/DoctrineBatchHelperTest.php index b655c070..f6f9981d 100644 --- a/module/Core/test/Util/DoctrineBatchHelperTest.php +++ b/module/Core/test/Util/DoctrineBatchHelperTest.php @@ -31,7 +31,7 @@ class DoctrineBatchHelperTest extends TestCase public function entityManagerIsFlushedAndClearedTheExpectedAmountOfTimes( array $iterable, int $batchSize, - int $expectedCalls + int $expectedCalls, ): void { $wrappedIterable = $this->helper->wrapIterable($iterable, $batchSize); diff --git a/module/Core/test/Util/RedirectResponseHelperTest.php b/module/Core/test/Util/RedirectResponseHelperTest.php index 0eb8c0fe..eb26768f 100644 --- a/module/Core/test/Util/RedirectResponseHelperTest.php +++ b/module/Core/test/Util/RedirectResponseHelperTest.php @@ -28,7 +28,7 @@ class RedirectResponseHelperTest extends TestCase int $configuredStatus, int $configuredLifetime, int $expectedStatus, - ?string $expectedCacheControl + ?string $expectedCacheControl, ): void { $this->shortenerOpts->redirectStatusCode = $configuredStatus; $this->shortenerOpts->redirectCacheLifetime = $configuredLifetime; diff --git a/module/Core/test/Util/UrlValidatorTest.php b/module/Core/test/Util/UrlValidatorTest.php index 25710172..57a5d3ce 100644 --- a/module/Core/test/Util/UrlValidatorTest.php +++ b/module/Core/test/Util/UrlValidatorTest.php @@ -90,7 +90,7 @@ class UrlValidatorTest extends TestCase */ public function validateUrlWithTitleReturnsNullWhenRequestFailsAndValidationIsDisabled( ?bool $doValidate, - bool $validateUrl + bool $validateUrl, ): void { $request = $this->httpClient->request(Argument::cetera())->willThrow(ClientException::class); $this->options->validateUrl = $validateUrl; diff --git a/module/Core/test/Visit/VisitLocatorTest.php b/module/Core/test/Visit/VisitLocatorTest.php index 11e7062f..5c51b848 100644 --- a/module/Core/test/Visit/VisitLocatorTest.php +++ b/module/Core/test/Visit/VisitLocatorTest.php @@ -53,7 +53,7 @@ class VisitLocatorTest extends TestCase */ public function locateVisitsIteratesAndLocatesExpectedVisits( string $serviceMethodName, - string $expectedRepoMethodName + string $expectedRepoMethodName, ): void { $unlocatedVisits = map( range(1, 200), @@ -105,7 +105,7 @@ class VisitLocatorTest extends TestCase public function visitsWhichCannotBeLocatedAreIgnoredOrLocatedAsEmpty( string $serviceMethodName, string $expectedRepoMethodName, - bool $isNonLocatableAddress + bool $isNonLocatableAddress, ): void { $unlocatedVisits = [ Visit::forValidShortUrl(ShortUrl::withLongUrl('foo'), Visitor::emptyInstance()), diff --git a/module/Core/test/Visit/VisitsStatsHelperTest.php b/module/Core/test/Visit/VisitsStatsHelperTest.php index cae3fbb1..ab76bbf1 100644 --- a/module/Core/test/Visit/VisitsStatsHelperTest.php +++ b/module/Core/test/Visit/VisitsStatsHelperTest.php @@ -80,7 +80,7 @@ class VisitsStatsHelperTest extends TestCase { $shortCode = '123ABC'; $identifier = ShortUrlIdentifier::fromShortCodeAndDomain($shortCode); - $spec = $apiKey === null ? null : $apiKey->spec(); + $spec = $apiKey?->spec(); $repo = $this->prophesize(ShortUrlRepositoryInterface::class); $count = $repo->shortCodeIsInUse($identifier, $spec)->willReturn( diff --git a/module/Rest/src/Entity/ApiKey.php b/module/Rest/src/Entity/ApiKey.php index 0317390e..6c63c67b 100644 --- a/module/Rest/src/Entity/ApiKey.php +++ b/module/Rest/src/Entity/ApiKey.php @@ -116,7 +116,7 @@ class ApiKey extends AbstractEntity { /** @var ApiKeyRole|null $role */ $role = $this->roles->get($roleName); - return $role === null ? [] : $role->meta(); + return $role?->meta() ?? []; } public function mapRoles(callable $fun): array diff --git a/module/Rest/src/Service/ApiKeyService.php b/module/Rest/src/Service/ApiKeyService.php index 0aad928f..545ff310 100644 --- a/module/Rest/src/Service/ApiKeyService.php +++ b/module/Rest/src/Service/ApiKeyService.php @@ -22,7 +22,7 @@ class ApiKeyService implements ApiKeyServiceInterface public function create( ?Chronos $expirationDate = null, ?string $name = null, - RoleDefinition ...$roleDefinitions + RoleDefinition ...$roleDefinitions, ): ApiKey { $key = $this->buildApiKeyWithParams($expirationDate, $name); foreach ($roleDefinitions as $definition) { diff --git a/module/Rest/src/Service/ApiKeyServiceInterface.php b/module/Rest/src/Service/ApiKeyServiceInterface.php index 982bdf4f..85b726df 100644 --- a/module/Rest/src/Service/ApiKeyServiceInterface.php +++ b/module/Rest/src/Service/ApiKeyServiceInterface.php @@ -14,7 +14,7 @@ interface ApiKeyServiceInterface public function create( ?Chronos $expirationDate = null, ?string $name = null, - RoleDefinition ...$roleDefinitions + RoleDefinition ...$roleDefinitions, ): ApiKey; public function check(string $key): ApiKeyCheckResult; diff --git a/module/Rest/test-api/Action/DeleteShortUrlTest.php b/module/Rest/test-api/Action/DeleteShortUrlTest.php index 360287ec..479527c1 100644 --- a/module/Rest/test-api/Action/DeleteShortUrlTest.php +++ b/module/Rest/test-api/Action/DeleteShortUrlTest.php @@ -19,7 +19,7 @@ class DeleteShortUrlTest extends ApiTestCase string $shortCode, ?string $domain, string $expectedDetail, - string $apiKey + string $apiKey, ): void { $resp = $this->callApiWithKey(self::METHOD_DELETE, $this->buildShortUrlPath($shortCode, $domain), [], $apiKey); $payload = $this->getJsonResponsePayload($resp); diff --git a/module/Rest/test-api/Action/EditShortUrlTagsTest.php b/module/Rest/test-api/Action/EditShortUrlTagsTest.php index 18f6f3b0..f940a52d 100644 --- a/module/Rest/test-api/Action/EditShortUrlTagsTest.php +++ b/module/Rest/test-api/Action/EditShortUrlTagsTest.php @@ -35,7 +35,7 @@ class EditShortUrlTagsTest extends ApiTestCase string $shortCode, ?string $domain, string $expectedDetail, - string $apiKey + string $apiKey, ): void { $url = $this->buildShortUrlPath($shortCode, $domain, '/tags'); $resp = $this->callApiWithKey(self::METHOD_PUT, $url, [RequestOptions::JSON => [ diff --git a/module/Rest/test-api/Action/EditShortUrlTest.php b/module/Rest/test-api/Action/EditShortUrlTest.php index 6652c1a4..a25ccddd 100644 --- a/module/Rest/test-api/Action/EditShortUrlTest.php +++ b/module/Rest/test-api/Action/EditShortUrlTest.php @@ -6,12 +6,12 @@ namespace ShlinkioApiTest\Shlink\Rest\Action; use Cake\Chronos\Chronos; use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; +use GuzzleHttp\Psr7\Query; use GuzzleHttp\RequestOptions; use Laminas\Diactoros\Uri; use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase; use ShlinkioApiTest\Shlink\Rest\Utils\NotFoundUrlHelpersTrait; -use function GuzzleHttp\Psr7\build_query; use function sprintf; class EditShortUrlTest extends ApiTestCase @@ -105,7 +105,7 @@ class EditShortUrlTest extends ApiTestCase string $shortCode, ?string $domain, string $expectedDetail, - string $apiKey + string $apiKey, ): void { $url = $this->buildShortUrlPath($shortCode, $domain); $resp = $this->callApiWithKey(self::METHOD_PATCH, $url, [RequestOptions::JSON => []], $apiKey); @@ -147,7 +147,7 @@ class EditShortUrlTest extends ApiTestCase $url = new Uri(sprintf('/short-urls/%s', $shortCode)); if ($domain !== null) { - $url = $url->withQuery(build_query(['domain' => $domain])); + $url = $url->withQuery(Query::build(['domain' => $domain])); } $editResp = $this->callApiWithKey(self::METHOD_PATCH, (string) $url, [RequestOptions::JSON => [ diff --git a/module/Rest/test-api/Action/OrphanVisitsTest.php b/module/Rest/test-api/Action/OrphanVisitsTest.php index 067cf9a4..21f4cae1 100644 --- a/module/Rest/test-api/Action/OrphanVisitsTest.php +++ b/module/Rest/test-api/Action/OrphanVisitsTest.php @@ -45,7 +45,7 @@ class OrphanVisitsTest extends ApiTestCase array $query, int $totalItems, int $expectedAmount, - array $expectedVisits + array $expectedVisits, ): void { $resp = $this->callApiWithKey(self::METHOD_GET, '/visits/orphan', [RequestOptions::QUERY => $query]); $payload = $this->getJsonResponsePayload($resp); diff --git a/module/Rest/test-api/Action/ResolveShortUrlTest.php b/module/Rest/test-api/Action/ResolveShortUrlTest.php index ca99f058..216e35e9 100644 --- a/module/Rest/test-api/Action/ResolveShortUrlTest.php +++ b/module/Rest/test-api/Action/ResolveShortUrlTest.php @@ -51,7 +51,7 @@ class ResolveShortUrlTest extends ApiTestCase string $shortCode, ?string $domain, string $expectedDetail, - string $apiKey + string $apiKey, ): void { $resp = $this->callApiWithKey(self::METHOD_GET, $this->buildShortUrlPath($shortCode, $domain), [], $apiKey); $payload = $this->getJsonResponsePayload($resp); diff --git a/module/Rest/test-api/Action/ShortUrlVisitsTest.php b/module/Rest/test-api/Action/ShortUrlVisitsTest.php index 1d572004..327c7c05 100644 --- a/module/Rest/test-api/Action/ShortUrlVisitsTest.php +++ b/module/Rest/test-api/Action/ShortUrlVisitsTest.php @@ -23,7 +23,7 @@ class ShortUrlVisitsTest extends ApiTestCase string $shortCode, ?string $domain, string $expectedDetail, - string $apiKey + string $apiKey, ): void { $resp = $this->callApiWithKey( self::METHOD_GET, diff --git a/module/Rest/test-api/Action/TagVisitsTest.php b/module/Rest/test-api/Action/TagVisitsTest.php index 07b0576d..544fcccf 100644 --- a/module/Rest/test-api/Action/TagVisitsTest.php +++ b/module/Rest/test-api/Action/TagVisitsTest.php @@ -19,7 +19,7 @@ class TagVisitsTest extends ApiTestCase string $apiKey, string $tag, bool $excludeBots, - int $expectedVisitsAmount + int $expectedVisitsAmount, ): void { $resp = $this->callApiWithKey(self::METHOD_GET, sprintf('/tags/%s/visits', $tag), [ RequestOptions::QUERY => $excludeBots ? ['excludeBots' => true] : [], diff --git a/module/Rest/test-api/Middleware/CorsTest.php b/module/Rest/test-api/Middleware/CorsTest.php index 093a200c..a51d6a7b 100644 --- a/module/Rest/test-api/Middleware/CorsTest.php +++ b/module/Rest/test-api/Middleware/CorsTest.php @@ -28,7 +28,7 @@ class CorsTest extends ApiTestCase public function responseIncludesCorsHeadersIfOriginIsSent( string $origin, string $endpoint, - int $expectedStatusCode + int $expectedStatusCode, ): void { $resp = $this->callApiWithKey(self::METHOD_GET, $endpoint, [ RequestOptions::HEADERS => ['Origin' => $origin], diff --git a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php index 712d605d..170ccc09 100644 --- a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php @@ -49,7 +49,7 @@ class ListShortUrlsActionTest extends TestCase array $expectedTags, ?string $expectedOrderBy, ?string $startDate = null, - ?string $endDate = null + ?string $endDate = null, ): void { $apiKey = ApiKey::create(); $request = (new ServerRequest())->withQueryParams($query)->withAttribute(ApiKey::class, $apiKey); diff --git a/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php index 68503b58..c915098a 100644 --- a/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php +++ b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php @@ -88,7 +88,7 @@ class AuthenticationMiddlewareTest extends TestCase */ public function throwsExceptionWhenNoApiKeyIsProvided( ServerRequestInterface $request, - string $expectedMessage + string $expectedMessage, ): void { $this->apiKeyService->check(Argument::any())->shouldNotBeCalled(); $this->handler->handle($request)->shouldNotBeCalled(); diff --git a/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php index a274e1f8..acdc9600 100644 --- a/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php +++ b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php @@ -91,7 +91,7 @@ class CrossDomainMiddlewareTest extends TestCase */ public function optionsRequestParsesRouteMatchToDetermineAllowedMethods( ?string $allowHeader, - string $expectedAllowedMethods + string $expectedAllowedMethods, ): void { $originalResponse = new Response(); if ($allowHeader !== null) { @@ -121,7 +121,7 @@ class CrossDomainMiddlewareTest extends TestCase public function expectedStatusCodeIsReturnDependingOnRequestMethod( string $method, int $status, - int $expectedStatus + int $expectedStatus, ): void { $originalResponse = (new Response())->withStatus($status); $request = (new ServerRequest())->withMethod($method)