Skip to content

Commit

Permalink
Merge pull request #2168 from acelaya-forks/feature/update-common
Browse files Browse the repository at this point in the history
Update to latest shlink-common and remove deprecation references
  • Loading branch information
acelaya authored Jul 29, 2024
2 parents 6b0b528 + 037cd8a commit c10f0db
Show file tree
Hide file tree
Showing 72 changed files with 213 additions and 136 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"pagerfanta/core": "^3.8",
"ramsey/uuid": "^4.7",
"shlinkio/doctrine-specification": "^2.1.1",
"shlinkio/shlink-common": "^6.1",
"shlinkio/shlink-common": "dev-main#144e5c1 as 6.2",
"shlinkio/shlink-config": "^3.0",
"shlinkio/shlink-event-dispatcher": "^4.1",
"shlinkio/shlink-importer": "^5.3.2",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ services:

shlink_db_postgres:
container_name: shlink_db_postgres
image: postgres:12.2-alpine
image: postgres:16.3-alpine
ports:
- "5434:5432"
volumes:
Expand Down
3 changes: 3 additions & 0 deletions module/CLI/src/Command/Domain/GetDomainVisitsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ protected function configure(): void
->addArgument('domain', InputArgument::REQUIRED, 'The domain which visits we want to get.');
}

/**
* @return Paginator<Visit>
*/
protected function getVisitsPaginator(InputInterface $input, DateRange $dateRange): Paginator
{
$domain = $input->getArgument('domain');
Expand Down
3 changes: 3 additions & 0 deletions module/CLI/src/Command/ShortUrl/GetShortUrlVisitsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
}
}

