mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-24 09:50:17 -06:00
Merge pull request #2258 from acelaya-forks/feature/phpstan-2
Update to PHPStan 2.0
This commit is contained in:
commit
a444ed0246
@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
|
|||||||
|
|
||||||
* Update to Shlink PHP coding standard 2.4
|
* Update to Shlink PHP coding standard 2.4
|
||||||
* Update to `hidehalo/nanoid-php` 2.0
|
* Update to `hidehalo/nanoid-php` 2.0
|
||||||
|
* Update to PHPStan 2.0
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
* *Nothing*
|
* *Nothing*
|
||||||
|
@ -64,10 +64,10 @@
|
|||||||
"require-dev": {
|
"require-dev": {
|
||||||
"devizzent/cebe-php-openapi": "^1.0.1",
|
"devizzent/cebe-php-openapi": "^1.0.1",
|
||||||
"devster/ubench": "^2.1",
|
"devster/ubench": "^2.1",
|
||||||
"phpstan/phpstan": "^1.12",
|
"phpstan/phpstan": "^2.0",
|
||||||
"phpstan/phpstan-doctrine": "^1.5",
|
"phpstan/phpstan-doctrine": "^2.0",
|
||||||
"phpstan/phpstan-phpunit": "^1.4",
|
"phpstan/phpstan-phpunit": "^2.0",
|
||||||
"phpstan/phpstan-symfony": "^1.4",
|
"phpstan/phpstan-symfony": "^2.0",
|
||||||
"phpunit/php-code-coverage": "^11.0",
|
"phpunit/php-code-coverage": "^11.0",
|
||||||
"phpunit/phpcov": "^10.0",
|
"phpunit/phpcov": "^10.0",
|
||||||
"phpunit/phpunit": "^11.4",
|
"phpunit/phpunit": "^11.4",
|
||||||
|
@ -22,7 +22,7 @@ class CreateShortUrlCommand extends Command
|
|||||||
{
|
{
|
||||||
public const NAME = 'short-url:create';
|
public const NAME = 'short-url:create';
|
||||||
|
|
||||||
private SymfonyStyle|null $io;
|
private SymfonyStyle $io;
|
||||||
private readonly ShortUrlDataInput $shortUrlDataInput;
|
private readonly ShortUrlDataInput $shortUrlDataInput;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
@ -235,7 +235,7 @@ class ListShortUrlsCommand extends Command
|
|||||||
}
|
}
|
||||||
if ($input->getOption('show-domain')) {
|
if ($input->getOption('show-domain')) {
|
||||||
$columnsMap['Domain'] = static fn (array $_, ShortUrl $shortUrl): string =>
|
$columnsMap['Domain'] = static fn (array $_, ShortUrl $shortUrl): string =>
|
||||||
$shortUrl->getDomain()?->authority ?? Domain::DEFAULT_AUTHORITY;
|
$shortUrl->getDomain()->authority ?? Domain::DEFAULT_AUTHORITY;
|
||||||
}
|
}
|
||||||
if ($input->getOption('show-api-key') || $input->getOption('show-api-key-name')) {
|
if ($input->getOption('show-api-key') || $input->getOption('show-api-key-name')) {
|
||||||
$columnsMap['API Key Name'] = static fn (array $_, ShortUrl $shortUrl): string|null =>
|
$columnsMap['API Key Name'] = static fn (array $_, ShortUrl $shortUrl): string|null =>
|
||||||
|
@ -61,8 +61,8 @@ abstract class AbstractVisitsListCommand extends Command
|
|||||||
'date' => $visit->date->toAtomString(),
|
'date' => $visit->date->toAtomString(),
|
||||||
'userAgent' => $visit->userAgent,
|
'userAgent' => $visit->userAgent,
|
||||||
'potentialBot' => $visit->potentialBot,
|
'potentialBot' => $visit->potentialBot,
|
||||||
'country' => $visit->getVisitLocation()?->countryName ?? 'Unknown',
|
'country' => $visit->getVisitLocation()->countryName ?? 'Unknown',
|
||||||
'city' => $visit->getVisitLocation()?->cityName ?? 'Unknown',
|
'city' => $visit->getVisitLocation()->cityName ?? 'Unknown',
|
||||||
...$extraFields,
|
...$extraFields,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -41,22 +41,24 @@ class GeolocationDbUpdaterTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function properResultIsReturnedWhenLicenseIsMissing(): void
|
public function properResultIsReturnedWhenLicenseIsMissing(): void
|
||||||
{
|
{
|
||||||
$mustBeUpdated = fn () => self::assertTrue(true);
|
|
||||||
|
|
||||||
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->willReturn(false);
|
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->willReturn(false);
|
||||||
$this->dbUpdater->expects($this->once())->method('downloadFreshCopy')->willThrowException(
|
$this->dbUpdater->expects($this->once())->method('downloadFreshCopy')->willThrowException(
|
||||||
new MissingLicenseException(''),
|
new MissingLicenseException(''),
|
||||||
);
|
);
|
||||||
$this->geoLiteDbReader->expects($this->never())->method('metadata');
|
$this->geoLiteDbReader->expects($this->never())->method('metadata');
|
||||||
|
|
||||||
$result = $this->geolocationDbUpdater()->checkDbUpdate($mustBeUpdated);
|
$isCalled = false;
|
||||||
|
$result = $this->geolocationDbUpdater()->checkDbUpdate(function () use (&$isCalled): void {
|
||||||
|
$isCalled = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
self::assertTrue($isCalled);
|
||||||
self::assertEquals(GeolocationResult::LICENSE_MISSING, $result);
|
self::assertEquals(GeolocationResult::LICENSE_MISSING, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function exceptionIsThrownWhenOlderDbDoesNotExistAndDownloadFails(): void
|
public function exceptionIsThrownWhenOlderDbDoesNotExistAndDownloadFails(): void
|
||||||
{
|
{
|
||||||
$mustBeUpdated = fn () => self::assertTrue(true);
|
|
||||||
$prev = new DbUpdateException('');
|
$prev = new DbUpdateException('');
|
||||||
|
|
||||||
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->willReturn(false);
|
$this->dbUpdater->expects($this->once())->method('databaseFileExists')->willReturn(false);
|
||||||
@ -65,14 +67,17 @@ class GeolocationDbUpdaterTest extends TestCase
|
|||||||
)->willThrowException($prev);
|
)->willThrowException($prev);
|
||||||
$this->geoLiteDbReader->expects($this->never())->method('metadata');
|
$this->geoLiteDbReader->expects($this->never())->method('metadata');
|
||||||
|
|
||||||
|
$isCalled = false;
|
||||||
try {
|
try {
|
||||||
$this->geolocationDbUpdater()->checkDbUpdate($mustBeUpdated);
|
$this->geolocationDbUpdater()->checkDbUpdate(function () use (&$isCalled): void {
|
||||||
|
$isCalled = true;
|
||||||
|
});
|
||||||
self::fail();
|
self::fail();
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
/** @var GeolocationDbUpdateFailedException $e */
|
|
||||||
self::assertInstanceOf(GeolocationDbUpdateFailedException::class, $e);
|
self::assertInstanceOf(GeolocationDbUpdateFailedException::class, $e);
|
||||||
self::assertSame($prev, $e->getPrevious());
|
self::assertSame($prev, $e->getPrevious());
|
||||||
self::assertFalse($e->olderDbExists());
|
self::assertFalse($e->olderDbExists());
|
||||||
|
self::assertTrue($isCalled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +97,6 @@ class GeolocationDbUpdaterTest extends TestCase
|
|||||||
$this->geolocationDbUpdater()->checkDbUpdate();
|
$this->geolocationDbUpdater()->checkDbUpdate();
|
||||||
self::fail();
|
self::fail();
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
/** @var GeolocationDbUpdateFailedException $e */
|
|
||||||
self::assertInstanceOf(GeolocationDbUpdateFailedException::class, $e);
|
self::assertInstanceOf(GeolocationDbUpdateFailedException::class, $e);
|
||||||
self::assertSame($prev, $e->getPrevious());
|
self::assertSame($prev, $e->getPrevious());
|
||||||
self::assertTrue($e->olderDbExists());
|
self::assertTrue($e->olderDbExists());
|
||||||
|
@ -109,7 +109,7 @@ function normalizeLocale(string $locale): string
|
|||||||
* minimum quality
|
* minimum quality
|
||||||
*
|
*
|
||||||
* @param non-empty-string $acceptLanguage
|
* @param non-empty-string $acceptLanguage
|
||||||
* @return iterable<string>;
|
* @return iterable<string>
|
||||||
*/
|
*/
|
||||||
function acceptLanguageToLocales(string $acceptLanguage, float $minQuality = 0): iterable
|
function acceptLanguageToLocales(string $acceptLanguage, float $minQuality = 0): iterable
|
||||||
{
|
{
|
||||||
|
@ -8,11 +8,11 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||||||
use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException;
|
use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortCodeUniquenessHelperInterface;
|
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortCodeUniquenessHelperInterface;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepository;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Resolver\ShortUrlRelationResolverInterface;
|
use Shlinkio\Shlink\Core\ShortUrl\Resolver\ShortUrlRelationResolverInterface;
|
||||||
use Shlinkio\Shlink\Core\Util\DoctrineBatchHelperInterface;
|
use Shlinkio\Shlink\Core\Util\DoctrineBatchHelperInterface;
|
||||||
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||||
use Shlinkio\Shlink\Core\Visit\Repository\VisitRepositoryInterface;
|
use Shlinkio\Shlink\Core\Visit\Repository\VisitRepository;
|
||||||
use Shlinkio\Shlink\Importer\ImportedLinksProcessorInterface;
|
use Shlinkio\Shlink\Importer\ImportedLinksProcessorInterface;
|
||||||
use Shlinkio\Shlink\Importer\Model\ImportedShlinkOrphanVisit;
|
use Shlinkio\Shlink\Importer\Model\ImportedShlinkOrphanVisit;
|
||||||
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
|
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
|
||||||
@ -93,7 +93,7 @@ readonly class ImportedLinksProcessor implements ImportedLinksProcessorInterface
|
|||||||
bool $importShortCodes,
|
bool $importShortCodes,
|
||||||
callable $skipOnShortCodeConflict,
|
callable $skipOnShortCodeConflict,
|
||||||
): ShortUrlImporting {
|
): ShortUrlImporting {
|
||||||
/** @var ShortUrlRepositoryInterface $shortUrlRepo */
|
/** @var ShortUrlRepository $shortUrlRepo */
|
||||||
$shortUrlRepo = $this->em->getRepository(ShortUrl::class);
|
$shortUrlRepo = $this->em->getRepository(ShortUrl::class);
|
||||||
$alreadyImportedShortUrl = $shortUrlRepo->findOneByImportedUrl($importedUrl);
|
$alreadyImportedShortUrl = $shortUrlRepo->findOneByImportedUrl($importedUrl);
|
||||||
if ($alreadyImportedShortUrl !== null) {
|
if ($alreadyImportedShortUrl !== null) {
|
||||||
@ -132,7 +132,7 @@ readonly class ImportedLinksProcessor implements ImportedLinksProcessorInterface
|
|||||||
{
|
{
|
||||||
$iterable = $this->batchHelper->wrapIterable($orphanVisits, 100);
|
$iterable = $this->batchHelper->wrapIterable($orphanVisits, 100);
|
||||||
|
|
||||||
/** @var VisitRepositoryInterface $visitRepo */
|
/** @var VisitRepository $visitRepo */
|
||||||
$visitRepo = $this->em->getRepository(Visit::class);
|
$visitRepo = $this->em->getRepository(Visit::class);
|
||||||
$mostRecentOrphanVisit = $visitRepo->findMostRecentOrphanVisit();
|
$mostRecentOrphanVisit = $visitRepo->findMostRecentOrphanVisit();
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ use Doctrine\ORM\Events;
|
|||||||
use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions;
|
use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions;
|
||||||
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
||||||
use Shlinkio\Shlink\Core\Tag\Entity\Tag;
|
use Shlinkio\Shlink\Core\Tag\Entity\Tag;
|
||||||
use Symfony\Component\Lock\Lock;
|
|
||||||
use Symfony\Component\Lock\LockFactory;
|
use Symfony\Component\Lock\LockFactory;
|
||||||
|
use Symfony\Component\Lock\SharedLockInterface;
|
||||||
use Symfony\Component\Lock\Store\InMemoryStore;
|
use Symfony\Component\Lock\Store\InMemoryStore;
|
||||||
|
|
||||||
use function array_map;
|
use function array_map;
|
||||||
@ -24,9 +24,9 @@ class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInt
|
|||||||
private array $memoizedNewDomains = [];
|
private array $memoizedNewDomains = [];
|
||||||
/** @var array<string, Tag> */
|
/** @var array<string, Tag> */
|
||||||
private array $memoizedNewTags = [];
|
private array $memoizedNewTags = [];
|
||||||
/** @var array<string, Lock> */
|
/** @var array<string, SharedLockInterface> */
|
||||||
private array $tagLocks = [];
|
private array $tagLocks = [];
|
||||||
/** @var array<string, Lock> */
|
/** @var array<string, SharedLockInterface> */
|
||||||
private array $domainLocks = [];
|
private array $domainLocks = [];
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@ -100,7 +100,7 @@ class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, Lock> $locks
|
* @param array<string, SharedLockInterface> $locks
|
||||||
*/
|
*/
|
||||||
private function lock(array &$locks, string $name): void
|
private function lock(array &$locks, string $name): void
|
||||||
{
|
{
|
||||||
@ -112,7 +112,7 @@ class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInt
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
/**
|
/**
|
||||||
* @param array<string, Lock> $locks
|
* @param array<string, SharedLockInterface> $locks
|
||||||
*/
|
*/
|
||||||
private function releaseLock(array &$locks, string $name): void
|
private function releaseLock(array &$locks, string $name): void
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito
|
|||||||
public function findTagsWithInfo(TagsListFiltering|null $filtering = null): array
|
public function findTagsWithInfo(TagsListFiltering|null $filtering = null): array
|
||||||
{
|
{
|
||||||
$orderField = OrderableField::toValidField($filtering?->orderBy?->field);
|
$orderField = OrderableField::toValidField($filtering?->orderBy?->field);
|
||||||
$orderDir = $filtering?->orderBy?->direction ?? 'ASC';
|
$orderDir = $filtering->orderBy->direction ?? 'ASC';
|
||||||
$apiKey = $filtering?->apiKey;
|
$apiKey = $filtering?->apiKey;
|
||||||
$conn = $this->getEntityManager()->getConnection();
|
$conn = $this->getEntityManager()->getConnection();
|
||||||
|
|
||||||
@ -113,8 +113,8 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito
|
|||||||
->from('(' . $tagsSubQb->getSQL() . ')', 't')
|
->from('(' . $tagsSubQb->getSQL() . ')', 't')
|
||||||
->leftJoin('t', '(' . $allVisitsSubQb->getSQL() . ')', 'v', $mainQb->expr()->eq('t.tag_id', 'v.tag_id'))
|
->leftJoin('t', '(' . $allVisitsSubQb->getSQL() . ')', 'v', $mainQb->expr()->eq('t.tag_id', 'v.tag_id'))
|
||||||
->leftJoin('t', '(' . $nonBotVisitsSubQb->getSQL() . ')', 'b', $mainQb->expr()->eq('t.tag_id', 'b.tag_id'))
|
->leftJoin('t', '(' . $nonBotVisitsSubQb->getSQL() . ')', 'b', $mainQb->expr()->eq('t.tag_id', 'b.tag_id'))
|
||||||
->setMaxResults($filtering?->limit ?? PHP_INT_MAX)
|
->setMaxResults($filtering->limit ?? PHP_INT_MAX)
|
||||||
->setFirstResult($filtering?->offset ?? 0);
|
->setFirstResult($filtering->offset ?? 0);
|
||||||
|
|
||||||
$mainQb->orderBy(camelCaseToSnakeCase($orderField->value), $orderDir);
|
$mainQb->orderBy(camelCaseToSnakeCase($orderField->value), $orderDir);
|
||||||
if ($orderField !== OrderableField::TAG) {
|
if ($orderField !== OrderableField::TAG) {
|
||||||
|
@ -47,9 +47,11 @@ readonly class TagService implements TagServiceInterface
|
|||||||
*/
|
*/
|
||||||
private function createPaginator(AdapterInterface $adapter, TagsParams $params): Paginator
|
private function createPaginator(AdapterInterface $adapter, TagsParams $params): Paginator
|
||||||
{
|
{
|
||||||
return (new Paginator($adapter))
|
$paginator = new Paginator($adapter);
|
||||||
->setMaxPerPage($params->itemsPerPage)
|
$paginator->setMaxPerPage($params->itemsPerPage)
|
||||||
->setCurrentPage($params->page);
|
->setCurrentPage($params->page);
|
||||||
|
|
||||||
|
return $paginator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,7 +11,7 @@ use Shlinkio\Shlink\Common\Util\DateRange;
|
|||||||
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepository;
|
||||||
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||||
use Shlinkio\Shlink\Core\Visit\Entity\VisitLocation;
|
use Shlinkio\Shlink\Core\Visit\Entity\VisitLocation;
|
||||||
use Shlinkio\Shlink\Core\Visit\Persistence\OrphanVisitsCountFiltering;
|
use Shlinkio\Shlink\Core\Visit\Persistence\OrphanVisitsCountFiltering;
|
||||||
@ -48,7 +48,7 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo
|
|||||||
ShortUrlIdentifier $identifier,
|
ShortUrlIdentifier $identifier,
|
||||||
VisitsCountFiltering $filtering,
|
VisitsCountFiltering $filtering,
|
||||||
): QueryBuilder {
|
): QueryBuilder {
|
||||||
/** @var ShortUrlRepositoryInterface $shortUrlRepo */
|
/** @var ShortUrlRepository $shortUrlRepo */
|
||||||
$shortUrlRepo = $this->getEntityManager()->getRepository(ShortUrl::class);
|
$shortUrlRepo = $this->getEntityManager()->getRepository(ShortUrl::class);
|
||||||
$shortUrlId = $shortUrlRepo->findOne($identifier, $filtering->apiKey?->spec())?->getId() ?? '-1';
|
$shortUrlId = $shortUrlRepo->findOne($identifier, $filtering->apiKey?->spec())?->getId() ?? '-1';
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException;
|
|||||||
use Shlinkio\Shlink\Core\Exception\TagNotFoundException;
|
use Shlinkio\Shlink\Core\Exception\TagNotFoundException;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepository;
|
||||||
use Shlinkio\Shlink\Core\Tag\Entity\Tag;
|
use Shlinkio\Shlink\Core\Tag\Entity\Tag;
|
||||||
use Shlinkio\Shlink\Core\Tag\Repository\TagRepository;
|
use Shlinkio\Shlink\Core\Tag\Repository\TagRepository;
|
||||||
use Shlinkio\Shlink\Core\Visit\Entity\OrphanVisitsCount;
|
use Shlinkio\Shlink\Core\Visit\Entity\OrphanVisitsCount;
|
||||||
@ -32,7 +32,7 @@ use Shlinkio\Shlink\Core\Visit\Persistence\OrphanVisitsCountFiltering;
|
|||||||
use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering;
|
use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering;
|
||||||
use Shlinkio\Shlink\Core\Visit\Repository\OrphanVisitsCountRepository;
|
use Shlinkio\Shlink\Core\Visit\Repository\OrphanVisitsCountRepository;
|
||||||
use Shlinkio\Shlink\Core\Visit\Repository\ShortUrlVisitsCountRepository;
|
use Shlinkio\Shlink\Core\Visit\Repository\ShortUrlVisitsCountRepository;
|
||||||
use Shlinkio\Shlink\Core\Visit\Repository\VisitRepositoryInterface;
|
use Shlinkio\Shlink\Core\Visit\Repository\VisitRepository;
|
||||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||||
|
|
||||||
readonly class VisitsStatsHelper implements VisitsStatsHelperInterface
|
readonly class VisitsStatsHelper implements VisitsStatsHelperInterface
|
||||||
@ -70,13 +70,13 @@ readonly class VisitsStatsHelper implements VisitsStatsHelperInterface
|
|||||||
VisitsParams $params,
|
VisitsParams $params,
|
||||||
ApiKey|null $apiKey = null,
|
ApiKey|null $apiKey = null,
|
||||||
): Paginator {
|
): Paginator {
|
||||||
/** @var ShortUrlRepositoryInterface $repo */
|
/** @var ShortUrlRepository $repo */
|
||||||
$repo = $this->em->getRepository(ShortUrl::class);
|
$repo = $this->em->getRepository(ShortUrl::class);
|
||||||
if (! $repo->shortCodeIsInUse($identifier, $apiKey?->spec())) {
|
if (! $repo->shortCodeIsInUse($identifier, $apiKey?->spec())) {
|
||||||
throw ShortUrlNotFoundException::fromNotFound($identifier);
|
throw ShortUrlNotFoundException::fromNotFound($identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var VisitRepositoryInterface $repo */
|
/** @var VisitRepository $repo */
|
||||||
$repo = $this->em->getRepository(Visit::class);
|
$repo = $this->em->getRepository(Visit::class);
|
||||||
|
|
||||||
return $this->createPaginator(
|
return $this->createPaginator(
|
||||||
@ -96,7 +96,7 @@ readonly class VisitsStatsHelper implements VisitsStatsHelperInterface
|
|||||||
throw TagNotFoundException::fromTag($tag);
|
throw TagNotFoundException::fromTag($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var VisitRepositoryInterface $repo */
|
/** @var VisitRepository $repo */
|
||||||
$repo = $this->em->getRepository(Visit::class);
|
$repo = $this->em->getRepository(Visit::class);
|
||||||
|
|
||||||
return $this->createPaginator(new TagVisitsPaginatorAdapter($repo, $tag, $params, $apiKey), $params);
|
return $this->createPaginator(new TagVisitsPaginatorAdapter($repo, $tag, $params, $apiKey), $params);
|
||||||
@ -113,7 +113,7 @@ readonly class VisitsStatsHelper implements VisitsStatsHelperInterface
|
|||||||
throw DomainNotFoundException::fromAuthority($domain);
|
throw DomainNotFoundException::fromAuthority($domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var VisitRepositoryInterface $repo */
|
/** @var VisitRepository $repo */
|
||||||
$repo = $this->em->getRepository(Visit::class);
|
$repo = $this->em->getRepository(Visit::class);
|
||||||
|
|
||||||
return $this->createPaginator(new DomainVisitsPaginatorAdapter($repo, $domain, $params, $apiKey), $params);
|
return $this->createPaginator(new DomainVisitsPaginatorAdapter($repo, $domain, $params, $apiKey), $params);
|
||||||
@ -124,7 +124,7 @@ readonly class VisitsStatsHelper implements VisitsStatsHelperInterface
|
|||||||
*/
|
*/
|
||||||
public function orphanVisits(OrphanVisitsParams $params, ApiKey|null $apiKey = null): Paginator
|
public function orphanVisits(OrphanVisitsParams $params, ApiKey|null $apiKey = null): Paginator
|
||||||
{
|
{
|
||||||
/** @var VisitRepositoryInterface $repo */
|
/** @var VisitRepository $repo */
|
||||||
$repo = $this->em->getRepository(Visit::class);
|
$repo = $this->em->getRepository(Visit::class);
|
||||||
|
|
||||||
return $this->createPaginator(new OrphanVisitsPaginatorAdapter($repo, $params, $apiKey), $params);
|
return $this->createPaginator(new OrphanVisitsPaginatorAdapter($repo, $params, $apiKey), $params);
|
||||||
@ -132,7 +132,7 @@ readonly class VisitsStatsHelper implements VisitsStatsHelperInterface
|
|||||||
|
|
||||||
public function nonOrphanVisits(VisitsParams $params, ApiKey|null $apiKey = null): Paginator
|
public function nonOrphanVisits(VisitsParams $params, ApiKey|null $apiKey = null): Paginator
|
||||||
{
|
{
|
||||||
/** @var VisitRepositoryInterface $repo */
|
/** @var VisitRepository $repo */
|
||||||
$repo = $this->em->getRepository(Visit::class);
|
$repo = $this->em->getRepository(Visit::class);
|
||||||
|
|
||||||
return $this->createPaginator(new NonOrphanVisitsPaginatorAdapter($repo, $params, $apiKey), $params);
|
return $this->createPaginator(new NonOrphanVisitsPaginatorAdapter($repo, $params, $apiKey), $params);
|
||||||
|
@ -139,7 +139,7 @@ class DomainRepositoryTest extends DatabaseTestCase
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resolveDomain(string|null $domain): Domain|null
|
public function resolveDomain(string|null $domain): Domain
|
||||||
{
|
{
|
||||||
return $this->domain;
|
return $this->domain;
|
||||||
}
|
}
|
||||||
|
@ -99,8 +99,6 @@ class ShortUrlRedirectRuleServiceTest extends TestCase
|
|||||||
$result = $this->ruleService->setRulesForShortUrl($shortUrl, $data);
|
$result = $this->ruleService->setRulesForShortUrl($shortUrl, $data);
|
||||||
|
|
||||||
self::assertCount(2, $result);
|
self::assertCount(2, $result);
|
||||||
self::assertInstanceOf(ShortUrlRedirectRule::class, $result[0]);
|
|
||||||
self::assertInstanceOf(ShortUrlRedirectRule::class, $result[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
|
@ -90,8 +90,8 @@ class ShortUrlTitleResolutionHelperTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
#[TestWith(['TEXT/html; charset=utf-8'], name: 'charset')]
|
#[TestWith(['TEXT/html; charset=utf-8'], 'charset')]
|
||||||
#[TestWith(['TEXT/html'], name: 'no charset')]
|
#[TestWith(['TEXT/html'], 'no charset')]
|
||||||
public function titleIsUpdatedWhenItCanBeResolvedFromResponse(string $contentType): void
|
public function titleIsUpdatedWhenItCanBeResolvedFromResponse(string $contentType): void
|
||||||
{
|
{
|
||||||
$data = ShortUrlCreation::fromRawData(['longUrl' => self::LONG_URL]);
|
$data = ShortUrlCreation::fromRawData(['longUrl' => self::LONG_URL]);
|
||||||
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||||||
namespace ShlinkioTest\Shlink\Rest\Middleware;
|
namespace ShlinkioTest\Shlink\Rest\Middleware;
|
||||||
|
|
||||||
use Laminas\Diactoros\Response\EmptyResponse;
|
use Laminas\Diactoros\Response\EmptyResponse;
|
||||||
use Mezzio\Router\Middleware\ImplicitOptionsMiddleware;
|
|
||||||
use PHPUnit\Framework\Attributes\Test;
|
use PHPUnit\Framework\Attributes\Test;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Psr\Http\Message\ResponseFactoryInterface;
|
use Psr\Http\Message\ResponseFactoryInterface;
|
||||||
@ -21,13 +20,6 @@ class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase
|
|||||||
$this->factory = new EmptyResponseImplicitOptionsMiddlewareFactory();
|
$this->factory = new EmptyResponseImplicitOptionsMiddlewareFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Test]
|
|
||||||
public function serviceIsCreated(): void
|
|
||||||
{
|
|
||||||
$instance = ($this->factory)();
|
|
||||||
self::assertInstanceOf(ImplicitOptionsMiddleware::class, $instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
public function responsePrototypeIsEmptyResponse(): void
|
public function responsePrototypeIsEmptyResponse(): void
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ parameters:
|
|||||||
- config
|
- config
|
||||||
- docker/config
|
- docker/config
|
||||||
symfony:
|
symfony:
|
||||||
console_application_loader: 'config/cli-app.php'
|
consoleApplicationLoader: 'config/cli-app.php'
|
||||||
doctrine:
|
doctrine:
|
||||||
repositoryClass: Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository
|
repositoryClass: Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository
|
||||||
objectManagerLoader: 'config/entity-manager.php'
|
objectManagerLoader: 'config/entity-manager.php'
|
||||||
|
Loading…
Reference in New Issue
Block a user