Skip to content

Commit

Permalink
Added bleeding edge before update phpstan to version 2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Nov 14, 2024
1 parent e9db245 commit 527951a
Show file tree
Hide file tree
Showing 82 changed files with 320 additions and 148 deletions.
29 changes: 15 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ parameters:
checkUninitializedProperties: true

doctrine:
reportUnknownTypes: true
reportUnknownTypes: false
allowNullablePropertyForRequiredField: true
ormRepositoryClass: App\Repository\AbstractRepository

strictRules:
strictArrayFilter: false

ignoreErrors:
-
message: '#should be contravariant#'
Expand All @@ -33,3 +37,11 @@ parameters:
-
message: '#Call to static method .* will always evaluate to true.#'
path: tests/*
-
identifier: doctrine.columnType
paths:
- src/Entity/User.php
- src/Traits/TimestampableTrait.php

includes:
- vendor-bin/phpstan/vendor/phpstan/phpstan/conf/bleedingEdge.neon
5 changes: 5 additions & 0 deletions src/Command/AnonymousCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ private function createGenerator(): Generator
return $this->service->getGenerator();
}

/**
* @psalm-return Query
*
* @phpstan-return Query<null, mixed>
*/
private function createQuery(): Query
{
return $this->repository
Expand Down
9 changes: 7 additions & 2 deletions src/Command/UcFirstCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Symfony\Component\PropertyAccess\PropertyAccess;

/**
* Command to set a first character uppercase to fields.
* Command to set the first character uppercase to fields.
*
* @psalm-type EntityType = array{name: string, fields: non-empty-array<string>}
*/
Expand Down Expand Up @@ -253,7 +253,12 @@ private function getFieldName(SymfonyStyle $io): ?string
}

