Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use typed properties #2473

Merged
merged 5 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/Doctrine/ODM/MongoDB/APM/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

final class Command
{
/** @var CommandStartedEvent */
private $startedEvent;
private CommandStartedEvent $startedEvent;

/** @var CommandSucceededEvent|CommandFailedEvent */
private $finishedEvent;
Expand Down
7 changes: 3 additions & 4 deletions lib/Doctrine/ODM/MongoDB/APM/CommandLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
final class CommandLogger implements Countable, CommandLoggerInterface
{
/** @var Command[] */
private $commands = [];
private array $commands = [];

/** @var CommandStartedEvent[] */
private $startedCommands = [];
private array $startedCommands = [];

/** @var bool */
private $registered = false;
private bool $registered = false;

public function register(): void
{
Expand Down
16 changes: 6 additions & 10 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,19 @@

final class Aggregation implements IteratorAggregate
{
/** @var DocumentManager */
private $dm;
private DocumentManager $dm;

/** @var ClassMetadata|null */
private $classMetadata;
private ?ClassMetadata $classMetadata;

/** @var Collection */
private $collection;
private Collection $collection;

/** @var array<string, mixed> */
private $pipeline;
private array $pipeline;

/** @var array<string, mixed> */
private $options;
private array $options;

/** @var bool */
private $rewindable;
private bool $rewindable;

/**
* @param array<string, mixed> $pipeline
Expand Down
24 changes: 7 additions & 17 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,26 @@ class Builder
{
/**
* The DocumentManager instance for this query
*
* @var DocumentManager
*/
private $dm;
private DocumentManager $dm;

/**
* The ClassMetadata instance.
*
* @var ClassMetadata
*/
private $class;
private ClassMetadata $class;

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

/**
* The Collection instance.
*
* @var Collection
*/
private $collection;
private Collection $collection;

/** @var Stage[] */
private $stages = [];
private array $stages = [];

/** @var bool */
private $rewindable = true;
private bool $rewindable = true;

/**
* Create a new aggregation builder.
Expand Down
14 changes: 5 additions & 9 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,20 @@
*/
class Expr
{
/** @var DocumentManager */
private $dm;
private DocumentManager $dm;

/** @var ClassMetadata */
private $class;
private ClassMetadata $class;

/** @var array<string, mixed> */
private $expr = [];
private array $expr = [];

/**
* The current field we are operating on.
*
* @var string
*/
private $currentField;
private ?string $currentField = null;

/** @var array{case: mixed|self, then?: mixed|self}|null */
private $switchBranch;
private ?array $switchBranch = null;

public function __construct(DocumentManager $dm, ClassMetadataInterface $class)
{
Expand Down
6 changes: 2 additions & 4 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/AbstractBucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
*/
abstract class AbstractBucket extends Stage
{
/** @var DocumentManager */
private $dm;
private DocumentManager $dm;

/** @var ClassMetadata */
private $class;
private ClassMetadata $class;

/** @var Bucket\AbstractOutput|null */
protected $output;
Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Bucket extends AbstractBucket
{
/** @var mixed[] */
private $boundaries;
private array $boundaries;

/** @var mixed */
private $default;
Expand Down Expand Up @@ -70,7 +70,8 @@ public function output(): Bucket\BucketOutput
*/
protected function getExtraPipelineFields(): array
{
$fields = ['boundaries' => $this->boundaries];
/** @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
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ abstract class AbstractOutput extends Stage
/** @var Stage\AbstractBucket */
protected $bucket;

/** @var Expr */
private $expr;
private Expr $expr;

public function __construct(Builder $builder, Stage\AbstractBucket $bucket)
{
Expand Down
6 changes: 2 additions & 4 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/BucketAuto.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
*/
class BucketAuto extends AbstractBucket
{
/** @var int */
private $buckets;
private ?int $buckets = null;

/** @var string|null */
private $granularity;
private ?string $granularity = null;

/**
* A positive 32-bit integer that specifies the number of buckets into which
Expand Down
6 changes: 2 additions & 4 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/CollStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ class CollStats extends Stage
public const LATENCY_STATS_SIMPLE = 1;
public const LATENCY_STATS_HISTOGRAMS = 2;

/** @var int */
private $latencyStats = self::LATENCY_STATS_NONE;
private int $latencyStats = self::LATENCY_STATS_NONE;

/** @var bool */
private $storageStats = false;
private bool $storageStats = false;

public function __construct(Builder $builder)
{
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
*/
class Count extends Stage
{
/** @var string */
private $fieldName;
private string $fieldName;

public function __construct(Builder $builder, string $fieldName)
{
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Facet.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
class Facet extends Stage
{
/** @var Builder[] */
private $pipelines = [];
private array $pipelines = [];

/** @var string */
private $field;
private string $field;

public function getExpression(): array
{
Expand All @@ -46,7 +45,8 @@ public function field(string $field): self
*/
public function pipeline($builder): self
{
if (! $this->field) {
/** @psalm-suppress RedundantPropertyInitializationCheck because the property might not be set yet */
if (! isset($this->field)) {
throw new LogicException(__METHOD__ . ' requires you set a current field using field().');
}

Expand Down
24 changes: 8 additions & 16 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GeoNear.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,24 @@
*/
class GeoNear extends MatchStage
{
/** @var string */
private $distanceField;
private ?string $distanceField = null;

/** @var float */
private $distanceMultiplier;
private ?float $distanceMultiplier = null;

/** @var string */
private $includeLocs;
private ?string $includeLocs = null;

/** @var float */
private $maxDistance;
private ?float $maxDistance = null;

/** @var float */
private $minDistance;
private ?float $minDistance = null;

/** @var array<string, mixed>|array{int|float, int|float} */
private $near;

/** @var int */
private $num;
private ?int $num = null;

/** @var bool */
private $spherical = false;
private bool $spherical = false;

/** @var bool */
private $uniqueDocs;
private ?bool $uniqueDocs = null;

/**
* @param float|array<string, mixed>|Point $x
Expand Down
30 changes: 10 additions & 20 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,28 @@
*/
class GraphLookup extends Stage
{
/** @var string|null */
private $from;
private ?string $from;

/** @var string|Expr|mixed[]|null */
private $startWith;

/** @var string|null */
private $connectFromField;
private ?string $connectFromField = null;

/** @var string|null */
private $connectToField;
private ?string $connectToField = null;

/** @var string|null */
private $as;
private ?string $as = null;

/** @var int|null */
private $maxDepth;
private ?int $maxDepth = null;

/** @var string|null */
private $depthField;
private ?string $depthField = null;

/** @var Stage\GraphLookup\MatchStage */
private $restrictSearchWithMatch;
private Stage\GraphLookup\MatchStage $restrictSearchWithMatch;

/** @var DocumentManager */
private $dm;
private DocumentManager $dm;

/** @var ClassMetadata */
private $class;
private ClassMetadata $class;

/** @var ClassMetadata|null */
private $targetClass;
private ?ClassMetadata $targetClass = null;

/**
* @param string $from Target collection for the $graphLookup operation to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

class MatchStage extends BaseMatchStage
{
/** @var GraphLookup */
private $graphLookup;
private GraphLookup $graphLookup;

public function __construct(Builder $builder, GraphLookup $graphLookup)
{
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
*/
class Limit extends Stage
{
/** @var int */
private $limit;
private int $limit;

public function __construct(Builder $builder, int $limit)
{
Expand Down
30 changes: 10 additions & 20 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,25 @@
*/
class Lookup extends Stage
{
/** @var DocumentManager */
private $dm;
private DocumentManager $dm;

/** @var ClassMetadata */
private $class;
private ClassMetadata $class;

/** @var ClassMetadata */
private $targetClass;
private ?ClassMetadata $targetClass = null;

/** @var string */
private $from;
private string $from;

/** @var string */
private $localField;
private ?string $localField = null;

/** @var string */
private $foreignField;
private ?string $foreignField = null;

/** @var string */
private $as;
private ?string $as = null;
IonBazan marked this conversation as resolved.
Show resolved Hide resolved

/** @var array */
private $let;
private ?array $let = null;

/** @var array */
private $pipeline;
private ?array $pipeline = null;

/** @var bool */
private $excludeLocalAndForeignField = false;
private bool $excludeLocalAndForeignField = false;

public function __construct(Builder $builder, string $from, DocumentManager $documentManager, ClassMetadata $class)
{
Expand Down
Loading