/**
* @return Paginator<Visit>
*/
protected function getVisitsPaginator(InputInterface $input, DateRange $dateRange): Paginator
{
$identifier = $this->shortUrlIdentifierInput->toShortUrlIdentifier($input);
Expand Down
11 changes: 5 additions & 6 deletions module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
use Shlinkio\Shlink\CLI\Util\ExitCode;
use Shlinkio\Shlink\CLI\Util\ShlinkTable;
use Shlinkio\Shlink\Common\Paginator\Paginator;
use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtilsTrait;
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtils;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlWithVisitsSummary;
use Shlinkio\Shlink\Core\ShortUrl\Model\TagsMode;
use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlsParamsInputFilter;
use Shlinkio\Shlink\Core\ShortUrl\ShortUrlListServiceInterface;
use Shlinkio\Shlink\Core\ShortUrl\Transformer\ShortUrlDataTransformerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -32,16 +32,14 @@

class ListShortUrlsCommand extends Command
{
use PagerfantaUtilsTrait;

public const NAME = 'short-url:list';

private readonly StartDateOption $startDateOption;
private readonly EndDateOption $endDateOption;

public function __construct(
private readonly ShortUrlListServiceInterface $shortUrlService,
private readonly DataTransformerInterface $transformer,
private readonly ShortUrlDataTransformerInterface $transformer,
) {
parent::__construct();
$this->startDateOption = new StartDateOption($this, 'short URLs');
Expand Down Expand Up @@ -179,6 +177,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/**
* @param array<string, callable(array $serializedShortUrl, ShortUrl $shortUrl): ?string> $columnsMap
* @return Paginator<ShortUrlWithVisitsSummary>
*/
private function renderPage(
OutputInterface $output,
Expand All @@ -196,7 +195,7 @@ private function renderPage(
ShlinkTable::default($output)->render(
array_keys($columnsMap),
$rows,
$all ? null : $this->formatCurrentPageMessage($shortUrls, 'Page %s of %s'),
$all ? null : PagerfantaUtils::formatCurrentPageMessage($shortUrls, 'Page %s of %s'),
);

return $shortUrls;
Expand Down
3 changes: 3 additions & 0 deletions module/CLI/src/Command/Tag/GetTagVisitsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ protected function configure(): void
->addArgument('tag', InputArgument::REQUIRED, 'The tag which visits we want to get.');
}

/**
* @return Paginator<Visit>
*/
protected function getVisitsPaginator(InputInterface $input, DateRange $dateRange): Paginator
{
$tag = $input->getArgument('tag');
Expand Down
6 changes: 6 additions & 0 deletions module/CLI/src/Command/Visit/AbstractVisitsListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ final protected function execute(InputInterface $input, OutputInterface $output)
return ExitCode::EXIT_SUCCESS;
}

/**
* @param Paginator<Visit> $paginator
*/
private function resolveRowsAndHeaders(Paginator $paginator): array
{
$extraKeys = [];
Expand Down Expand Up @@ -74,6 +77,9 @@ private function resolveRowsAndHeaders(Paginator $paginator): array
];
}

/**
* @return Paginator<Visit>
*/
abstract protected function getVisitsPaginator(InputInterface $input, DateRange $dateRange): Paginator;

/**
Expand Down
3 changes: 3 additions & 0 deletions module/CLI/src/Command/Visit/GetNonOrphanVisitsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ protected function configure(): void
->setDescription('Returns the list of non-orphan visits.');
}

/**
* @return Paginator<Visit>
*/
protected function getVisitsPaginator(InputInterface $input, DateRange $dateRange): Paginator
{
return $this->visitsHelper->nonOrphanVisits(new VisitsParams($dateRange));
Expand Down
3 changes: 3 additions & 0 deletions module/CLI/src/Command/Visit/GetOrphanVisitsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ enumToString(OrphanVisitType::class),
));
}

/**
* @return Paginator<Visit>
*/
protected function getVisitsPaginator(InputInterface $input, DateRange $dateRange): Paginator
{
$rawType = $input->getOption('type');
Expand Down
2 changes: 2 additions & 0 deletions module/CLI/test/Command/Db/CreateDatabaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand All @@ -31,6 +32,7 @@ class CreateDatabaseCommandTest extends TestCase
private MockObject & ProcessRunnerInterface $processHelper;
private MockObject & Connection $regularConn;
private MockObject & ClassMetadataFactory $metadataFactory;
/** @var MockObject&AbstractSchemaManager<SQLitePlatform> */
private MockObject & AbstractSchemaManager $schemaManager;
private MockObject & Driver $driver;

Expand Down
1 change: 1 addition & 0 deletions module/Core/src/Domain/Repository/DomainRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Shlinkio\Shlink\Rest\ApiKey\Role;
use Shlinkio\Shlink\Rest\Entity\ApiKey;

/** @extends EntitySpecificationRepository<Domain> */
class DomainRepository extends EntitySpecificationRepository implements DomainRepositoryInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
use Shlinkio\Shlink\Rest\Entity\ApiKey;

/** @extends ObjectRepository<Domain> */
interface DomainRepositoryInterface extends ObjectRepository, EntitySpecificationRepositoryInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Shlinkio\Shlink\Common\Validation\HostAndPortValidator;
use Shlinkio\Shlink\Common\Validation\InputFactory;

/** @extends InputFilter<mixed> */
class DomainRedirectsInputFilter extends InputFilter
{
public const DOMAIN = 'domain';
Expand Down
13 changes: 9 additions & 4 deletions module/Core/src/EventDispatcher/PublishingUpdatesGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

namespace Shlinkio\Shlink\Core\EventDispatcher;

use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
use Shlinkio\Shlink\Common\UpdatePublishing\Update;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Shlinkio\Shlink\Core\ShortUrl\Transformer\ShortUrlDataTransformerInterface;
use Shlinkio\Shlink\Core\Visit\Entity\Visit;

final readonly class PublishingUpdatesGenerator implements PublishingUpdatesGeneratorInterface
{
public function __construct(private DataTransformerInterface $shortUrlTransformer)
public function __construct(private ShortUrlDataTransformerInterface $shortUrlTransformer)
{
}

public function newVisitUpdate(Visit $visit): Update
{
return Update::forTopicAndPayload(Topic::NEW_VISIT->value, [
'shortUrl' => $this->shortUrlTransformer->transform($visit->shortUrl),
'shortUrl' => $this->transformShortUrl($visit->shortUrl),
'visit' => $visit->jsonSerialize(),
]);
}
Expand All @@ -36,7 +36,7 @@ public function newShortUrlVisitUpdate(Visit $visit): Update
$topic = Topic::newShortUrlVisit($shortUrl?->getShortCode());

return Update::forTopicAndPayload($topic, [
'shortUrl' => $this->shortUrlTransformer->transform($shortUrl),
'shortUrl' => $this->transformShortUrl($shortUrl),
'visit' => $visit->jsonSerialize(),
]);
}
Expand All @@ -47,4 +47,9 @@ public function newShortUrlUpdate(ShortUrl $shortUrl): Update
'shortUrl' => $this->shortUrlTransformer->transform($shortUrl),
]);
}

private function transformShortUrl(?ShortUrl $shortUrl): array
{
return $shortUrl === null ? [] : $this->shortUrlTransformer->transform($shortUrl);
}
}
3 changes: 3 additions & 0 deletions module/Core/src/Exception/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ValidationException extends InvalidArgumentException implements ProblemDet

private array $invalidElements;