/**
* @psalm-return string[]
* @return string[]
*
* @phpstan-template T of object
*
* @phpstan-param ClassMetadata<T> $metadata
* phpstan-ignore missingType.generics
*/
private function getFields(ClassMetadata $metadata): array
{
Expand Down
1 change: 0 additions & 1 deletion src/Controller/AboutPhpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ private function getApacheVersion(Request $request): bool|string

private function getLoadedExtensions(): string
{
/** @psalm-var string[] $extensions */
$extensions = $this->getSorted(\array_map('strtolower', \get_loaded_extensions()));

return \implode(', ', $extensions);
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ protected function renderSpreadsheetDocument(
throw $this->createTranslatedNotFoundException('errors.render_document');
}
if (!StringUtils::isString($name) && StringUtils::isString($doc->getTitle())) {
/** @psalm-var string $name */
/** @psalm-var non-empty-string $name */
$name = $doc->getTitle();
}

Expand All @@ -439,7 +439,7 @@ protected function renderWordDocument(WordDocument $doc, bool $inline = true, st
throw $this->createTranslatedNotFoundException('errors.render_document');
}
if (!StringUtils::isString($name) && StringUtils::isString($doc->getTitle())) {
/** @psalm-var string $name */
/** @psalm-var non-empty-string $name */
$name = $doc->getTitle();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/AbstractEntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ protected function getDefaultRoute(): string
/**
* Gets the form type class name used to edit an entity.
*
* @psalm-return class-string<FormTypeInterface>
* @return class-string<FormTypeInterface<TEntity>>
*/
protected function getEditFormType(): string
{
/** @psalm-var class-string<FormTypeInterface> */
/** @psalm-var class-string<FormTypeInterface<TEntity>> */
return \sprintf('App\\Form\\%1$s\\%1$sType', $this->shortName);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Controller/CalculationArchiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public function invoke(Request $request, CalculationArchiveService $service): Re
}

/**
* @return FormInterface<mixed>
*
* @throws ORMException
*/
private function createQueryForm(CalculationArchiveService $service, CalculationArchiveQuery $query): FormInterface
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/CalculationUpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public function update(Request $request, CalculationUpdateService $service): Res
}

/**
* @return FormInterface<mixed>
*
* @throws \Exception
*/
private function createQueryForm(CalculationUpdateQuery $query): FormInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/CommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function execute(
}

/** @psalm-var CommandType $command */
$command = $service->getCommand($name);
$command = $service->getCommand($name); // @phpstan-ignore varTag.nativeType
$session = $request->getSession();
$key = $this->cleanKey('command.execute.' . $name);
$data = $this->getCommandData($session, $dataService, $key, $command);
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/GeneratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public function generateProducts(

/**
* @param array{entity: ?string, count: int, simulate: bool} $data
*
* @return FormInterface<mixed>
*/
private function createGenerateForm(array $data): FormInterface
{
Expand Down
1 change: 0 additions & 1 deletion src/Controller/OpenWeatherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ public function apiSearch(Request $request, OpenWeatherSearchService $service, U
return $this->jsonFalse();
}

/** @psalm-var array{id: int, latitude: float, longitude: float} $city */
foreach ($cities as $city) {
$parameters = [
self::KEY_UNITS => $units,
Expand Down
3 changes: 3 additions & 0 deletions src/Controller/ProductUpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public function invoke(Request $request, ProductUpdateService $service): Respons
]);
}

/**
* @return FormInterface<mixed>
*/
private function createQueryForm(ProductUpdateService $service, ProductUpdateQuery $query): FormInterface
{
$helper = $this->createFormHelper('product.update.', $query);
Expand Down
12 changes: 7 additions & 5 deletions src/Database/AbstractDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,15 @@ public function getFilename(): string

/**
* Gets the number of records for the given table.
*
* @return int<0, max>
*/
public function getRecordsCount(string $table): int
{
$query = "SELECT COUNT(1) FROM $table";
$result = $this->querySingle($query);

/** @psalm-var int<0, max> */
return \is_int($result) ? $result : 0;
}

Expand Down Expand Up @@ -255,7 +258,7 @@ abstract protected function createSchema(): void;
*
* @psalm-param int<1,3> $mode
*
* @psalm-return array<int, T>
* @psalm-return list<T>
*
* @phpstan-ignore method.templateTypeNotInParameter
*/
Expand All @@ -266,13 +269,14 @@ protected function executeAndFetch(\SQLite3Stmt $stmt, int $mode = \SQLITE3_ASSO
return [];
}

/** @psalm-var list<T> $rows */
$rows = [];
while ($row = $result->fetchArray($mode)) {
$rows[] = $row;
}
$result->finalize();

/** @psalm-var array<int, T> */
/** @psalm-var list<T> */
return $rows;
}

Expand Down Expand Up @@ -339,16 +343,14 @@ protected function likeValue(string $value): string
*/
protected function search(string $query, string $value, int $limit, int $mode = \SQLITE3_ASSOC): array
{
// parameter
$value = $this->likeValue($value);

// create statement
/** @var \SQLite3Stmt $stmt */
$stmt = $this->getStatement($query);
$stmt->bindValue(':value', $value);
$stmt->bindValue(':limit', $limit, \SQLITE3_INTEGER);

// execute
/** @psalm-var array<int, T> */
return $this->executeAndFetch($stmt, $mode);
}
}
3 changes: 3 additions & 0 deletions src/Database/OpenWeatherDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class OpenWeatherDatabase extends AbstractDatabase implements \Countable
LIMIT :limit
SQL;

/**
* @return int<0, max>
*/
public function count(): int
{
return $this->getRecordsCount('city');
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/CalculationCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function contains(CalculationItem $item): bool
}

/**
* @return int the number of items
* @return int<0, max> the number of items
*/
public function count(): int
{
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/CalculationGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function contains(CalculationCategory $category): bool
}

/**
* @return int the number of categories
* @return int<0, max> the number of categories
*/
public function count(): int
{
Expand Down
8 changes: 6 additions & 2 deletions src/Entity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ public function compare(ComparableInterface $other): int
}

/**
* @return int the number of items
* Gets the number of items.
*
* @return int<0, max>
*/
public function count(): int
{
Expand All @@ -126,11 +128,13 @@ public function count(): int
/**
* Gets the number of margins for all items.
*
* @return int<0, max>
*
* @psalm-suppress MixedArgumentTypeCoercion
*/
public function countMargins(): int
{
/** @psalm-var int */
/** @psalm-var int<0, max> */
return $this->items->reduce(fn (int $carry, TaskItem $item): int => $carry + $item->count(), 0);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Entity/TaskItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public function compare(ComparableInterface $other): int
}

/**
* @return int the number of margins
* Gets the number of margins.
*
* @return int<0, max>
*/
public function count(): int
{
Expand Down
4 changes: 4 additions & 0 deletions src/Form/AbstractHelperType.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ abstract protected function addFormFields(FormHelper $helper): void;

/**
* Creates the form helper.
*
* @psalm-param FormBuilderInterface $builder
*
* @phpstan-param FormBuilderInterface<mixed> $builder
*/
protected function createFormHelper(FormBuilderInterface $builder): FormHelper
{
Expand Down
2 changes: 2 additions & 0 deletions src/Form/Extension/FileTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public static function getExtendedTypes(): iterable
}

/**
* @param FormInterface<FileType> $form
*
* @psalm-param array<array-key, mixed> $options
*
* @psalm-return array<array-key, mixed>
Expand Down
6 changes: 6 additions & 0 deletions src/Form/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class FormHelper
* @param ?string $labelPrefix the label prefix.
* If the prefix is not null, the label is added automatically
* when the field property is set.
*
* @psalm-param FormBuilderInterface $builder
*
* @phpstan-param FormBuilderInterface<mixed> $builder
*/
public function __construct(private readonly FormBuilderInterface $builder, ?string $labelPrefix = null)
{
Expand Down Expand Up @@ -591,6 +595,8 @@ public function field(string $field): self

/**
* Gets the underlying form builder.
*
* @phpstan-return FormBuilderInterface<mixed>
*/
public function getBuilder(): FormBuilderInterface
{
Expand Down
Loading

0 comments on commit 527951a

Please sign in to comment.