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

Flag properties as readonly if possible #9956

Merged
merged 1 commit into from
Aug 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Cache/DefaultCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/
class DefaultCache implements Cache
{
private UnitOfWork $uow;
private CacheFactory $cacheFactory;
private readonly UnitOfWork $uow;
private readonly CacheFactory $cacheFactory;

/**
* @var QueryCache[]
Expand All @@ -32,7 +32,7 @@ class DefaultCache implements Cache
private ?QueryCache $defaultQueryCache = null;

public function __construct(
private EntityManagerInterface $em
private readonly EntityManagerInterface $em
) {
$this->uow = $em->getUnitOfWork();
$this->cacheFactory = $em->getConfiguration()
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
*/
class DefaultCollectionHydrator implements CollectionHydrator
{
private UnitOfWork $uow;
private readonly UnitOfWork $uow;

/** @var array<string,mixed> */
private static array $hints = [Query::HINT_CACHE_ENABLED => true];

public function __construct(
private EntityManagerInterface $em
private readonly EntityManagerInterface $em
) {
$this->uow = $em->getUnitOfWork();
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Cache/DefaultQueryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
*/
class DefaultQueryCache implements QueryCache
{
private UnitOfWork $uow;
private QueryCacheValidator $validator;
private readonly UnitOfWork $uow;
private readonly QueryCacheValidator $validator;
protected ?CacheLogger $cacheLogger = null;

/** @var array<string,mixed> */
private static array $hints = [Query::HINT_CACHE_ENABLED => true];

public function __construct(
private EntityManagerInterface $em,
private Region $region
private readonly EntityManagerInterface $em,
private readonly Region $region
) {
$cacheConfig = $em->getConfiguration()->getSecondLevelCacheConfiguration();

Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Cache/Region/DefaultRegion.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class DefaultRegion implements Region
private const REGION_PREFIX = 'DC2_REGION_';

public function __construct(
private string $name,
private CacheItemPoolInterface $cacheItemPool,
private int $lifetime = 0
private readonly string $name,
private readonly CacheItemPoolInterface $cacheItemPool,
private readonly int $lifetime = 0
) {
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Cache/Region/FileLockRegion.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class FileLockRegion implements ConcurrentRegion
* @throws InvalidArgumentException
*/
public function __construct(
private Region $region,
private string $directory,
private string|int $lockLifetime
private readonly Region $region,
private readonly string $directory,
private readonly string|int $lockLifetime
) {
if (! is_dir($directory) && ! @mkdir($directory, 0775, true)) {
throw new InvalidArgumentException(sprintf('The directory "%s" does not exist and could not be created.', $directory));
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
class EntityRepository implements ObjectRepository, Selectable
{
/** @psalm-var class-string<T> */
private string $entityName;
private readonly string $entityName;
private static ?Inflector $inflector = null;

/**
* @psalm-param ClassMetadata<T> $class
*/
public function __construct(
private EntityManagerInterface $em,
private ClassMetadata $class
private readonly EntityManagerInterface $em,
private readonly ClassMetadata $class
) {
$this->entityName = $class->name;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ final class HydrationCompleteHandler
/** @var mixed[][] */
private array $deferredPostLoadInvocations = [];

public function __construct(private ListenersInvoker $listenersInvoker, private EntityManagerInterface $em)
{
public function __construct(
private readonly ListenersInvoker $listenersInvoker,
private readonly EntityManagerInterface $em,
) {
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ final class ReflectionEmbeddedProperty extends ReflectionProperty
* @psalm-param class-string $embeddedClass
*/
public function __construct(
private ReflectionProperty $parentProperty,
private ReflectionProperty $childProperty,
private string $embeddedClass
private readonly ReflectionProperty $parentProperty,
private readonly ReflectionProperty $childProperty,
private readonly string $embeddedClass
) {
parent::__construct($childProperty->getDeclaringClass()->getName(), $childProperty->getName());
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/ReflectionEnumProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ final class ReflectionEnumProperty extends ReflectionProperty
* @param class-string<BackedEnum> $enumType
*/
public function __construct(
private ReflectionProperty $originalReflectionProperty,
private string $enumType
private readonly ReflectionProperty $originalReflectionProperty,
private readonly string $enumType
) {
parent::__construct(
$originalReflectionProperty->getDeclaringClass()->getName(),
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/ReflectionReadonlyProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
final class ReflectionReadonlyProperty extends ReflectionProperty
{
public function __construct(
private ReflectionProperty $wrappedProperty
private readonly ReflectionProperty $wrappedProperty
) {
if (! $wrappedProperty->isReadOnly()) {
throw new InvalidArgumentException('Given property is not readonly.');
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/Filter/SQLFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class SQLFilter
private array $parameters = [];

final public function __construct(
private EntityManagerInterface $em
private readonly EntityManagerInterface $em
) {
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/FilterCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class FilterCollection
private int $filtersState = self::FILTERS_STATE_CLEAN;

public function __construct(
private EntityManagerInterface $em
private readonly EntityManagerInterface $em
) {
$this->config = $em->getConfiguration();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class ResultSetMappingBuilder extends ResultSetMapping
* @psalm-param self::COLUMN_RENAMING_* $defaultRenameMode
*/
public function __construct(
private EntityManagerInterface $em,
private int $defaultRenameMode = self::COLUMN_RENAMING_NONE,
private readonly EntityManagerInterface $em,
private readonly int $defaultRenameMode = self::COLUMN_RENAMING_NONE,
) {
}

Expand Down
14 changes: 7 additions & 7 deletions lib/Doctrine/ORM/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SqlWalker
*/
public const HINT_PARTIAL = 'doctrine.partial';

private ResultSetMapping $rsm;
private readonly ResultSetMapping $rsm;

/**
* Counter for generating unique column aliases.
Expand All @@ -81,8 +81,8 @@ class SqlWalker
*/
private int $newObjectCounter = 0;

private EntityManagerInterface $em;
private Connection $conn;
private readonly EntityManagerInterface $em;
private readonly Connection $conn;

/** @var mixed[] */
private array $tableAliasMap = [];
Expand Down Expand Up @@ -131,19 +131,19 @@ class SqlWalker
/**
* The database platform abstraction.
*/
private AbstractPlatform $platform;
private readonly AbstractPlatform $platform;

/**
* The quote strategy.
*/
private QuoteStrategy $quoteStrategy;
private readonly QuoteStrategy $quoteStrategy;

/**
* @psalm-param array<string, QueryComponent> $queryComponents The query components (symbol table).
*/
public function __construct(
private Query $query,
private ParserResult $parserResult,
private readonly Query $query,
private readonly ParserResult $parserResult,
private array $queryComponents
) {
$this->rsm = $parserResult->getResultSetMapping();
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Query/TreeWalkerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ abstract class TreeWalkerAdapter implements TreeWalker
* {@inheritdoc}
*/
public function __construct(
private AbstractQuery $query,
private ParserResult $parserResult,
private readonly AbstractQuery $query,
private readonly ParserResult $parserResult,
private array $queryComponents
) {
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Query/TreeWalkerChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class TreeWalkerChain implements TreeWalker
* {@inheritdoc}
*/
public function __construct(
private AbstractQuery $query,
private ParserResult $parserResult,
private readonly AbstractQuery $query,
private readonly ParserResult $parserResult,
private array $queryComponents
) {
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class QueryBuilder
* @param EntityManagerInterface $em The EntityManager to use.
*/
public function __construct(
private EntityManagerInterface $em
private readonly EntityManagerInterface $em
) {
$this->parameters = new ArrayCollection();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

abstract class AbstractEntityManagerCommand extends Command
{
public function __construct(private EntityManagerProvider $entityManagerProvider)
public function __construct(private readonly EntityManagerProvider $entityManagerProvider)
{
parent::__construct();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class ConnectionFromManagerProvider implements ConnectionProvider
{
public function __construct(private EntityManagerProvider $entityManagerProvider)
public function __construct(private readonly EntityManagerProvider $entityManagerProvider)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
final class SingleManagerProvider implements EntityManagerProvider
{
public function __construct(
private EntityManagerInterface $entityManager,
private string $defaultManagerName = 'default',
private readonly EntityManagerInterface $entityManager,
private readonly string $defaultManagerName = 'default',
) {
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class DebugUnitOfWorkListener
* The stream can be php://output to print to the screen.
*/
public function __construct(
private string $file = 'php://output',
private string $context = ''
private readonly string $file = 'php://output',
private readonly string $context = ''
) {
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Tools/Event/GenerateSchemaEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
class GenerateSchemaEventArgs extends EventArgs
{
public function __construct(
private EntityManagerInterface $em,
private Schema $schema
private readonly EntityManagerInterface $em,
private readonly Schema $schema
) {
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Tools/Event/GenerateSchemaTableEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
class GenerateSchemaTableEventArgs extends EventArgs
{
public function __construct(
private ClassMetadata $classMetadata,
private Schema $schema,
private Table $classTable
private readonly ClassMetadata $classMetadata,
private readonly Schema $schema,
private readonly Table $classTable
) {
}

Expand Down
8 changes: 5 additions & 3 deletions lib/Doctrine/ORM/Tools/Pagination/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ class Paginator implements Countable, IteratorAggregate
{
use SQLResultCasing;

private Query $query;
private readonly Query $query;
private ?bool $useOutputWalkers = null;
private ?int $count = null;

/**
* @param bool $fetchJoinCollection Whether the query joins a collection (true by default).
*/
public function __construct(Query|QueryBuilder $query, private bool $fetchJoinCollection = true)
{
public function __construct(
Query|QueryBuilder $query,
private readonly bool $fetchJoinCollection = true
) {
if ($query instanceof QueryBuilder) {
$query = $query->getQuery();
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class SchemaTool
{
private const KNOWN_COLUMN_OPTIONS = ['comment', 'unsigned', 'fixed', 'default'];

private AbstractPlatform $platform;
private QuoteStrategy $quoteStrategy;
private AbstractSchemaManager $schemaManager;
private readonly AbstractPlatform $platform;
private readonly QuoteStrategy $quoteStrategy;
private readonly AbstractSchemaManager $schemaManager;

/**
* Initializes a new SchemaTool instance that uses the connection of the
* provided EntityManager.
*/
public function __construct(private EntityManagerInterface $em)
public function __construct(private readonly EntityManagerInterface $em)
{
$this->platform = $em->getConnection()->getDatabasePlatform();
$this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class SchemaValidator
{
public function __construct(private EntityManagerInterface $em)
public function __construct(private readonly EntityManagerInterface $em)
{
}

Expand Down