/**
* @param InputFilterInterface<mixed> $inputFilter
*/
public static function fromInputFilter(InputFilterInterface $inputFilter, ?Throwable $prev = null): self
{
return static::fromArray($inputFilter->getMessages(), $prev);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

use Pagerfanta\Adapter\AdapterInterface;

/**
* @template T
* @implements AdapterInterface<T>
*/
abstract class AbstractCacheableCountPaginatorAdapter implements AdapterInterface
{
private ?int $count = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use function Shlinkio\Shlink\Core\ArrayUtils\contains;
use function Shlinkio\Shlink\Core\enumValues;

/** @extends InputFilter<mixed> */
class RedirectRulesInputFilter extends InputFilter
{
public const REDIRECT_RULES = 'redirectRules';
Expand Down Expand Up @@ -44,6 +45,9 @@ public static function initialize(array $rawData): self
return $instance;
}

/**
* @return InputFilter<mixed>
*/
private static function createRedirectRuleInputFilter(): InputFilter
{
$redirectRuleInputFilter = new InputFilter();
Expand All @@ -60,6 +64,9 @@ private static function createRedirectRuleInputFilter(): InputFilter
return $redirectRuleInputFilter;
}

/**
* @return InputFilter<mixed>
*/
private static function createRedirectConditionInputFilter(): InputFilter
{
$redirectConditionInputFilter = new InputFilter();
Expand Down
6 changes: 3 additions & 3 deletions module/Core/src/ShortUrl/Entity/ShortUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class ShortUrl extends AbstractEntity
{
/**
* @param Collection<int, Tag> $tags
* @param Collection<int, Visit> & Selectable $visits
* @param Collection<int, ShortUrlVisitsCount> & Selectable $visitsCounts
* @param Collection<int, Visit> & Selectable<int, Visit> $visits
* @param Collection<int, ShortUrlVisitsCount> & Selectable<int, ShortUrlVisitsCount> $visitsCounts
*/
private function __construct(
private string $longUrl,
Expand Down Expand Up @@ -213,7 +213,7 @@ public function mostRecentImportedVisitDate(): ?Chronos
}

/**
* @param Collection<int, Visit> & Selectable $visits
* @param Collection<int, Visit> & Selectable<int, Visit> $visits
* @internal
*/
public function setVisits(Collection & Selectable $visits): self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use const Shlinkio\Shlink\LOOSE_URI_MATCHER;
use const Shlinkio\Shlink\MIN_SHORT_CODES_LENGTH;

/** @extends InputFilter<mixed> */
class ShortUrlInputFilter extends InputFilter
{
// Fields for creation only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use function Shlinkio\Shlink\Core\enumValues;

/** @extends InputFilter<mixed> */
class ShortUrlsParamsInputFilter extends InputFilter
{
public const PAGE = 'page';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

use Pagerfanta\Adapter\AdapterInterface;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlWithVisitsSummary;
use Shlinkio\Shlink\Core\ShortUrl\Persistence\ShortUrlsCountFiltering;
use Shlinkio\Shlink\Core\ShortUrl\Persistence\ShortUrlsListFiltering;
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlListRepositoryInterface;
use Shlinkio\Shlink\Rest\Entity\ApiKey;

/** @implements AdapterInterface<ShortUrlWithVisitsSummary> */
readonly class ShortUrlRepositoryAdapter implements AdapterInterface
{
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;

/** @extends EntitySpecificationRepository<ShortUrl> */
class CrawlableShortCodesQuery extends EntitySpecificationRepository implements CrawlableShortCodesQueryInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use function sprintf;

/** @extends EntitySpecificationRepository<ShortUrl> */
class ExpiredShortUrlsRepository extends EntitySpecificationRepository implements ExpiredShortUrlsRepositoryInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use function Shlinkio\Shlink\Core\ArrayUtils\map;
use function sprintf;

/** @extends EntitySpecificationRepository<ShortUrl> */
class ShortUrlListRepository extends EntitySpecificationRepository implements ShortUrlListRepositoryInterface
{
/**
Expand Down
1 change: 1 addition & 0 deletions module/Core/src/ShortUrl/Repository/ShortUrlRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use function count;
use function strtolower;

/** @extends EntitySpecificationRepository<ShortUrl> */
class ShortUrlRepository extends EntitySpecificationRepository implements ShortUrlRepositoryInterface
{
public function findOneWithDomainFallback(ShortUrlIdentifier $identifier, ShortUrlMode $shortUrlMode): ?ShortUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode;
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;

/** @extends ObjectRepository<ShortUrl> */
interface ShortUrlRepositoryInterface extends ObjectRepository, EntitySpecificationRepositoryInterface
{
public function findOneWithDomainFallback(ShortUrlIdentifier $identifier, ShortUrlMode $shortUrlMode): ?ShortUrl;
Expand Down
3 changes: 1 addition & 2 deletions module/Core/src/ShortUrl/ShortUrlListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Shlinkio\Shlink\Common\Paginator\Paginator;
use Shlinkio\Shlink\Core\Options\UrlShortenerOptions;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlWithVisitsSummary;
use Shlinkio\Shlink\Core\ShortUrl\Paginator\Adapter\ShortUrlRepositoryAdapter;
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlListRepositoryInterface;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
Expand All @@ -21,7 +20,7 @@ public function __construct(
}

/**
* @return ShortUrlWithVisitsSummary[]|Paginator
* @inheritDoc
*/
public function listShortUrls(ShortUrlsParams $params, ?ApiKey $apiKey = null): Paginator
{
Expand Down
2 changes: 1 addition & 1 deletion module/Core/src/ShortUrl/ShortUrlListServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
interface ShortUrlListServiceInterface
{
/**
* @return ShortUrlWithVisitsSummary[]|Paginator
* @return Paginator<ShortUrlWithVisitsSummary>
*/
public function listShortUrls(ShortUrlsParams $params, ?ApiKey $apiKey = null): Paginator;
}
Loading

0 comments on commit c10f0db

Please sign in to comment.