Skip to content
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: 2 additions & 1 deletion UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ ActiveRecord style functionality.

## Strict Typing

Proper type hints have been added to all method signatures and strict types have been enabled.
Type declarations have been enabled for all parameters and strict types have been enabled.
Return type declarations will be added in the next major release.
40 changes: 20 additions & 20 deletions lib/Doctrine/Persistence/AbstractManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,35 @@ public function __construct(
*
* @param string $name The name of the service.
*
* @return object The instance of the given service.
* @return ObjectManager The instance of the given service.
*/
abstract protected function getService(string $name) : object;
abstract protected function getService(string $name);

/**
* Resets the given services.
*
* A service in this context is connection or a manager instance.
*
* @param string $name The name of the service.
*
* @return void
*/
abstract protected function resetService(string $name) : void;
abstract protected function resetService(string $name);

/**
* Gets the name of the registry.
*
* @return string
*/
public function getName() : string
public function getName()
{
return $this->name;
}

/**
* {@inheritdoc}
*/
public function getConnection(?string $name = null) : object
public function getConnection(?string $name = null)
{
if ($name === null) {
$name = $this->defaultConnection;
Expand All @@ -102,15 +106,15 @@ public function getConnection(?string $name = null) : object
/**
* {@inheritdoc}
*/
public function getConnectionNames() : array
public function getConnectionNames()
{
return $this->connections;
}

/**
* {@inheritdoc}
*/
public function getConnections() : array
public function getConnections()
{
$connections = [];
foreach ($this->connections as $name => $id) {
Expand All @@ -123,15 +127,15 @@ public function getConnections() : array
/**
* {@inheritdoc}
*/
public function getDefaultConnectionName() : string
public function getDefaultConnectionName()
{
return $this->defaultConnection;
}

/**
* {@inheritdoc}
*/
public function getDefaultManagerName() : string
public function getDefaultManagerName()
{
return $this->defaultManager;
}
Expand All @@ -141,7 +145,7 @@ public function getDefaultManagerName() : string
*
* @throws InvalidArgumentException
*/
public function getManager(?string $name = null) : ObjectManager
public function getManager(?string $name = null)
{
if ($name === null) {
$name = $this->defaultManager;
Expand All @@ -153,16 +157,13 @@ public function getManager(?string $name = null) : ObjectManager
);
}

/** @var ObjectManager $objectManager */
$objectManager = $this->getService($this->managers[$name]);

return $objectManager;
return $this->getService($this->managers[$name]);
}

/**
* {@inheritdoc}
*/
public function getManagerForClass(string $class) : ?ObjectManager
public function getManagerForClass(string $class)
{
// Check for namespace alias
if (strpos($class, ':') !== false) {
Expand All @@ -184,7 +185,6 @@ public function getManagerForClass(string $class) : ?ObjectManager
}

foreach ($this->managers as $id) {
/** @var ObjectManager $manager */
$manager = $this->getService($id);

if (! $manager->getMetadataFactory()->isTransient($class)) {
Expand All @@ -198,15 +198,15 @@ public function getManagerForClass(string $class) : ?ObjectManager
/**
* {@inheritdoc}
*/
public function getManagerNames() : array
public function getManagerNames()
{
return $this->managers;
}

/**
* {@inheritdoc}
*/
public function getManagers() : array
public function getManagers()
{
$managers = [];

Expand All @@ -226,7 +226,7 @@ public function getManagers() : array
public function getRepository(
string $persistentObjectName,
?string $persistentManagerName = null
) : ObjectRepository {
) {
return $this
->selectManager($persistentObjectName, $persistentManagerName)
->getRepository($persistentObjectName);
Expand All @@ -235,7 +235,7 @@ public function getRepository(
/**
* {@inheritdoc}
*/
public function resetManager(?string $name = null) : ObjectManager
public function resetManager(?string $name = null)
{
if ($name === null) {
$name = $this->defaultManager;
Expand Down
10 changes: 6 additions & 4 deletions lib/Doctrine/Persistence/ConnectionRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,28 @@ interface ConnectionRegistry
*
* @return string The default connection name.
*/
public function getDefaultConnectionName() : string;
public function getDefaultConnectionName();

/**
* Gets the named connection.
*
* @param string $name The connection name (null for the default one).
*
* @return object
*/
public function getConnection(?string $name = null) : object;
public function getConnection(?string $name = null);

/**
* Gets an array of all registered connections.
*
* @return array<string, object> An array of Connection instances.
*/
public function getConnections() : array;
public function getConnections();

/**
* Gets all connection names.
*
* @return array<string, string> An array of connection names.
*/
public function getConnectionNames() : array;
public function getConnectionNames();
}
12 changes: 9 additions & 3 deletions lib/Doctrine/Persistence/Event/LifecycleEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,30 @@ public function __construct(object $object, ObjectManager $objectManager)
* Retrieves the associated entity.
*
* @deprecated
*
* @return object
*/
public function getEntity() : object
public function getEntity()
{
return $this->object;
}

/**
* Retrieves the associated object.
*
* @return object
*/
public function getObject() : object
public function getObject()
{
return $this->object;
}

/**
* Retrieves the associated ObjectManager.
*
* @return ObjectManager
*/
public function getObjectManager() : ObjectManager
public function getObjectManager()
{
return $this->objectManager;
}
Expand Down
8 changes: 6 additions & 2 deletions lib/Doctrine/Persistence/Event/LoadClassMetadataEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ public function __construct(ClassMetadata $classMetadata, ObjectManager $objectM

/**
* Retrieves the associated ClassMetadata.
*
* @return ClassMetadata
*/
public function getClassMetadata() : ClassMetadata
public function getClassMetadata()
{
return $this->classMetadata;
}

/**
* Retrieves the associated ObjectManager.
*
* @return ObjectManager
*/
public function getObjectManager() : ObjectManager
public function getObjectManager()
{
return $this->objectManager;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/Persistence/Event/ManagerEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public function __construct(ObjectManager $objectManager)

/**
* Retrieves the associated ObjectManager.
*
* @return ObjectManager
*/
public function getObjectManager() : ObjectManager
public function getObjectManager()
{
return $this->objectManager;
}
Expand Down
12 changes: 9 additions & 3 deletions lib/Doctrine/Persistence/Event/OnClearEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,30 @@ public function __construct(ObjectManager $objectManager, ?string $entityClass =

/**
* Retrieves the associated ObjectManager.
*
* @return ObjectManager
*/
public function getObjectManager() : ObjectManager
public function getObjectManager()
{
return $this->objectManager;
}

/**
* Returns the name of the entity class that is cleared, or null if all are cleared.
*
* @return string|null
*/
public function getEntityClass() : ?string
public function getEntityClass()
{
return $this->entityClass;
}

/**
* Returns whether this event clears all entities.
*
* @return bool
*/
public function clearsAllEntities() : bool
public function clearsAllEntities()
{
return $this->entityClass === null;
}
Expand Down
14 changes: 10 additions & 4 deletions lib/Doctrine/Persistence/Event/PreUpdateEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ public function __construct(object $entity, ObjectManager $objectManager, array
*
* @return array<string, array<int, mixed>>
*/
public function getEntityChangeSet() : array
public function getEntityChangeSet()
{
return $this->entityChangeSet;
}

/**
* Checks if field has a changeset.
*
* @return bool
*/
public function hasChangedField(string $field) : bool
public function hasChangedField(string $field)
{
return isset($this->entityChangeSet[$field]);
}
Expand Down Expand Up @@ -73,8 +75,10 @@ public function getNewValue(string $field)
* Sets the new value of this field.
*
* @param mixed $value
*
* @return void
*/
public function setNewValue(string $field, $value) : void
public function setNewValue(string $field, $value)
{
$this->assertValidField($field);

Expand All @@ -84,9 +88,11 @@ public function setNewValue(string $field, $value) : void
/**
* Asserts the field exists in changeset.
*
* @return void
*
* @throws InvalidArgumentException
*/
private function assertValidField(string $field) : void
private function assertValidField(string $field)
{
if (! isset($this->entityChangeSet[$field])) {
throw new InvalidArgumentException(sprintf(
Expand Down
Loading