Increaed phpstan level to 7

This commit is contained in:
Alejandro Celaya 2021-07-17 20:58:24 +02:00
parent 8efda2ef56
commit bceea090ed
9 changed files with 28 additions and 8 deletions

View File

@ -112,7 +112,7 @@
], ],
"cs": "phpcs", "cs": "phpcs",
"cs:fix": "phpcbf", "cs:fix": "phpcbf",
"stan": "phpstan analyse module/*/src/ module/*/config config docker/config data/migrations --level=6", "stan": "phpstan analyse module/*/src/ module/*/config config docker/config data/migrations --level=7",
"test": [ "test": [
"@test:unit", "@test:unit",
"@test:db", "@test:db",

View File

@ -8,6 +8,8 @@ use Shlinkio\Shlink\Core\Domain\DomainServiceInterface;
use Shlinkio\Shlink\Rest\ApiKey\Model\RoleDefinition; use Shlinkio\Shlink\Rest\ApiKey\Model\RoleDefinition;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use function is_string;
class RoleResolver implements RoleResolverInterface class RoleResolver implements RoleResolverInterface
{ {
public function __construct(private DomainServiceInterface $domainService) public function __construct(private DomainServiceInterface $domainService)
@ -23,7 +25,7 @@ class RoleResolver implements RoleResolverInterface
if ($author) { if ($author) {
$roleDefinitions[] = RoleDefinition::forAuthoredShortUrls(); $roleDefinitions[] = RoleDefinition::forAuthoredShortUrls();
} }
if ($domainAuthority !== null) { if (is_string($domainAuthority)) {
$domain = $this->domainService->getOrCreate($domainAuthority); $domain = $this->domainService->getOrCreate($domainAuthority);
$roleDefinitions[] = RoleDefinition::forDomain($domain); $roleDefinitions[] = RoleDefinition::forDomain($domain);
} }

View File

@ -11,6 +11,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Throwable; use Throwable;
use function is_string;
use function sprintf; use function sprintf;
abstract class AbstractWithDateRangeCommand extends BaseCommand abstract class AbstractWithDateRangeCommand extends BaseCommand
@ -49,7 +50,7 @@ abstract class AbstractWithDateRangeCommand extends BaseCommand
private function getDateOption(InputInterface $input, OutputInterface $output, string $key): ?Chronos private function getDateOption(InputInterface $input, OutputInterface $output, string $key): ?Chronos
{ {
$value = $this->getOptionWithDeprecatedFallback($input, $key); $value = $this->getOptionWithDeprecatedFallback($input, $key);
if (empty($value)) { if (empty($value) || ! is_string($value)) {
return null; return null;
} }

View File

@ -68,6 +68,21 @@ class RoleResolverTest extends TestCase
[RoleDefinition::forDomain($domain)], [RoleDefinition::forDomain($domain)],
1, 1,
]; ];
yield 'false domain role' => [
$buildInput([RoleResolver::DOMAIN_ONLY_PARAM => false]),
[],
0,
];
yield 'true domain role' => [
$buildInput([RoleResolver::DOMAIN_ONLY_PARAM => true]),
[],
0,
];
yield 'string array domain role' => [
$buildInput([RoleResolver::DOMAIN_ONLY_PARAM => ['foo', 'bar']]),
[],
0,
];
yield 'author role only' => [ yield 'author role only' => [
$buildInput([RoleResolver::DOMAIN_ONLY_PARAM => null, RoleResolver::AUTHOR_ONLY_PARAM => true]), $buildInput([RoleResolver::DOMAIN_ONLY_PARAM => null, RoleResolver::AUTHOR_ONLY_PARAM => true]),
[RoleDefinition::forAuthoredShortUrls()], [RoleDefinition::forAuthoredShortUrls()],

View File

@ -23,6 +23,7 @@ class RobotsAction implements RequestHandlerInterface, StatusCodeInterface
public function handle(ServerRequestInterface $request): ResponseInterface public function handle(ServerRequestInterface $request): ResponseInterface
{ {
// @phpstan-ignore-next-line The "Response" phpdoc is wrong
return new Response(self::STATUS_OK, ['Content-type' => 'text/plain'], $this->buildRobots()); return new Response(self::STATUS_OK, ['Content-type' => 'text/plain'], $this->buildRobots());
} }

View File

@ -49,7 +49,6 @@ final class ShortUrlsOrdering
]); ]);
} }
/** @var string|array $orderBy */
if (! $isArray) { if (! $isArray) {
[$field, $dir] = array_pad(explode('-', $orderBy), 2, null); [$field, $dir] = array_pad(explode('-', $orderBy), 2, null);
$this->orderField = $field; $this->orderField = $field;

View File

@ -7,8 +7,7 @@ namespace Shlinkio\Shlink\Core\Util;
use Cocur\Slugify\SlugifyInterface; use Cocur\Slugify\SlugifyInterface;
use Symfony\Component\String\AbstractUnicodeString; use Symfony\Component\String\AbstractUnicodeString;
use Symfony\Component\String\Slugger\SluggerInterface; use Symfony\Component\String\Slugger\SluggerInterface;
use Symfony\Component\String\UnicodeString;
use function Symfony\Component\String\s;
class CocurSymfonySluggerBridge implements SluggerInterface class CocurSymfonySluggerBridge implements SluggerInterface
{ {
@ -18,6 +17,6 @@ class CocurSymfonySluggerBridge implements SluggerInterface
public function slug(string $string, string $separator = '-', ?string $locale = null): AbstractUnicodeString public function slug(string $string, string $separator = '-', ?string $locale = null): AbstractUnicodeString
{ {
return s($this->slugger->slugify($string, $separator)); return new UnicodeString($this->slugger->slugify($string, $separator));
} }
} }

View File

@ -17,8 +17,10 @@ class DropDefaultDomainFromRequestMiddleware implements MiddlewareInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{ {
/** @var array $body */
$body = $request->getParsedBody();
$request = $request->withQueryParams($this->sanitizeDomainFromPayload($request->getQueryParams())) $request = $request->withQueryParams($this->sanitizeDomainFromPayload($request->getQueryParams()))
->withParsedBody($this->sanitizeDomainFromPayload($request->getParsedBody())); ->withParsedBody($this->sanitizeDomainFromPayload($body));
return $handler->handle($request); return $handler->handle($request);
} }

View File

@ -32,6 +32,7 @@ class OverrideDomainMiddleware implements MiddlewareInterface
$domain = $this->domainService->getDomain($domainId); $domain = $this->domainService->getDomain($domainId);
if ($requestMethod === RequestMethodInterface::METHOD_POST) { if ($requestMethod === RequestMethodInterface::METHOD_POST) {
/** @var array $payload */
$payload = $request->getParsedBody(); $payload = $request->getParsedBody();
$payload[ShortUrlInputFilter::DOMAIN] = $domain->getAuthority(); $payload[ShortUrlInputFilter::DOMAIN] = $domain->getAuthority();