Skip to content

Commit

Permalink
Convert @psalm-* annotations to generic or @phpstan-* annotation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored Oct 14, 2024
1 parent ff90e9a commit fe0f1ff
Show file tree
Hide file tree
Showing 91 changed files with 556 additions and 1,155 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ jobs:
if: "${{ matrix.symfony-version == '7' }}"
run: |
composer config minimum-stability dev
# not yet ready for v7
composer remove --no-update --dev vimeo/psalm
# update symfony deps
composer require --no-update symfony/console:^7@dev
composer require --no-update symfony/var-dumper:^7@dev
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,3 @@ jobs:

- name: "Run a static analysis with phpstan/phpstan"
run: "vendor/bin/phpstan analyse --error-format=github"

static-analysis-psalm:
name: "Static Analysis with Psalm"
runs-on: "ubuntu-22.04"

strategy:
matrix:
php-version:
- "8.2"

steps:
- name: "Checkout code"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
extensions: "mongodb"
php-version: "${{ matrix.php-version }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v3"

- name: "Upload composer.lock as build artifact"
uses: actions/upload-artifact@v4
with:
name: "composer-lock-static-analysis-psalm"
path: composer.lock
overwrite: true

- name: "Run a static analysis with vimeo/psalm"
run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc)"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ vendor/
.phpunit.cache
.phpunit.result.cache
phpcs.xml
psalm.xml
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^10.4",
"squizlabs/php_codesniffer": "^3.5",
"symfony/cache": "^5.4 || ^6.0 || ^7.0",
"vimeo/psalm": "~5.24.0"
"symfony/cache": "^5.4 || ^6.0 || ^7.0"
},
"conflict": {
"doctrine/annotations": "<1.12 || >=3.0"
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
use function array_merge;
use function assert;

/** @psalm-import-type PipelineExpression from Builder */
/** @phpstan-import-type PipelineExpression from Builder */
final class Aggregation implements IteratorAggregate
{
/**
* @param array<string, mixed> $pipeline
* @param array<string, mixed> $options
* @psalm-param PipelineExpression $pipeline
* @phpstan-param PipelineExpression $pipeline
*/
public function __construct(private DocumentManager $dm, private ?ClassMetadata $classMetadata, private Collection $collection, private array $pipeline, private array $options = [], private bool $rewindable = true)
{
Expand Down
18 changes: 9 additions & 9 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
/**
* Fluent interface for building aggregation pipelines.
*
* @psalm-import-type SortShape from Sort
* @psalm-import-type StageExpression from Stage
* @psalm-type PipelineExpression = list<StageExpression>
* @phpstan-import-type SortShape from Sort
* @phpstan-type StageExpression array<string, mixed>
* @phpstan-type PipelineExpression list<StageExpression>
*/
class Builder
{
Expand All @@ -44,7 +44,7 @@ class Builder
*/
private ClassMetadata $class;

/** @psalm-var class-string */
/** @var class-string */
private ?string $hydrationClass = null;

/**
Expand All @@ -60,7 +60,7 @@ class Builder
/**
* Create a new aggregation builder.
*
* @psalm-param class-string $documentName
* @param class-string $documentName
*/
public function __construct(DocumentManager $dm, string $documentName)
{
Expand Down Expand Up @@ -270,8 +270,8 @@ public function getAggregation(array $options = []): Aggregation
* you should not apply filters as this may cause wrong results to be
* given.
*
* @return array<array<string, mixed>>
* @psalm-return PipelineExpression
* @return list<array<string, mixed>>
* @phpstan-return PipelineExpression
*/
// phpcs:enable Squiz.Commenting.FunctionComment.ExtraParamComment
public function getPipeline(/* bool $applyFilters = true */): array
Expand Down Expand Up @@ -609,7 +609,7 @@ public function skip(int $skip): Stage\Skip
*
* @param array<string, int|string|array<string, string>>|string $fieldName Field name or array of field/order pairs
* @param int|string|null $order Field order (if one field is specified)
* @psalm-param SortShape|string $fieldName Field name or array of field/order pairs
* @phpstan-param SortShape|string $fieldName Field name or array of field/order pairs
*/
public function sort($fieldName, $order = null): Stage\Sort
{
Expand Down Expand Up @@ -699,7 +699,7 @@ public function addStage(Stage $stage): Stage
*/
private function applyFilters(array $query): array
{
$documentPersister = $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
$documentPersister = $this->getDocumentPersister();

$query = $documentPersister->addDiscriminatorToPreparedQuery($query);
$query = $documentPersister->addFilterToPreparedQuery($query);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
/**
* Fluent interface for building aggregation pipelines.
*
* @psalm-type OperatorExpression = array<string, mixed>|object
* @phpstan-type OperatorExpression array<string, mixed>|object
*/
class Expr implements
AccumulatorOperators,
Expand Down
10 changes: 5 additions & 5 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*
* @internal
*
* @psalm-import-type PipelineExpression from Builder
* @psalm-type StageExpression = array<non-empty-string, mixed>
* @phpstan-import-type PipelineExpression from Builder
* @phpstan-import-type StageExpression from Builder
*/
abstract class Stage
{
Expand All @@ -31,7 +31,7 @@ public function __construct(Builder $builder)
* Assembles the aggregation stage
*
* @return array<string, mixed>
* @psalm-return StageExpression
* @phpstan-return StageExpression
*/
abstract public function getExpression(): array;

Expand Down Expand Up @@ -189,8 +189,8 @@ public function geoNear($x, $y = null): Stage\GeoNear
/**
* Returns the assembled aggregation pipeline
*
* @return array<array<string, mixed>>
* @psalm-return PipelineExpression
* @return list<array<string, mixed>>
* @phpstan-return PipelineExpression
*/
public function getPipeline(): array
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/AddFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
/**
* Fluent interface for adding a $addFields stage to an aggregation pipeline.
*
* @psalm-import-type OperatorExpression from Expr
* @psalm-type AddFieldsStageExpression = array{'$addFields': array<string, OperatorExpression|mixed>}
* @phpstan-import-type OperatorExpression from Expr
* @phpstan-type AddFieldsStageExpression array{'$addFields': array<string, OperatorExpression|mixed>}
*/
final class AddFields extends Operator
{
Expand Down
1 change: 0 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public function output(): Bucket\BucketOutput
/** @return array{boundaries: mixed[], default: mixed} */
protected function getExtraPipelineFields(): array
{
/** @psalm-suppress RedundantPropertyInitializationCheck because the property might not be set yet */
$fields = ['boundaries' => $this->boundaries ?? null];
if ($this->default !== null) {
$fields['default'] = $this->default;
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/CollStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Fluent interface for adding a $collStats stage to an aggregation pipeline.
*
* @psalm-type CollStatsStageExpression = array{
* @phpstan-type CollStatsStageExpression array{
* '$collStats': array{
* latencyStats?: array{histograms?: bool},
* storageStats?: array{},
Expand Down Expand Up @@ -52,7 +52,7 @@ public function showStorageStats(): static
return $this;
}

/** @psalm-return CollStatsStageExpression */
/** @phpstan-return CollStatsStageExpression */
public function getExpression(): array
{
$collStats = [];
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Fluent interface for adding a $count stage to an aggregation pipeline.
*
* @psalm-type CountStageExpression = array{'$count': string}
* @phpstan-type CountStageExpression array{'$count': string}
*/
class Count extends Stage
{
Expand All @@ -19,7 +19,7 @@ public function __construct(Builder $builder, private string $fieldName)
parent::__construct($builder);
}

/** @psalm-return CountStageExpression */
/** @phpstan-return CountStageExpression */
public function getExpression(): array
{
return [
Expand Down
12 changes: 6 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Densify.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
/**
* Fluent interface for adding a $densify stage to an aggregation pipeline.
*
* @psalm-type BoundsType = 'full'|'partition'|array{0: int|float|UTCDateTime, 1: int|float|UTCDateTime}
* @psalm-type UnitType = 'year'|'month'|'week'|'day'|'hour'|'minute'|'second'|'millisecond'
* @psalm-type DensifyStageExpression = array{
* @phpstan-type BoundsType 'full'|'partition'|array{0: int|float|UTCDateTime, 1: int|float|UTCDateTime}
* @phpstan-type UnitType 'year'|'month'|'week'|'day'|'hour'|'minute'|'second'|'millisecond'
* @phpstan-type DensifyStageExpression array{
* '$densify': object{
* field: string,
* partitionByFields?: list<string>,
Expand Down Expand Up @@ -54,8 +54,8 @@ public function partitionByFields(string ...$fields): static
/**
* @param array|string $bounds
* @param int|float $step
* @psalm-param BoundsType $bounds
* @psalm-param ''|UnitType $unit
* @phpstan-param BoundsType $bounds
* @phpstan-param ''|UnitType $unit
*/
public function range($bounds, $step, string $unit = ''): static
{
Expand All @@ -71,7 +71,7 @@ public function range($bounds, $step, string $unit = ''): static
return $this;
}

/** @psalm-return DensifyStageExpression */
/** @phpstan-return DensifyStageExpression */
public function getExpression(): array
{
$params = (object) [
Expand Down
5 changes: 2 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Facet.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
/**
* Fluent interface for adding a $facet stage to an aggregation pipeline.
*
* @psalm-import-type PipelineExpression from Builder
* @psalm-type FacetStageExpression = array{'$facet': array<string, PipelineExpression>}
* @phpstan-import-type PipelineExpression from Builder
* @phpstan-type FacetStageExpression array{'$facet': array<string, PipelineExpression>}
*/
class Facet extends Stage
{
Expand Down Expand Up @@ -48,7 +48,6 @@ public function field(string $field): static
*/
public function pipeline($builder): static
{
/** @psalm-suppress RedundantPropertyInitializationCheck because the property might not be set yet */
if (! isset($this->field)) {
throw new LogicException(__METHOD__ . ' requires setting a current field using field().');
}
Expand Down
14 changes: 7 additions & 7 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
/**
* Fluent interface for adding a $fill stage to an aggregation pipeline.
*
* @psalm-import-type SortDirectionKeywords from Sort
* @psalm-import-type OperatorExpression from Expr
* @psalm-type SortDirection = int|SortDirectionKeywords
* @psalm-type SortShape = array<string, SortDirection>
* @psalm-type FillStageExpression = array{
* @phpstan-import-type SortDirectionKeywords from Sort
* @phpstan-import-type OperatorExpression from Expr
* @phpstan-type SortDirection int|SortDirectionKeywords
* @phpstan-type SortShape array<string, SortDirection>
* @phpstan-type FillStageExpression array{
* '$fill': array{
* partitionBy?: string|OperatorExpression,
* partitionByFields?: list<string>,
Expand Down Expand Up @@ -67,8 +67,8 @@ public function partitionByFields(string ...$fields): static
/**
* @param array<string, int|string>|string $fieldName Field name or array of field/order pairs
* @param int|string $order Field order (if one field is specified)
* @psalm-param SortShape|string $fieldName
* @psalm-param SortDirection|null $order
* @phpstan-param SortShape|string $fieldName
* @phpstan-param SortDirection|null $order
*/
public function sortBy($fieldName, $order = null): static
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Fluent builder for output param of $fill stage
*
* @psalm-import-type SortShape from Fill
* @phpstan-import-type SortShape from Fill
*/
class Output extends Stage
{
Expand Down Expand Up @@ -44,7 +44,7 @@ public function partitionByFields(string ...$fields): Fill
/**
* @param array<string, int|string>|string $fieldName Field name or array of field/order pairs
* @param int|string $order Field order (if one field is specified)
* @psalm-param SortShape|string $fieldName
* @phpstan-param SortShape|string $fieldName
*/
public function sortBy($fieldName, $order = null): Fill
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use function is_string;
use function substr;

/** @psalm-import-type FieldMapping from ClassMetadata */
/** @phpstan-import-type FieldMapping from ClassMetadata */
class GraphLookup extends Stage
{
private ?string $from;
Expand Down Expand Up @@ -130,7 +130,7 @@ public function depthField(string $depthField): static
* Target collection for the $graphLookup operation to search, recursively
* matching the connectFromField to the connectToField.
*
* @psalm-param class-string|string $from
* @param class-string|string $from
*/
public function from(string $from): static
{
Expand Down Expand Up @@ -281,7 +281,7 @@ private function getDocumentPersister(ClassMetadata $class): DocumentPersister
return $this->dm->getUnitOfWork()->getDocumentPersister($class->name);
}

/** @psalm-param FieldMapping $mapping */
/** @phpstan-param FieldMapping $mapping */
private function getReferencedFieldName(string $fieldName, array $mapping): string
{
if (! $this->targetClass) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Fluent interface for adding a $group stage to an aggregation pipeline.
*
* @psalm-type GroupStageExpression = array{'$group': array<string, mixed>}
* @phpstan-type GroupStageExpression array{'$group': array<string, mixed>}
*/
class Group extends Operator implements GroupAccumulatorOperators
{
Expand All @@ -28,7 +28,7 @@ public function __construct(Builder $builder)
$this->expr = $builder->expr();
}

/** @psalm-return GroupStageExpression */
/** @phpstan-return GroupStageExpression */
public function getExpression(): array
{
return [
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/IndexStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
/**
* Fluent interface for adding a $indexStats stage to an aggregation pipeline.
*
* @psalm-type IndexStatsStageExpression = array{'$indexStats': object}
* @phpstan-type IndexStatsStageExpression array{'$indexStats': object}
*/
class IndexStats extends Stage
{
/** @psalm-return IndexStatsStageExpression */
/** @phpstan-return IndexStatsStageExpression */
public function getExpression(): array
{
return [
Expand Down
Loading

0 comments on commit fe0f1ff

Please sign in to comment.