Skip to content

Commit

Permalink
Merge pull request #10509 from greg0ire/php8-migration
Browse files Browse the repository at this point in the history
Migrate the rest of the source code to PHP 8 syntax
  • Loading branch information
greg0ire authored Feb 8, 2023
2 parents 7e2eb61 + f5e7ddb commit f86fa17
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 38 deletions.
3 changes: 1 addition & 2 deletions lib/Doctrine/ORM/Mapping/DefaultEntityListenerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\ORM\Mapping;

use function get_class;
use function trim;

/**
Expand All @@ -29,7 +28,7 @@ public function clear(string|null $className = null): void

public function register(object $object): void
{
$this->instances[get_class($object)] = $object;
$this->instances[$object::class] = $object;
}

public function resolve(string $className): object
Expand Down
22 changes: 8 additions & 14 deletions lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\Persistence\Mapping\ClassMetadata as PersistenceClassMetadata;
use Doctrine\Persistence\Mapping\Driver\FileDriver;
use Doctrine\Persistence\Mapping\Driver\FileLocator;
use DOMDocument;
use InvalidArgumentException;
use LogicException;
Expand Down Expand Up @@ -41,14 +42,14 @@ class XmlDriver extends FileDriver
{
public const DEFAULT_FILE_EXTENSION = '.dcm.xml';

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

/**
* {@inheritDoc}
*/
public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION, bool $isXsdValidationEnabled = false)
{
public function __construct(
string|array|FileLocator $locator,
string $fileExtension = self::DEFAULT_FILE_EXTENSION,
private readonly bool $isXsdValidationEnabled = false,
) {
if (! extension_loaded('simplexml')) {
throw new LogicException(sprintf(
'The XML metadata driver cannot be enabled because the SimpleXML PHP extension is missing.'
Expand All @@ -73,8 +74,6 @@ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENS
));
}

$this->isXsdValidationEnabled = $isXsdValidationEnabled;

parent::__construct($locator, $fileExtension);
}

Expand All @@ -86,7 +85,7 @@ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENS
*
* @template T of object
*/
public function loadMetadataForClass($className, PersistenceClassMetadata $metadata)
public function loadMetadataForClass($className, PersistenceClassMetadata $metadata): void
{
$xmlRoot = $this->getElement($className);
assert($xmlRoot instanceof SimpleXMLElement);
Expand Down Expand Up @@ -962,12 +961,7 @@ private function validateMapping(string $file): void
}
}

/**
* @param mixed $element
*
* @return bool
*/
protected function evaluateBoolean($element)
protected function evaluateBoolean(mixed $element): bool
{
$flag = (string) $element;

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/OptimisticLockException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OptimisticLockException extends Exception implements ORMException
{
public function __construct(
string $msg,
private object|string|null $entity,
private readonly object|string|null $entity,
Throwable|null $previous = null,
) {
parent::__construct($msg, 0, $previous);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/AST/PathExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PathExpression extends Node
final public const TYPE_STATE_FIELD = 8;

/** @psalm-var self::TYPE_*|null */
public int|null $type;
public int|null $type = null;

/** @psalm-param int-mask-of<self::TYPE_*> $expectedType */
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class AbstractSqlExecutor
/** @var list<string>|string */
protected array|string $sqlStatements;

protected QueryCacheProfile|null $queryCacheProfile;
protected QueryCacheProfile|null $queryCacheProfile = null;

/**
* Gets the SQL statements that are executed by the executor.
Expand Down
12 changes: 6 additions & 6 deletions lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class LimitSubqueryOutputWalker extends SqlWalker
{
private const ORDER_BY_PATH_EXPRESSION = '/(?<![a-z0-9_])%s\.%s(?![a-z0-9_])/i';

private AbstractPlatform $platform;
private ResultSetMapping $rsm;
private int $firstResult;
private int|null $maxResults;
private EntityManagerInterface $em;
private QuoteStrategy $quoteStrategy;
private readonly AbstractPlatform $platform;
private readonly ResultSetMapping $rsm;
private readonly int $firstResult;
private readonly int|null $maxResults;
private readonly EntityManagerInterface $em;
private readonly QuoteStrategy $quoteStrategy;

/** @var list<PathExpression> */
private array $orderByPathExpressions = [];
Expand Down
5 changes: 2 additions & 3 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
use function array_filter;
use function array_key_exists;
use function array_map;
use function array_merge;
use function array_pop;
use function array_sum;
use function array_values;
Expand Down Expand Up @@ -983,7 +982,7 @@ public function recomputeSingleEntityChangeSet(ClassMetadata $class, object $ent

if ($changeSet) {
if (isset($this->entityChangeSets[$oid])) {
$this->entityChangeSets[$oid] = array_merge($this->entityChangeSets[$oid], $changeSet);
$this->entityChangeSets[$oid] = [...$this->entityChangeSets[$oid], ...$changeSet];
} elseif (! isset($this->entityInsertions[$oid])) {
$this->entityChangeSets[$oid] = $changeSet;
$this->entityUpdates[$oid] = $entity;
Expand Down Expand Up @@ -2891,7 +2890,7 @@ private function performCallbackOnCachedPersister(callable $callback): void
return;
}

foreach (array_merge($this->persisters, $this->collectionPersisters) as $persister) {
foreach ([...$this->persisters, ...$this->collectionPersisters] as $persister) {
if ($persister instanceof CachedPersister) {
$callback($persister);
}
Expand Down
10 changes: 0 additions & 10 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,6 @@
'region' =&gt; $region,
]</code>
</LessSpecificReturnStatement>
<MissingParamType>
<code>$fileExtension</code>
<code>$locator</code>
</MissingParamType>
<MoreSpecificImplementedParamType>
<code>$metadata</code>
</MoreSpecificImplementedParamType>
Expand Down Expand Up @@ -1188,7 +1184,6 @@
</PossiblyInvalidIterator>
<PropertyNotSetInConstructor>
<code>MultiTableDeleteExecutor</code>
<code>MultiTableDeleteExecutor</code>
</PropertyNotSetInConstructor>
<UninitializedProperty>
<code>$this-&gt;sqlStatements</code>
Expand All @@ -1206,7 +1201,6 @@
</PossiblyInvalidIterator>
<PropertyNotSetInConstructor>
<code>MultiTableUpdateExecutor</code>
<code>MultiTableUpdateExecutor</code>
</PropertyNotSetInConstructor>
<PropertyTypeCoercion>
<code>$this-&gt;sqlStatements</code>
Expand All @@ -1219,9 +1213,6 @@
<PossiblyInvalidArgument>
<code>$this-&gt;sqlStatements</code>
</PossiblyInvalidArgument>
<PropertyNotSetInConstructor>
<code>SingleSelectExecutor</code>
</PropertyNotSetInConstructor>
</file>
<file src="lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php">
<InvalidReturnStatement>
Expand All @@ -1235,7 +1226,6 @@
</PossiblyInvalidArgument>
<PropertyNotSetInConstructor>
<code>SingleTableDeleteUpdateExecutor</code>
<code>SingleTableDeleteUpdateExecutor</code>
</PropertyNotSetInConstructor>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/Andx.php">
Expand Down

0 comments on commit f86fa17

Please sign in to comment.