Skip to content

Commit 7f9827d

Browse files
authored
Merge pull request #10497 from greg0ire/php8-migration
Migrate more classes to PHP 8 syntax
2 parents de8b444 + 941292f commit 7f9827d

File tree

5 files changed

+36
-71
lines changed

5 files changed

+36
-71
lines changed

lib/Doctrine/ORM/Event/OnClassMetadataNotFoundEventArgs.php

+9-20
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,30 @@
1919
*/
2020
class OnClassMetadataNotFoundEventArgs extends ManagerEventArgs
2121
{
22-
/** @var string */
23-
private $className;
24-
25-
/** @var ClassMetadata|null */
26-
private $foundMetadata;
27-
28-
/**
29-
* @param string $className
30-
* @param EntityManagerInterface $objectManager
31-
*/
32-
public function __construct($className, ObjectManager $objectManager)
33-
{
34-
$this->className = (string) $className;
22+
private ClassMetadata|null $foundMetadata = null;
3523

24+
/** @param EntityManagerInterface $objectManager */
25+
public function __construct(
26+
private readonly string $className,
27+
ObjectManager $objectManager,
28+
) {
3629
parent::__construct($objectManager);
3730
}
3831

39-
/** @return void */
40-
public function setFoundMetadata(ClassMetadata|null $classMetadata)
32+
public function setFoundMetadata(ClassMetadata|null $classMetadata): void
4133
{
4234
$this->foundMetadata = $classMetadata;
4335
}
4436

45-
/** @return ClassMetadata|null */
46-
public function getFoundMetadata()
37+
public function getFoundMetadata(): ClassMetadata|null
4738
{
4839
return $this->foundMetadata;
4940
}
5041

5142
/**
5243
* Retrieve class name for which a failed metadata fetch attempt was executed
53-
*
54-
* @return string
5544
*/
56-
public function getClassName()
45+
public function getClassName(): string
5746
{
5847
return $this->className;
5948
}

lib/Doctrine/ORM/PersistentCollection.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec
6969
*/
7070
private string|null $backRefFieldName = null;
7171

72-
/**
73-
* The class descriptor of the collection's entity type.
74-
*/
75-
private ClassMetadata|null $typeClass = null;
76-
7772
/**
7873
* Whether the collection is dirty and needs to be synchronized with the database
7974
* when the UnitOfWork that manages its persistent state commits.
@@ -83,18 +78,17 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec
8378
/**
8479
* Creates a new persistent collection.
8580
*
86-
* @param EntityManagerInterface $em The EntityManager the collection will be associated with.
87-
* @param ClassMetadata $class The class descriptor of the entity type of this collection.
81+
* @param EntityManagerInterface $em The EntityManager the collection will be associated with.
82+
* @param ClassMetadata $typeClass The class descriptor of the entity type of this collection.
8883
* @psalm-param Collection<TKey, T>&Selectable<TKey, T> $collection The collection elements.
8984
*/
9085
public function __construct(
9186
EntityManagerInterface $em,
92-
ClassMetadata $class,
87+
private readonly ClassMetadata|null $typeClass,
9388
Collection $collection,
9489
) {
9590
$this->collection = $collection;
9691
$this->em = $em;
97-
$this->typeClass = $class;
9892
$this->initialized = true;
9993
}
10094

@@ -523,6 +517,11 @@ public function __sleep(): array
523517
return ['collection', 'initialized'];
524518
}
525519

520+
public function __wakeup(): void
521+
{
522+
$this->em = null;
523+
}
524+
526525
/**
527526
* Extracts a slice of $length elements starting at position $offset from the Collection.
528527
*
@@ -614,7 +613,7 @@ public function matching(Criteria $criteria): Collection
614613
*
615614
* @return Collection<TKey, T>&Selectable<TKey, T>
616615
*/
617-
public function unwrap(): Collection&Selectable
616+
public function unwrap(): Selectable&Collection
618617
{
619618
assert($this->collection instanceof Collection);
620619
assert($this->collection instanceof Selectable);

lib/Doctrine/ORM/Query/Printer.php

+10-28
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,16 @@
1313
*/
1414
class Printer
1515
{
16-
/**
17-
* Current indentation level
18-
*
19-
* @var int
20-
*/
21-
protected $_indent = 0;
22-
23-
/**
24-
* Defines whether parse tree is printed (default, false) or not (true).
25-
*
26-
* @var bool
27-
*/
28-
protected $_silent;
16+
/** Current indentation level */
17+
protected int $indent = 0;
2918

3019
/**
3120
* Constructs a new parse tree printer.
3221
*
3322
* @param bool $silent Parse tree will not be printed if true.
3423
*/
35-
public function __construct($silent = false)
24+
public function __construct(protected bool $silent = false)
3625
{
37-
$this->_silent = $silent;
3826
}
3927

4028
/**
@@ -44,39 +32,33 @@ public function __construct($silent = false)
4432
* This method is called before executing a production.
4533
*
4634
* @param string $name Production name.
47-
*
48-
* @return void
4935
*/
50-
public function startProduction($name)
36+
public function startProduction(string $name): void
5137
{
5238
$this->println('(' . $name);
53-
$this->_indent++;
39+
$this->indent++;
5440
}
5541

5642
/**
5743
* Decreases indentation level by one and prints a closing parenthesis.
5844
*
5945
* This method is called after executing a production.
60-
*
61-
* @return void
6246
*/
63-
public function endProduction()
47+
public function endProduction(): void
6448
{
65-
$this->_indent--;
49+
$this->indent--;
6650
$this->println(')');
6751
}
6852

6953
/**
7054
* Prints text indented with spaces depending on current indentation level.
7155
*
7256
* @param string $str The text.
73-
*
74-
* @return void
7557
*/
76-
public function println($str)
58+
public function println(string $str): void
7759
{
78-
if (! $this->_silent) {
79-
echo str_repeat(' ', $this->_indent), $str, "\n";
60+
if (! $this->silent) {
61+
echo str_repeat(' ', $this->indent), $str, "\n";
8062
}
8163
}
8264
}

lib/Doctrine/ORM/Query/SqlWalker.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ public function walkPathExpression(AST\PathExpression $pathExpr): string
627627
public function walkSelectClause(AST\SelectClause $selectClause): string
628628
{
629629
$sql = 'SELECT ' . ($selectClause->isDistinct ? 'DISTINCT ' : '');
630-
$sqlSelectExpressions = array_filter(array_map([$this, 'walkSelectExpression'], $selectClause->selectExpressions));
630+
$sqlSelectExpressions = array_filter(array_map($this->walkSelectExpression(...), $selectClause->selectExpressions));
631631

632632
if ($this->query->getHint(Query::HINT_INTERNAL_ITERATION) === true && $selectClause->isDistinct) {
633633
$this->query->setHint(self::HINT_DISTINCT, true);
@@ -1043,7 +1043,7 @@ public function walkFunction(AST\Functions\FunctionNode $function): string
10431043
*/
10441044
public function walkOrderByClause(AST\OrderByClause $orderByClause): string
10451045
{
1046-
$orderByItems = array_map([$this, 'walkOrderByItem'], $orderByClause->orderByItems);
1046+
$orderByItems = array_map($this->walkOrderByItem(...), $orderByClause->orderByItems);
10471047

10481048
$collectionOrderByItems = $this->generateOrderedCollectionOrderByItems();
10491049
if ($collectionOrderByItems !== '') {
@@ -1677,7 +1677,7 @@ public function walkUpdateClause(AST\UpdateClause $updateClause): string
16771677
$this->setSQLTableAlias($tableName, $tableName, $updateClause->aliasIdentificationVariable);
16781678
$this->rootAliases[] = $updateClause->aliasIdentificationVariable;
16791679

1680-
return $sql . ' SET ' . implode(', ', array_map([$this, 'walkUpdateItem'], $updateClause->updateItems));
1680+
return $sql . ' SET ' . implode(', ', array_map($this->walkUpdateItem(...), $updateClause->updateItems));
16811681
}
16821682

16831683
/**
@@ -1756,7 +1756,7 @@ public function walkConditionalExpression(
17561756
return $this->walkConditionalTerm($condExpr);
17571757
}
17581758

1759-
return implode(' OR ', array_map([$this, 'walkConditionalTerm'], $condExpr->conditionalTerms));
1759+
return implode(' OR ', array_map($this->walkConditionalTerm(...), $condExpr->conditionalTerms));
17601760
}
17611761

17621762
/**
@@ -1771,7 +1771,7 @@ public function walkConditionalTerm(
17711771
return $this->walkConditionalFactor($condTerm);
17721772
}
17731773

1774-
return implode(' AND ', array_map([$this, 'walkConditionalFactor'], $condTerm->conditionalFactors));
1774+
return implode(' AND ', array_map($this->walkConditionalFactor(...), $condTerm->conditionalFactors));
17751775
}
17761776

17771777
/**
@@ -1953,7 +1953,7 @@ public function walkInListExpression(AST\InListExpression $inExpr): string
19531953
{
19541954
return $this->walkArithmeticExpression($inExpr->expression)
19551955
. ($inExpr->not ? ' NOT' : '') . ' IN ('
1956-
. implode(', ', array_map([$this, 'walkInParameter'], $inExpr->literals))
1956+
. implode(', ', array_map($this->walkInParameter(...), $inExpr->literals))
19571957
. ')';
19581958
}
19591959

@@ -2134,7 +2134,7 @@ public function walkSimpleArithmeticExpression(AST\Node|string $simpleArithmetic
21342134
return $this->walkArithmeticTerm($simpleArithmeticExpr);
21352135
}
21362136

2137-
return implode(' ', array_map([$this, 'walkArithmeticTerm'], $simpleArithmeticExpr->arithmeticTerms));
2137+
return implode(' ', array_map($this->walkArithmeticTerm(...), $simpleArithmeticExpr->arithmeticTerms));
21382138
}
21392139

21402140
/**
@@ -2154,7 +2154,7 @@ public function walkArithmeticTerm(AST\Node|string $term): string
21542154
return $this->walkArithmeticFactor($term);
21552155
}
21562156

2157-
return implode(' ', array_map([$this, 'walkArithmeticFactor'], $term->arithmeticFactors));
2157+
return implode(' ', array_map($this->walkArithmeticFactor(...), $term->arithmeticFactors));
21582158
}
21592159

21602160
/**

psalm-baseline.xml

-5
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,6 @@
227227
<code>list&lt;T&gt;</code>
228228
</MoreSpecificReturnType>
229229
</file>
230-
<file src="lib/Doctrine/ORM/Event/OnClassMetadataNotFoundEventArgs.php">
231-
<RedundantCastGivenDocblockType>
232-
<code>(string) $className</code>
233-
</RedundantCastGivenDocblockType>
234-
</file>
235230
<file src="lib/Doctrine/ORM/Id/AssignedGenerator.php">
236231
<PossiblyNullArgument>
237232
<code>$entity</code>

0 commit comments

Comments
 (0)