mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-12 01:54:41 +08:00
Updated to coding standard v2.1
This commit is contained in:
@@ -46,10 +46,7 @@ abstract class AbstractTrackingAction implements MiddlewareInterface
|
||||
* Process an incoming server request and return a response, optionally delegating
|
||||
* to the next middleware component to create the response.
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param RequestHandlerInterface $handler
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
|
||||
@@ -41,10 +41,7 @@ class QrCodeAction implements MiddlewareInterface
|
||||
* Process an incoming server request and return a response, optionally delegating
|
||||
* to the next middleware component to create the response.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param RequestHandlerInterface $handler
|
||||
*
|
||||
* @return Response
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
@@ -71,8 +68,6 @@ class QrCodeAction implements MiddlewareInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return int
|
||||
*/
|
||||
private function getSizeParam(Request $request): int
|
||||
{
|
||||
|
||||
@@ -76,7 +76,7 @@ class SimplifiedConfigParser
|
||||
$simplifiedConfigOrder = array_flip(array_keys(self::SIMPLIFIED_CONFIG_MAPPING));
|
||||
uksort(
|
||||
$configForExistingKeys,
|
||||
fn (string $a, string $b): int => $simplifiedConfigOrder[$a] - $simplifiedConfigOrder[$b]
|
||||
fn (string $a, string $b): int => $simplifiedConfigOrder[$a] - $simplifiedConfigOrder[$b],
|
||||
);
|
||||
|
||||
return $configForExistingKeys;
|
||||
|
||||
@@ -8,7 +8,7 @@ use function Shlinkio\Shlink\Common\loadConfigFromGlob;
|
||||
|
||||
class ConfigProvider
|
||||
{
|
||||
public function __invoke()
|
||||
public function __invoke(): array
|
||||
{
|
||||
return loadConfigFromGlob(__DIR__ . '/../config/{,*.}config.php');
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ class ShortUrl extends AbstractEntity
|
||||
$hasAllTags = count($shortUrlTags) === count($tags) && array_reduce(
|
||||
$tags,
|
||||
fn (bool $hasAllTags, string $tag) => $hasAllTags && contains($shortUrlTags, $tag),
|
||||
true
|
||||
true,
|
||||
);
|
||||
|
||||
return $hasAllTags;
|
||||
|
||||
@@ -28,9 +28,7 @@ class NotFoundTemplateHandler implements RequestHandlerInterface
|
||||
/**
|
||||
* Dispatch the next available middleware and return the response.
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
|
||||
@@ -62,14 +62,14 @@ class LocateShortUrlVisit
|
||||
private function downloadOrUpdateGeoLiteDb(string $visitId): bool
|
||||
{
|
||||
try {
|
||||
$this->dbUpdater->checkDbUpdate(function (bool $olderDbExists) {
|
||||
$this->dbUpdater->checkDbUpdate(function (bool $olderDbExists): void {
|
||||
$this->logger->notice(sprintf('%s GeoLite2 database...', $olderDbExists ? 'Updating' : 'Downloading'));
|
||||
});
|
||||
} catch (GeolocationDbUpdateFailedException $e) {
|
||||
if (! $e->olderDbExists()) {
|
||||
$this->logger->error(
|
||||
'GeoLite2 database download failed. It is not possible to locate visit with id {visitId}. {e}',
|
||||
['e' => $e, 'visitId' => $visitId]
|
||||
['e' => $e, 'visitId' => $visitId],
|
||||
);
|
||||
return false;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class LocateShortUrlVisit
|
||||
} catch (WrongIpException $e) {
|
||||
$this->logger->warning(
|
||||
'Tried to locate visit with id "{visitId}", but its address seems to be wrong. {e}',
|
||||
['e' => $e, 'visitId' => $visitId]
|
||||
['e' => $e, 'visitId' => $visitId],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class NotifyVisitToWebHooks
|
||||
return map($this->webhooks, function (string $webhook) use ($requestOptions, $visitId) {
|
||||
$promise = $this->httpClient->requestAsync(RequestMethodInterface::METHOD_POST, $webhook, $requestOptions);
|
||||
return $promise->otherwise(
|
||||
partial_left(Closure::fromCallable([$this, 'logWebhookFailure']), $webhook, $visitId)
|
||||
partial_left(Closure::fromCallable([$this, 'logWebhookFailure']), $webhook, $visitId),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class DeleteShortUrlException extends DomainException implements ProblemDetailsE
|
||||
$e = new self(sprintf(
|
||||
'Impossible to delete short URL with short code "%s" since it has more than "%s" visits.',
|
||||
$shortCode,
|
||||
$threshold
|
||||
$threshold,
|
||||
));
|
||||
|
||||
$e->detail = $e->getMessage();
|
||||
|
||||
@@ -63,7 +63,7 @@ class ValidationException extends InvalidArgumentException implements ProblemDet
|
||||
$this->invalidElementsToString(),
|
||||
PHP_EOL,
|
||||
PHP_EOL,
|
||||
$this->getTraceAsString()
|
||||
$this->getTraceAsString(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class ValidationException extends InvalidArgumentException implements ProblemDet
|
||||
return reduce_left($this->getInvalidElements(), fn ($messages, string $name, $_, string $acc) => $acc . sprintf(
|
||||
"\n '%s' => %s",
|
||||
$name,
|
||||
is_array($messages) ? print_r($messages, true) : $messages
|
||||
is_array($messages) ? print_r($messages, true) : $messages,
|
||||
), '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,7 @@ class QrCodeCacheMiddleware implements MiddlewareInterface
|
||||
* Process an incoming server request and return a response, optionally delegating
|
||||
* to the next middleware component to create the response.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param RequestHandlerInterface $handler
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function process(Request $request, RequestHandlerInterface $handler): Response
|
||||
{
|
||||
|
||||
@@ -23,7 +23,6 @@ final class CreateShortUrlData
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UriInterface
|
||||
*/
|
||||
public function getLongUrl(): UriInterface
|
||||
{
|
||||
@@ -39,7 +38,6 @@ final class CreateShortUrlData
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ShortUrlMeta
|
||||
*/
|
||||
public function getMeta(): ShortUrlMeta
|
||||
{
|
||||
|
||||
@@ -48,7 +48,7 @@ final class ShortUrlMeta
|
||||
* @param string|null $domain
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public static function createFromParams(
|
||||
public static function createFromParams( // phpcs:ignore
|
||||
$validSince = null,
|
||||
$validUntil = null,
|
||||
$customSlug = null,
|
||||
|
||||
@@ -36,7 +36,7 @@ final class Visitor
|
||||
return new self(
|
||||
$request->getHeaderLine('User-Agent'),
|
||||
$request->getHeaderLine('Referer'),
|
||||
$request->getAttribute(IpAddressMiddlewareFactory::REQUEST_ATTR)
|
||||
$request->getAttribute(IpAddressMiddlewareFactory::REQUEST_ATTR),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ final class VisitsParams
|
||||
return new self(
|
||||
new DateRange($startDate, $endDate),
|
||||
(int) ($query['page'] ?? 1),
|
||||
isset($query['itemsPerPage']) ? (int) $query['itemsPerPage'] : null
|
||||
isset($query['itemsPerPage']) ? (int) $query['itemsPerPage'] : null,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ class AppOptions extends AbstractOptions
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDisableTrackParam(): ?string
|
||||
{
|
||||
|
||||
@@ -8,8 +8,8 @@ use Zend\Stdlib\AbstractOptions;
|
||||
|
||||
class DeleteShortUrlsOptions extends AbstractOptions
|
||||
{
|
||||
private $visitsThreshold = 15;
|
||||
private $checkVisitsThreshold = true;
|
||||
private int $visitsThreshold = 15;
|
||||
private bool $checkVisitsThreshold = true;
|
||||
|
||||
public function getVisitsThreshold(): int
|
||||
{
|
||||
|
||||
@@ -8,20 +8,18 @@ use Zend\Stdlib\AbstractOptions;
|
||||
|
||||
class UrlShortenerOptions extends AbstractOptions
|
||||
{
|
||||
// phpcs:disable
|
||||
protected $__strictMode__ = false;
|
||||
// phpcs:enable
|
||||
protected $__strictMode__ = false; // phpcs:ignore
|
||||
|
||||
private $validateUrl = true;
|
||||
private bool $validateUrl = true;
|
||||
|
||||
public function isUrlValidationEnabled(): bool
|
||||
{
|
||||
return $this->validateUrl;
|
||||
}
|
||||
|
||||
protected function setValidateUrl($validateUrl): self
|
||||
protected function setValidateUrl(bool $validateUrl): self
|
||||
{
|
||||
$this->validateUrl = (bool) $validateUrl;
|
||||
$this->validateUrl = $validateUrl;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,12 @@ class ShortUrlRepositoryAdapter implements AdapterInterface
|
||||
private array $tags;
|
||||
private ?DateRange $dateRange;
|
||||
|
||||
/**
|
||||
* @param string|array|null $orderBy
|
||||
*/
|
||||
public function __construct(
|
||||
ShortUrlRepositoryInterface $repository,
|
||||
$searchTerm = null,
|
||||
?string $searchTerm = null,
|
||||
array $tags = [],
|
||||
$orderBy = null,
|
||||
?DateRange $dateRange = null
|
||||
@@ -41,9 +44,8 @@ class ShortUrlRepositoryAdapter implements AdapterInterface
|
||||
*
|
||||
* @param int $offset Page offset
|
||||
* @param int $itemCountPerPage Number of items per page
|
||||
* @return array
|
||||
*/
|
||||
public function getItems($offset, $itemCountPerPage): array
|
||||
public function getItems($offset, $itemCountPerPage): array // phpcs:ignore
|
||||
{
|
||||
return $this->repository->findList(
|
||||
$itemCountPerPage,
|
||||
@@ -51,7 +53,7 @@ class ShortUrlRepositoryAdapter implements AdapterInterface
|
||||
$this->searchTerm,
|
||||
$this->tags,
|
||||
$this->orderBy,
|
||||
$this->dateRange
|
||||
$this->dateRange,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@ class VisitsPaginatorAdapter implements AdapterInterface
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function getItems($offset, $itemCountPerPage): array
|
||||
public function getItems($offset, $itemCountPerPage): array // phpcs:ignore
|
||||
{
|
||||
return $this->visitRepository->findVisitsByShortCode(
|
||||
$this->shortCode,
|
||||
$this->params->getDateRange(),
|
||||
$itemCountPerPage,
|
||||
$offset
|
||||
$offset,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,9 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array|null $orderBy
|
||||
*/
|
||||
private function processOrderByForList(QueryBuilder $qb, $orderBy): array
|
||||
{
|
||||
$isArray = is_array($orderBy);
|
||||
@@ -117,7 +120,7 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
|
||||
$qb->andWhere($qb->expr()->orX(
|
||||
$qb->expr()->like('s.longUrl', ':searchPattern'),
|
||||
$qb->expr()->like('s.shortCode', ':searchPattern'),
|
||||
$qb->expr()->like('t.name', ':searchPattern')
|
||||
$qb->expr()->like('t.name', ':searchPattern'),
|
||||
));
|
||||
$qb->setParameter('searchPattern', '%' . $searchTerm . '%');
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class DeleteShortUrlService implements DeleteShortUrlServiceInterface
|
||||
if (! $ignoreThreshold && $this->isThresholdReached($shortUrl)) {
|
||||
throw Exception\DeleteShortUrlException::fromVisitsThreshold(
|
||||
$this->deleteShortUrlsOptions->getVisitsThreshold(),
|
||||
$shortUrl->getShortCode()
|
||||
$shortUrl->getShortCode(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@ use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException;
|
||||
trait FindShortCodeTrait
|
||||
{
|
||||
/**
|
||||
* @param string $shortCode
|
||||
* @return ShortUrl
|
||||
* @throws ShortUrlNotFoundException
|
||||
*/
|
||||
private function findByShortCode(EntityManagerInterface $em, string $shortCode): ShortUrl
|
||||
|
||||
@@ -22,7 +22,7 @@ class ShortUrlDataTransformer implements DataTransformerInterface
|
||||
/**
|
||||
* @param ShortUrl $shortUrl
|
||||
*/
|
||||
public function transform($shortUrl): array
|
||||
public function transform($shortUrl): array // phpcs:ignore
|
||||
{
|
||||
$longUrl = $shortUrl->getLongUrl();
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ use function trim;
|
||||
trait TagManagerTrait
|
||||
{
|
||||
/**
|
||||
* @param EntityManagerInterface $em
|
||||
* @param string[] $tags
|
||||
* @return Collections\Collection|Tag[]
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user