Skip to content

Commit

Permalink
Add native type to private properties and final classes (#2666)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored Jul 2, 2024
1 parent e716dbe commit e9f8083
Show file tree
Hide file tree
Showing 26 changed files with 86 additions and 171 deletions.
4 changes: 1 addition & 3 deletions lib/Doctrine/ODM/MongoDB/APM/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
final class Command
{
private CommandStartedEvent $startedEvent;

/** @var CommandSucceededEvent|CommandFailedEvent */
private $finishedEvent;
private CommandSucceededEvent|CommandFailedEvent $finishedEvent;

private function __construct()
{
Expand Down
4 changes: 1 addition & 3 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class Bucket extends AbstractBucket
{
/** @var mixed[] */
private array $boundaries;

/** @var mixed */
private $default;
private mixed $default = null;

/**
* An array of values based on the groupBy expression that specify the
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
*/
class Fill extends Stage
{
/** @var mixed|Expr|null */
private $partitionBy = null;
private mixed $partitionBy = null;

/** @var array<string> */
private array $partitionByFields = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Output extends Stage
private string $currentField = '';

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

public function __construct(Builder $builder, private Fill $fill)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GeoNear.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GeoNear extends MatchStage
private ?float $minDistance = null;

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

private ?int $num = null;

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GraphLookup extends Stage
private ?string $from;

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

private ?string $connectFromField = null;

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Lookup extends Stage
* @var Builder|array<array<string, mixed>>|null
* @psalm-var Builder|PipelineExpression|null
*/
private $pipeline = null;
private Builder|array|null $pipeline = null;

private bool $excludeLocalAndForeignField = false;

Expand Down
14 changes: 4 additions & 10 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,17 @@
*/
class Merge extends Stage
{
/**
* @var string|array
* @psalm-var OutputCollection
*/
private $into;
/** @psalm-var OutputCollection */
private string|array $into;

/** @var list<string> */
private array $on = [];

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

/**
* @var string|array|Builder|Stage
* @psalm-var WhenMatchedParamType
*/
private $whenMatched;
/** @psalm-var WhenMatchedParamType */
private string|array|Builder|Stage|null $whenMatched = null;

private ?string $whenNotMatched = null;

Expand Down
7 changes: 2 additions & 5 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Out.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
*/
class Out extends Stage
{
/**
* @var array|string
* @psalm-var OutputCollection
*/
private $out;
/** @psalm-var OutputCollection */
private array|string $out;

public function __construct(Builder $builder, string $collection, private DocumentManager $dm)
{
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Equals.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class Equals extends AbstractSearchOperator implements ScoredSearchOperator

private string $path = '';

/** @var mixed */
private $value;
private mixed $value;

/** @param string|int|float|ObjectId|UTCDateTime|null $value */
public function __construct(Search $search, string $path = '', $value = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class GeoShape extends AbstractSearchOperator implements ScoredSearchOperator
private array $path = [];
private string $relation = '';

/** @var LineString|Point|Polygon|MultiPolygon|array|null */
private $geometry = null;
private LineString|Point|Polygon|MultiPolygon|array|null $geometry = null;

/** @param LineString|Point|Polygon|MultiPolygon|array|null $geometry */
public function __construct(Search $search, $geometry = null, string $relation = '', string ...$path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class GeoWithin extends AbstractSearchOperator implements ScoredSearchOperator
private ?object $box = null;
private ?object $circle = null;

/** @var array|MultiPolygon|Polygon|null */
private $geometry = null;
private array|MultiPolygon|Polygon|null $geometry = null;

public function __construct(Search $search, string ...$path)
{
Expand Down
6 changes: 2 additions & 4 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Near.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ class Near extends AbstractSearchOperator implements ScoredSearchOperator
{
use ScoredSearchOperatorTrait;

/** @var int|float|UTCDateTime|array|Point|null */
private $origin;
private int|float|UTCDateTime|array|Point|null $origin;

/** @var int|float|null */
private $pivot;
private int|float|null $pivot;

/** @var list<string> */
private array $path;
Expand Down
12 changes: 4 additions & 8 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ class Range extends AbstractSearchOperator implements ScoredSearchOperator
{
use ScoredSearchOperatorTrait;

/** @var int|float|UTCDateTime|null */
private $gt = null;

/** @var int|float|UTCDateTime|null */
private $lt = null;

private bool $includeLowerBound = false;
private bool $includeUpperBound = false;
private int|float|UTCDateTime|null $gt = null;
private int|float|UTCDateTime|null $lt = null;
private bool $includeLowerBound = false;
private bool $includeUpperBound = false;

/** @var list<string> */
private array $path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
*/
class SetWindowFields extends Stage
{
/** @var mixed|Expr|null */
private $partitionBy = null;
private mixed $partitionBy = null;

/** @var array<string, int> */
private array $sortBy = [];
Expand Down
7 changes: 2 additions & 5 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/UnionWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
*/
class UnionWith extends Stage
{
/**
* @var array|Builder|null
* @psalm-var ?PipelineParamType
*/
private $pipeline = null;
/** @psalm-var ?PipelineParamType */
private array|Builder|Stage|null $pipeline = null;

public function __construct(Builder $builder, private DocumentManager $dm, private string $collection)
{
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ODM/MongoDB/Event/DocumentNotFoundEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ final class DocumentNotFoundEventArgs extends LifecycleEventArgs
{
private bool $disableException = false;

/** @param mixed $identifier */
public function __construct(object $document, DocumentManager $dm, private $identifier)
public function __construct(object $document, DocumentManager $dm, private mixed $identifier)
{
parent::__construct($document, $dm);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
final class HydratingIterator implements Iterator
{
/** @var Generator<mixed, array<string, mixed>>|null */
private $iterator;
private ?Generator $iterator;

/**
* @param Traversable<mixed, array<string, mixed>> $traversable
Expand Down
14 changes: 4 additions & 10 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,17 +539,14 @@
/**
* Allows users to specify a validation schema for the collection.
*
* @var array|object|null
* @psalm-var array<string, mixed>|object|null
*/
private $validator;
private array|object|null $validator = null;

/**
* Determines whether to error on invalid documents or just warn about the violations but allow invalid documents to be inserted.
*
* @var string
*/
private $validationAction = self::SCHEMA_VALIDATION_ACTION_ERROR;
private string $validationAction = self::SCHEMA_VALIDATION_ACTION_ERROR;

/**
* Determines how strictly MongoDB applies the validation rules to existing documents during an update.
Expand Down Expand Up @@ -813,11 +810,8 @@

private ReflectionService $reflectionService;

/**
* @var string|null
* @psalm-var class-string|null
*/
private $rootClass;
/** @var class-string|null */
private ?string $rootClass;

/**
* Initializes a new ClassMetadata instance that will hold the object-document mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,71 +41,61 @@ trait PersistentCollectionTrait
*
* @var array<TKey, T>
*/
private $snapshot = [];
private array $snapshot = [];

/**
* Collection's owning document
*
* @var object|null
*/
private $owner;
private ?object $owner = null;

/**
* @var array|null
* @var array<string, mixed>|null
* @psalm-var FieldMapping|null
*/
private $mapping;
private ?array $mapping = null;

/**
* Whether the collection is dirty and needs to be synchronized with the database
* when the UnitOfWork that manages its persistent state commits.
*
* @var bool
*/
private $isDirty = false;
private bool $isDirty = false;

/**
* Whether the collection has already been initialized.
*
* @var bool
*/
private $initialized = true;
private bool $initialized = true;

/**
* The wrapped Collection instance.
*
* @var BaseCollection<TKey, T>
*/
private $coll;
private BaseCollection $coll;

/**
* The DocumentManager that manages the persistence of the collection.
*
* @var DocumentManager|null
*/
private $dm;
private DocumentManager $dm;

/**
* The UnitOfWork that manages the persistence of the collection.
*
* @var UnitOfWork
*/
private $uow;
private UnitOfWork $uow;

/**
* The raw mongo data that will be used to initialize this collection.
*
* @var mixed[]
*/
private $mongoData = [];
private array $mongoData = [];

/**
* Any hints to account for during reconstitution/lookup of the documents.
*
* @var array
* @var array<int, mixed>
* @psalm-var Hints
*/
private $hints = [];
private array $hints = [];

public function setDocumentManager(DocumentManager $dm)
{
Expand Down Expand Up @@ -292,7 +282,7 @@ public function getMapping()

public function getTypeClass()
{
if ($this->dm === null) {
if (! isset($this->dm)) {
throw new MongoDBException('No DocumentManager is associated with this PersistentCollection, please set one using setDocumentManager method.');
}

Expand Down Expand Up @@ -653,7 +643,7 @@ private function doAdd($value, $arrayAccess)
$arrayAccess ? $this->coll->offsetSet(null, $value) : $this->coll->add($value);
$this->changed();

if ($this->uow !== null && $this->isOrphanRemovalEnabled() && $value !== null) {
if (isset($this->uow) && $this->isOrphanRemovalEnabled() && $value !== null) {
$this->uow->unscheduleOrphanRemoval($value);
}

Expand Down Expand Up @@ -702,7 +692,7 @@ private function doSet($offset, $value, bool $arrayAccess): void
$arrayAccess ? $this->coll->offsetSet($offset, $value) : $this->coll->set($offset, $value);

// Handle orphanRemoval
if ($this->uow !== null && $this->isOrphanRemovalEnabled() && $value !== null) {
if (isset($this->uow) && $this->isOrphanRemovalEnabled() && $value !== null) {
$this->uow->unscheduleOrphanRemoval($value);
}

Expand Down Expand Up @@ -733,7 +723,7 @@ private function isOrphanRemovalEnabled(): bool
*/
private function needsSchedulingForSynchronization(): bool
{
return $this->owner && $this->dm && ! empty($this->mapping['isOwningSide'])
return $this->owner && isset($this->dm) && ! empty($this->mapping['isOwningSide'])
&& $this->dm->getClassMetadata(get_class($this->owner))->isChangeTrackingNotify();
}

Expand Down
3 changes: 0 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
*/
final class StaticProxyFactory implements ProxyFactory
{
/** @var UnitOfWork The UnitOfWork this factory is bound to. */
private UnitOfWork $uow;

private LifecycleEventManager $lifecycleEventManager;

private LazyLoadingGhostFactory $proxyFactory;

public function __construct(DocumentManager $documentManager)
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ODM/MongoDB/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ class Builder
/**
* Array containing the query data.
*
* @var array
* @psalm-var QueryShape
*/
private $query = ['type' => Query::TYPE_FIND];
private array $query = ['type' => Query::TYPE_FIND];

/**
* The Expr instance used for building this query.
Expand Down
Loading

0 comments on commit e9f8083

Please sign in to comment.