Skip to content

Commit

Permalink
build: Upgrade to Psalm v5 (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Apr 23, 2024
1 parent da9a110 commit d3d382b
Show file tree
Hide file tree
Showing 19 changed files with 541 additions and 538 deletions.
1 change: 0 additions & 1 deletion src/DependencyInjection/Compiler/AddConsoleCommandPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ private static function createDefinition(
): Definition {
$decoratedCommandDefinition = $containerBuilder->getDefinition($id);

/** @psalm-suppress ArgumentTypeCoercion */
$commandTagAttributes = self::createCommandTagAttributes(
$id,
$decoratedCommandDefinition->getClass(),
Expand Down
4 changes: 2 additions & 2 deletions src/Input/InvalidInputValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function fromAssert(
$exception->getMessage(),
$inputLabel,
),
(int) $exception->getCode(),
$exception->getCode(),
$exception,
);
}
Expand All @@ -46,7 +46,7 @@ public static function withErrorMessage(
$errorMessage,
$exception->getMessage(),
),
(int) $exception->getCode(),
$exception->getCode(),
$exception,
);
}
Expand Down
12 changes: 1 addition & 11 deletions src/Input/TypedInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ final class TypedInput
/**
* @param ArgumentInput|OptionInput $value
* @param non-empty-string $label
*
* @psalm-suppress RedundantCondition
*/
private function __construct(
private readonly array|bool|string|null $value,
Expand All @@ -46,7 +44,6 @@ private function __construct(
* @param non-empty-string $name
*
* @psalm-assert ArgumentInput $argument
* @psalm-suppress ArgumentTypeCoercion
*/
public static function fromArgument(mixed $argument, string $name): self
{
Expand All @@ -65,7 +62,6 @@ public static function fromArgument(mixed $argument, string $name): self
* @param non-empty-string $name
*
* @psalm-assert OptionInput $option
* @psalm-suppress ArgumentTypeCoercion
*/
public static function fromOption(mixed $option, string $name): self
{
Expand Down Expand Up @@ -104,8 +100,6 @@ public function asStringChoice(
}

/**
* @psalm-suppress MoreSpecificReturnType
*
* @param positive-int|0 $min
* @param positive-int|0 $max
*
Expand All @@ -119,12 +113,10 @@ public function asNaturalWithinRange(
$type = new NaturalRangeType($min, $max);

if (null === $errorMessage) {
/** @psalm-suppress LessSpecificReturnStatement */
return $type->coerceValue($this->value, $this->label);
}

try {
/** @psalm-suppress LessSpecificReturnStatement */
return $type->coerceValue($this->value, $this->label);
} catch (InvalidInputValueType $coercingFailed) {
throw InvalidInputValueType::withErrorMessage(
Expand All @@ -135,6 +127,7 @@ public function asNaturalWithinRange(
}

/**
* @psalm-suppress InvalidReturnType, NoValue
* @template T of BackedEnum
*
* @param class-string<T> $backedEnumClassName
Expand Down Expand Up @@ -162,7 +155,6 @@ public function asBackedEnum(
}

/**
* @psalm-suppress InvalidReturnType
* @template T of BackedEnum
*
* @param class-string<T> $backedEnumClassName
Expand All @@ -178,12 +170,10 @@ public function asNullableBackedEnum(
);

if (null === $errorMessage) {
/** @psalm-suppress InvalidReturnStatement */
return $type->coerceValue($this->value, $this->label);
}

try {
/** @psalm-suppress InvalidReturnStatement */
return $type->coerceValue($this->value, $this->label);
} catch (InvalidInputValueType $coercingFailed) {
throw InvalidInputValueType::withErrorMessage(
Expand Down
5 changes: 5 additions & 0 deletions src/Internal/Generator/TypeMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ private function __construct()
{
}

/**
* @psalm-suppress LessSpecificReturnStatement,MoreSpecificReturnType
*
* @return non-empty-list<InputType>
*/
public static function provideTypes(): array
{
$baseTypes = [
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/InputAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static function () use ($value, $label): void {
}

/**
* @param callable(): void $callable
* @param callable():void $callable
* @param non-empty-string $label
*/
public static function castThrowException(callable $callable, string $label): void
Expand Down
2 changes: 0 additions & 2 deletions src/Internal/Type/ListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ public function getTypeClassNames(): array
];
}

/** @psalm-suppress MoreSpecificReturnType */
public function getPsalmTypeDeclaration(): string
{
/** @psalm-suppress LessSpecificReturnStatement */
return sprintf(
'list<%s>',
$this->innerType->getPsalmTypeDeclaration(),
Expand Down
6 changes: 5 additions & 1 deletion src/Internal/Type/NaturalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@
*/
final class NaturalType implements ScalarType
{
/**
* @psalm-suppress MoreSpecificReturnType
*/
public function coerceValue(array|bool|string|null $value, string $label): int
{
InputAssert::integerString($value, $label);

$intValue = (int) $value;

/** @psalm-suppress InvalidDocblock,MissingClosureReturnType */
/** @psalm-suppress MissingClosureReturnType */
InputAssert::castThrowException(
static fn () => Assert::natural($intValue),
$label,
);

/** @psalm-suppress LessSpecificReturnStatement */
return (int) $value;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Internal/Type/NonEmptyListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function __construct(InputType $innerType)
$this->innerType = $innerType;
}

/**
* @psalm-suppress InvalidReturnType
*/
public function coerceValue(array|bool|string|null $value, string $label): array
{
$list = (new ListType($this->innerType))->coerceValue($value, $label);
Expand All @@ -46,6 +49,7 @@ public function coerceValue(array|bool|string|null $value, string $label): array
$label,
);

/** @psalm-suppress InvalidReturnStatement */
return $list;
}

Expand All @@ -57,10 +61,8 @@ public function getTypeClassNames(): array
];
}

/** @psalm-suppress MoreSpecificReturnType */
public function getPsalmTypeDeclaration(): string
{
/** @psalm-suppress LessSpecificReturnStatement */
return sprintf(
'non-empty-list<%s>',
$this->innerType->getPsalmTypeDeclaration(),
Expand Down
1 change: 0 additions & 1 deletion src/Internal/Type/NullOrNonEmptyStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function coerceValue(array|bool|string|null $value, string $label): ?stri
{
$trimmedValue = (new StringType())->coerceValue($value, $label);

/** @psalm-suppress InvalidReturnStatement */
return '' === $trimmedValue ? null : $trimmedValue;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Internal/Type/PositiveIntegerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
final class PositiveIntegerType implements ScalarType
{
/**
* @psalm-suppress InvalidReturnType,InvalidReturnStatement
*/
public function coerceValue(array|bool|string|null $value, string $label): int
{
$intValue = (new NaturalType())->coerceValue($value, $label);
Expand Down
1 change: 0 additions & 1 deletion src/Internal/Type/RawType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ final class RawType implements InputType
{
public function coerceValue(array|bool|string|null $value, string $label): mixed
{
/** @psalm-suppress NullableReturnStatement */
return $value;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Output/DecoratesOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function setVerbosity(int $level): void
$this->output->setVerbosity(...func_get_args());
}

/**
* @return OutputInterface::VERBOSITY_*
*/
public function getVerbosity(): int
{
return $this->output->getVerbosity(...func_get_args());
Expand Down
1 change: 0 additions & 1 deletion tests/Application/Feature/IOConfigurationSupportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function test_it_supports_application_which_configures_the_io(): void
new NullOutput(),
);

/** @psalm-suppress DocblockTypeContradiction */
self::assertTrue($service->called);
}

Expand Down
1 change: 0 additions & 1 deletion tests/Command/Feature/CommandAwarenessSupportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function test_it_can_be_executed(): void

$this->tester->execute([], ['interactive' => false]);

/** @psalm-suppress DocblockTypeContradiction */
self::assertTrue($this->service->called);
}
}
3 changes: 0 additions & 3 deletions tests/Command/Feature/CommandLazinessSupportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public function test_it_is_instantiated_when_getting_a_non_lazy_defining_propert

$this->application->find('app:lazy')->getSynopsis();

/** @psalm-suppress DocblockTypeContradiction */
self::assertTrue($this->service->called);
}

Expand All @@ -94,7 +93,6 @@ public function test_it_can_be_executed_via_the_command_tester(): void

$tester->execute([], ['interactive' => false]);

/** @psalm-suppress DocblockTypeContradiction */
self::assertTrue($this->service->called);
}

Expand All @@ -113,7 +111,6 @@ public function test_it_can_be_executed_via_the_application(): void

self::assertSame(ExitCode::SUCCESS, $exitCode);

/** @psalm-suppress DocblockTypeContradiction */
self::assertTrue($this->service->called);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function test_it_can_be_executed(): void

$this->tester->execute([], ['interactive' => false]);

/** @psalm-suppress DocblockTypeContradiction */
self::assertTrue($this->service->called);
}
}
3 changes: 3 additions & 0 deletions tests/IO/TypedInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ final class TypedInputTest extends TestCase
{
private const ARGUMENT_NAME = 'arg';

/**
* @psalm-suppress ArgumentTypeCoercion
*/
#[DataProvider('choiceListArgumentProvider')]
public function test_it_get_the_argument_value_as_a_choice_list(
InputArgument $inputArgument,
Expand Down
2 changes: 1 addition & 1 deletion vendor-bin/psalm/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require-dev": {
"vimeo/psalm": "^4.7",
"vimeo/psalm": "^5.0",
"psalm/plugin-phpunit": ">=0.16",
"psalm/plugin-symfony": ">=3.1"
},
Expand Down
Loading

0 comments on commit d3d382b

Please sign in to comment.