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
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ includes:

parameters:
level: 7
checkMissingOverrideMethodAttribute: true
phpVersion: 80400

paths:
Expand Down
16 changes: 14 additions & 2 deletions src/AbstractManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Persistence;

use InvalidArgumentException;
use Override;
use ReflectionClass;

use function assert;
Expand All @@ -22,8 +23,8 @@ abstract class AbstractManagerRegistry implements ManagerRegistry
*/
public function __construct(
private readonly string $name,
private array $connections,
private array $managers,
private readonly array $connections,
private readonly array $managers,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my first commit message:

It is no longer clear to me why I did not make the
AbstractManagerRegistry::$connections and
AbstractManagerRegistry::$managers readonly already in
greg0ire@59029af.

If you can imagine a reason why I didn't, let me know. If not, then I guess the best way to find out will be to just do it.

private readonly string $defaultConnection,
private readonly string $defaultManager,
private readonly string|null $proxyInterfaceName = null,
Expand Down Expand Up @@ -56,6 +57,7 @@ public function getName(): string
return $this->name;
}

#[Override]
public function getConnection(string|null $name = null): object
{
if ($name === null) {
Expand All @@ -74,6 +76,7 @@ public function getConnection(string|null $name = null): object
/**
* {@inheritDoc}
*/
#[Override]
public function getConnectionNames(): array
{
return $this->connections;
Expand All @@ -82,6 +85,7 @@ public function getConnectionNames(): array
/**
* {@inheritDoc}
*/
#[Override]
public function getConnections(): array
{
$connections = [];
Expand All @@ -92,11 +96,13 @@ public function getConnections(): array
return $connections;
}

#[Override]
public function getDefaultConnectionName(): string
{
return $this->defaultConnection;
}

#[Override]
public function getDefaultManagerName(): string
{
return $this->defaultManager;
Expand All @@ -107,6 +113,7 @@ public function getDefaultManagerName(): string
*
* @throws InvalidArgumentException
*/
#[Override]
public function getManager(string|null $name = null): ObjectManager
{
if ($name === null) {
Expand All @@ -125,6 +132,7 @@ public function getManager(string|null $name = null): ObjectManager
return $service;
}

#[Override]
public function getManagerForClass(string $class): ObjectManager|null
{
$proxyClass = new ReflectionClass($class);
Expand Down Expand Up @@ -157,6 +165,7 @@ public function getManagerForClass(string $class): ObjectManager|null
/**
* {@inheritDoc}
*/
#[Override]
public function getManagerNames(): array
{
return $this->managers;
Expand All @@ -165,6 +174,7 @@ public function getManagerNames(): array
/**
* {@inheritDoc}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be removed. The inline phpdoc tag is only about inheriting the long description (which is only useful when wanting to include it inside the long description define of the child, thing about it as the parent:: call for the phpdoc long description).
The current usage is likely a confusion with the block-level tag @inheritDoc that is meant to say "this method is overriding the parent one which already defines everything so don't complain about missing phpdoc". And the #[Override] already provides that intent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof should we wait on slevomat/coding-standard#1824 before attempting to address this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR slevomat/coding-standard#1828 @greg0ire. We can remove the phpdoc in all the doctrine projects in an other PR.

*/
#[Override]
public function getManagers(): array
{
$managers = [];
Expand All @@ -178,6 +188,7 @@ public function getManagers(): array
return $managers;
}

#[Override]
public function getRepository(
string $persistentObject,
string|null $persistentManagerName = null,
Expand All @@ -187,6 +198,7 @@ public function getRepository(
->getRepository($persistentObject);
}

#[Override]
public function resetManager(string|null $name = null): ObjectManager
{
if ($name === null) {
Expand Down
7 changes: 7 additions & 0 deletions src/Mapping/AbstractClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Proxy;
use Override;
use Psr\Cache\CacheItemPoolInterface;
use ReflectionClass;
use ReflectionException;
Expand Down Expand Up @@ -76,6 +77,7 @@ public function getLoadedMetadata(): array
/**
* {@inheritDoc}
*/
#[Override]
public function getAllMetadata(): array
{
if (! $this->initialized) {
Expand Down Expand Up @@ -153,6 +155,7 @@ private function normalizeClassName(string $className): string
* @throws ReflectionException
* @throws MappingException
*/
#[Override]
public function getMetadataFor(string $className): ClassMetadata
{
$className = $this->normalizeClassName($className);
Expand Down Expand Up @@ -223,6 +226,7 @@ public function getMetadataFor(string $className): ClassMetadata
return $this->loadedMetadata[$className];
}

#[Override]
public function hasMetadataFor(string $className): bool
{
$className = $this->normalizeClassName($className);
Expand All @@ -238,6 +242,7 @@ public function hasMetadataFor(string $className): bool
* @phpstan-param class-string $className
* @phpstan-param CMTemplate $class
*/
#[Override]
public function setMetadataFor(string $className, ClassMetadata $class): void
{
$this->loadedMetadata[$this->normalizeClassName($className)] = $class;
Expand Down Expand Up @@ -375,6 +380,7 @@ abstract protected function doLoadMetadata(
*/
abstract protected function newClassMetadataInstance(string $className): ClassMetadata;

#[Override]
public function isTransient(string $className): bool
{
if (! $this->initialized) {
Expand Down Expand Up @@ -444,6 +450,7 @@ private function createDefaultProxyClassNameResolver(): void
*
* @template T of object
*/
#[Override]
public function resolveClassName(string $className): string
{
$pos = strrpos($className, '\\' . Proxy::MARKER . '\\');
Expand Down
5 changes: 4 additions & 1 deletion src/Mapping/Driver/ClassNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace Doctrine\Persistence\Mapping\Driver;

use Override;

/**
* Basic implementation of ClassLocator that passes a list of class names.
*/
final class ClassNames implements ClassLocator
final readonly class ClassNames implements ClassLocator
{
/** @param list<class-string> $classNames */
public function __construct(
Expand All @@ -16,6 +18,7 @@ public function __construct(
}

/** @return list<class-string> */
#[Override]
public function getClassNames(): array
{
return $this->classNames;
Expand Down
19 changes: 11 additions & 8 deletions src/Mapping/Driver/DefaultFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Persistence\Mapping\Driver;

use Doctrine\Persistence\Mapping\MappingException;
use Override;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

Expand All @@ -22,8 +23,6 @@
*
* This behavior is independent of the actual content of the file. It just detects
* the file which is responsible for the given class name.
*
* @final since 4.2
*/
final class DefaultFileLocator implements FileLocator
{
Expand All @@ -32,10 +31,7 @@ final class DefaultFileLocator implements FileLocator
*
* @var array<int, string>
*/
protected array $paths = [];

/** The file extension of mapping documents. */
protected string|null $fileExtension;
private array $paths = [];

/**
* Initializes a new FileDriver that looks in the given path(s) for mapping
Expand All @@ -46,8 +42,10 @@ final class DefaultFileLocator implements FileLocator
* @param string|null $fileExtension The file extension of mapping documents,
* usually prefixed with a dot.
*/
public function __construct(string|array $paths, string|null $fileExtension = null)
{
public function __construct(
string|array $paths,
private string|null $fileExtension = null,
) {
$this->addPaths((array) $paths);
$this->fileExtension = $fileExtension;
}
Expand All @@ -67,12 +65,14 @@ public function addPaths(array $paths): void
*
* @return array<int, string>
*/
#[Override]
public function getPaths(): array
{
return $this->paths;
}

/** Gets the file extension used to look for mapping files under. */
#[Override]
public function getFileExtension(): string|null
{
return $this->fileExtension;
Expand All @@ -88,6 +88,7 @@ public function setFileExtension(string|null $fileExtension): void
$this->fileExtension = $fileExtension;
}

#[Override]
public function findMappingFile(string $className): string
{
$fileName = str_replace('\\', '.', $className) . $this->fileExtension;
Expand All @@ -105,6 +106,7 @@ public function findMappingFile(string $className): string
/**
* {@inheritDoc}
*/
#[Override]
public function getAllClassNames(string $globalBasename): array
{
if ($this->paths === []) {
Expand Down Expand Up @@ -142,6 +144,7 @@ public function getAllClassNames(string $globalBasename): array
return $classes;
}

#[Override]
public function fileExists(string $className): bool
{
$fileName = str_replace('\\', '.', $className) . $this->fileExtension;
Expand Down
4 changes: 3 additions & 1 deletion src/Mapping/Driver/FileClassLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use FilesystemIterator;
use InvalidArgumentException;
use Iterator;
use Override;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ReflectionClass;
Expand All @@ -34,7 +35,7 @@
*
* It is compatible with the Symfony Finder component, but does not require it.
*/
final class FileClassLocator implements ClassLocator
final readonly class FileClassLocator implements ClassLocator
{
/** @param iterable<SplFileInfo> $files An iterable of files to include. */
public function __construct(
Expand All @@ -43,6 +44,7 @@ public function __construct(
}

/** @return list<class-string> */
#[Override]
public function getClassNames(): array
{
$includedFiles = [];
Expand Down
3 changes: 3 additions & 0 deletions src/Mapping/Driver/FileDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Persistence\Mapping\Driver;

use Doctrine\Persistence\Mapping\MappingException;
use Override;

use function array_keys;
use function array_unique;
Expand Down Expand Up @@ -95,6 +96,7 @@ public function getElement(string $className): mixed
return $result[$className];
}

#[Override]
public function isTransient(string $className): bool
{
if ($this->classCache === null) {
Expand All @@ -111,6 +113,7 @@ public function isTransient(string $className): bool
/**
* {@inheritDoc}
*/
#[Override]
public function getAllClassNames(): array
{
if ($this->classCache === null) {
Expand Down
6 changes: 4 additions & 2 deletions src/Mapping/Driver/MappingDriverChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\MappingException;
use Override;

use function array_keys;
use function spl_object_id;
Expand All @@ -14,8 +15,6 @@
/**
* The DriverChain allows you to add multiple other mapping drivers for
* certain namespaces.
*
* @final since 4.2
*/
final class MappingDriverChain implements MappingDriver
{
Expand Down Expand Up @@ -55,6 +54,7 @@ public function getDrivers(): array
return $this->drivers;
}

#[Override]
public function loadMetadataForClass(string $className, ClassMetadata $metadata): void
{
foreach ($this->drivers as $namespace => $driver) {
Expand All @@ -77,6 +77,7 @@ public function loadMetadataForClass(string $className, ClassMetadata $metadata)
/**
* {@inheritDoc}
*/
#[Override]
public function getAllClassNames(): array
{
$classNames = [];
Expand Down Expand Up @@ -107,6 +108,7 @@ public function getAllClassNames(): array
return array_keys($classNames);
}

#[Override]
public function isTransient(string $className): bool
{
foreach ($this->drivers as $namespace => $driver) {
Expand Down
4 changes: 3 additions & 1 deletion src/Mapping/Driver/PHPDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use Closure;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\MappingException;
use Override;

/**
* The PHPDriver includes php files which just populate ClassMetadataInfo
* instances with plain PHP code.
*
* @template-extends FileDriver<ClassMetadata<object>>
* @final since 4.2
*/
final class PHPDriver extends FileDriver
{
Expand All @@ -26,6 +26,7 @@ public function __construct(string|array|FileLocator $locator)
parent::__construct($locator, '.php');
}

#[Override]
public function loadMetadataForClass(string $className, ClassMetadata $metadata): void
{
$this->metadata = $metadata;
Expand All @@ -36,6 +37,7 @@ public function loadMetadataForClass(string $className, ClassMetadata $metadata)
/**
* {@inheritDoc}
*/
#[Override]
protected function loadMappingFile(string $file): array
{
$callback = Closure::bind(static function (string $file): mixed {
Expand Down
Loading