mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 23:23:42 -06:00
Increased phpstan level to 8
This commit is contained in:
parent
2eeb762cd9
commit
95770ac104
@ -62,9 +62,9 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"devster/ubench": "^2.1",
|
"devster/ubench": "^2.1",
|
||||||
"dms/phpunit-arraysubset-asserts": "^0.2.1",
|
"dms/phpunit-arraysubset-asserts": "^v0.3.0",
|
||||||
"eaglewu/swoole-ide-helper": "dev-master",
|
"eaglewu/swoole-ide-helper": "dev-master",
|
||||||
"infection/infection": "^0.21.0",
|
"infection/infection": "^0.23.0",
|
||||||
"phpspec/prophecy-phpunit": "^2.0",
|
"phpspec/prophecy-phpunit": "^2.0",
|
||||||
"phpstan/phpstan": "^0.12.92",
|
"phpstan/phpstan": "^0.12.92",
|
||||||
"phpstan/phpstan-symfony": "^0.12.41",
|
"phpstan/phpstan-symfony": "^0.12.41",
|
||||||
@ -74,7 +74,7 @@
|
|||||||
"shlinkio/php-coding-standard": "~2.1.1",
|
"shlinkio/php-coding-standard": "~2.1.1",
|
||||||
"shlinkio/shlink-test-utils": "^2.1",
|
"shlinkio/shlink-test-utils": "^2.1",
|
||||||
"symfony/var-dumper": "^5.2",
|
"symfony/var-dumper": "^5.2",
|
||||||
"veewee/composer-run-parallel": "^0.1.0"
|
"veewee/composer-run-parallel": "^1.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@ -113,7 +113,7 @@
|
|||||||
],
|
],
|
||||||
"cs": "phpcs",
|
"cs": "phpcs",
|
||||||
"cs:fix": "phpcbf",
|
"cs:fix": "phpcbf",
|
||||||
"stan": "phpstan analyse module/*/src module/*/config config docker/config data/migrations --level=7",
|
"stan": "phpstan analyse module/*/src module/*/config config docker/config data/migrations --level=8",
|
||||||
"test": [
|
"test": [
|
||||||
"@test:unit",
|
"@test:unit",
|
||||||
"@test:db",
|
"@test:db",
|
||||||
|
@ -55,7 +55,7 @@ class LocateVisit
|
|||||||
}
|
}
|
||||||
|
|
||||||
$isLocatable = $originalIpAddress !== null || $visit->isLocatable();
|
$isLocatable = $originalIpAddress !== null || $visit->isLocatable();
|
||||||
$addr = $originalIpAddress ?? $visit->getRemoteAddr();
|
$addr = $originalIpAddress ?? $visit->getRemoteAddr() ?? '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$location = $isLocatable ? $this->ipLocationResolver->resolveIpLocation($addr) : Location::emptyInstance();
|
$location = $isLocatable ? $this->ipLocationResolver->resolveIpLocation($addr) : Location::emptyInstance();
|
||||||
|
@ -42,7 +42,7 @@ final class MercureUpdatesGenerator implements MercureUpdatesGeneratorInterface
|
|||||||
public function newShortUrlVisitUpdate(Visit $visit): Update
|
public function newShortUrlVisitUpdate(Visit $visit): Update
|
||||||
{
|
{
|
||||||
$shortUrl = $visit->getShortUrl();
|
$shortUrl = $visit->getShortUrl();
|
||||||
$topic = sprintf('%s/%s', self::NEW_VISIT_TOPIC, $shortUrl->getShortCode());
|
$topic = sprintf('%s/%s', self::NEW_VISIT_TOPIC, $shortUrl?->getShortCode());
|
||||||
|
|
||||||
return new Update($topic, $this->serialize([
|
return new Update($topic, $this->serialize([
|
||||||
'shortUrl' => $this->shortUrlTransformer->transform($shortUrl),
|
'shortUrl' => $this->shortUrlTransformer->transform($shortUrl),
|
||||||
|
@ -19,7 +19,7 @@ final class ShortUrlsParams
|
|||||||
private array $tags;
|
private array $tags;
|
||||||
private ShortUrlsOrdering $orderBy;
|
private ShortUrlsOrdering $orderBy;
|
||||||
private ?DateRange $dateRange;
|
private ?DateRange $dateRange;
|
||||||
private ?int $itemsPerPage = null;
|
private int $itemsPerPage;
|
||||||
|
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
@ -29,13 +29,16 @@ final class Visitor
|
|||||||
$this->userAgent = $this->cropToLength($userAgent, self::USER_AGENT_MAX_LENGTH);
|
$this->userAgent = $this->cropToLength($userAgent, self::USER_AGENT_MAX_LENGTH);
|
||||||
$this->referer = $this->cropToLength($referer, self::REFERER_MAX_LENGTH);
|
$this->referer = $this->cropToLength($referer, self::REFERER_MAX_LENGTH);
|
||||||
$this->visitedUrl = $this->cropToLength($visitedUrl, self::VISITED_URL_MAX_LENGTH);
|
$this->visitedUrl = $this->cropToLength($visitedUrl, self::VISITED_URL_MAX_LENGTH);
|
||||||
$this->remoteAddress = $this->cropToLength($remoteAddress, self::REMOTE_ADDRESS_MAX_LENGTH);
|
$this->remoteAddress = $remoteAddress === null ? null : $this->cropToLength(
|
||||||
|
$remoteAddress,
|
||||||
|
self::REMOTE_ADDRESS_MAX_LENGTH,
|
||||||
|
);
|
||||||
$this->potentialBot = isCrawler($userAgent);
|
$this->potentialBot = isCrawler($userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function cropToLength(?string $value, int $length): ?string
|
private function cropToLength(string $value, int $length): string
|
||||||
{
|
{
|
||||||
return $value === null ? null : substr($value, 0, $length);
|
return substr($value, 0, $length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromRequest(ServerRequestInterface $request): self
|
public static function fromRequest(ServerRequestInterface $request): self
|
||||||
|
@ -13,7 +13,7 @@ final class VisitsParams
|
|||||||
private const FIRST_PAGE = 1;
|
private const FIRST_PAGE = 1;
|
||||||
private const ALL_ITEMS = -1;
|
private const ALL_ITEMS = -1;
|
||||||
|
|
||||||
private ?DateRange $dateRange;
|
private DateRange $dateRange;
|
||||||
private int $itemsPerPage;
|
private int $itemsPerPage;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
@ -18,7 +18,6 @@ use Shlinkio\Shlink\Core\Model\ShortUrlsOrdering;
|
|||||||
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
|
use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl;
|
||||||
|
|
||||||
use function array_column;
|
use function array_column;
|
||||||
use function array_key_exists;
|
|
||||||
use function count;
|
use function count;
|
||||||
use function Functional\contains;
|
use function Functional\contains;
|
||||||
|
|
||||||
@ -59,6 +58,7 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
|
|||||||
|
|
||||||
// visitsCount and visitCount are deprecated. Only visits should work
|
// visitsCount and visitCount are deprecated. Only visits should work
|
||||||
if (contains(['visits', 'visitsCount', 'visitCount'], $fieldName)) {
|
if (contains(['visits', 'visitsCount', 'visitCount'], $fieldName)) {
|
||||||
|
// FIXME This query is inefficient. Debug it.
|
||||||
$qb->addSelect('COUNT(DISTINCT v) AS totalVisits')
|
$qb->addSelect('COUNT(DISTINCT v) AS totalVisits')
|
||||||
->leftJoin('s.visits', 'v')
|
->leftJoin('s.visits', 'v')
|
||||||
->groupBy('s')
|
->groupBy('s')
|
||||||
@ -75,9 +75,11 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
|
|||||||
'dateCreated' => 'dateCreated',
|
'dateCreated' => 'dateCreated',
|
||||||
'title' => 'title',
|
'title' => 'title',
|
||||||
];
|
];
|
||||||
if (array_key_exists($fieldName, $fieldNameMap)) {
|
$resolvedFieldName = $fieldNameMap[$fieldName] ?? null;
|
||||||
$qb->orderBy('s.' . $fieldNameMap[$fieldName], $order);
|
if ($resolvedFieldName !== null) {
|
||||||
|
$qb->orderBy('s.' . $resolvedFieldName, $order);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $qb->getQuery()->getResult();
|
return $qb->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,10 +196,12 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
|
|||||||
|
|
||||||
private function doShortCodeIsInUse(ShortUrlIdentifier $identifier, ?Specification $spec, ?int $lockMode): bool
|
private function doShortCodeIsInUse(ShortUrlIdentifier $identifier, ?Specification $spec, ?int $lockMode): bool
|
||||||
{
|
{
|
||||||
$qb = $this->createFindOneQueryBuilder($identifier, $spec);
|
$qb = $this->createFindOneQueryBuilder($identifier, $spec)->select('s.id');
|
||||||
$qb->select('s.id');
|
$query = $qb->getQuery();
|
||||||
|
|
||||||
$query = $qb->getQuery()->setLockMode($lockMode);
|
if ($lockMode !== null) {
|
||||||
|
$query = $query->setLockMode($lockMode);
|
||||||
|
}
|
||||||
|
|
||||||
return $query->getOneOrNullResult() !== null;
|
return $query->getOneOrNullResult() !== null;
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,12 @@ class ApiKeyService implements ApiKeyServiceInterface
|
|||||||
private function buildApiKeyWithParams(?Chronos $expirationDate, ?string $name): ApiKey
|
private function buildApiKeyWithParams(?Chronos $expirationDate, ?string $name): ApiKey
|
||||||
{
|
{
|
||||||
return match (true) {
|
return match (true) {
|
||||||
$expirationDate === null && $name === null => ApiKey::create(),
|
|
||||||
$expirationDate !== null && $name !== null => ApiKey::fromMeta(
|
$expirationDate !== null && $name !== null => ApiKey::fromMeta(
|
||||||
ApiKeyMeta::withNameAndExpirationDate($name, $expirationDate),
|
ApiKeyMeta::withNameAndExpirationDate($name, $expirationDate),
|
||||||
),
|
),
|
||||||
$name === null => ApiKey::fromMeta(ApiKeyMeta::withExpirationDate($expirationDate)),
|
$expirationDate !== null => ApiKey::fromMeta(ApiKeyMeta::withExpirationDate($expirationDate)),
|
||||||
default => ApiKey::fromMeta(ApiKeyMeta::withName($name)),
|
$name !== null => ApiKey::fromMeta(ApiKeyMeta::withName($name)),
|
||||||
|
default => ApiKey::create(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user