Migrate persisters to PHP 8 syntax
Showing 8 of 9 files from the diff.
Other files ignored by Codecov
phpstan-baseline.neon
has changed.
@@ -11,13 +11,8 @@
Loading
11 | 11 | ||
12 | 12 | class PersisterException extends Exception implements ORMException |
|
13 | 13 | { |
|
14 | - | /** |
|
15 | - | * @param string $class |
|
16 | - | * @param string $associationName |
|
17 | - | * |
|
18 | - | * @return PersisterException |
|
19 | - | */ |
|
20 | - | public static function matchingAssocationFieldRequiresObject($class, $associationName) |
|
14 | + | /** @return PersisterException */ |
|
15 | + | public static function matchingAssocationFieldRequiresObject(string $class, string $associationName) |
|
21 | 16 | { |
|
22 | 17 | return new self(sprintf( |
|
23 | 18 | 'Cannot match on %s::%s with a non-object value. Matching objects by id is ' . |
@@ -21,24 +21,14 @@
Loading
21 | 21 | */ |
|
22 | 22 | class SqlExpressionVisitor extends ExpressionVisitor |
|
23 | 23 | { |
|
24 | - | /** @var BasicEntityPersister */ |
|
25 | - | private $persister; |
|
26 | - | ||
27 | - | /** @var ClassMetadata */ |
|
28 | - | private $classMetadata; |
|
29 | - | ||
30 | - | public function __construct(BasicEntityPersister $persister, ClassMetadata $classMetadata) |
|
31 | - | { |
|
32 | - | $this->persister = $persister; |
|
33 | - | $this->classMetadata = $classMetadata; |
|
24 | + | public function __construct( |
|
25 | + | private readonly BasicEntityPersister $persister, |
|
26 | + | private readonly ClassMetadata $classMetadata, |
|
27 | + | ) { |
|
34 | 28 | } |
|
35 | 29 | ||
36 | - | /** |
|
37 | - | * Converts a comparison expression into the target query language output. |
|
38 | - | * |
|
39 | - | * @return mixed |
|
40 | - | */ |
|
41 | - | public function walkComparison(Comparison $comparison) |
|
30 | + | /** Converts a comparison expression into the target query language output. */ |
|
31 | + | public function walkComparison(Comparison $comparison): string |
|
42 | 32 | { |
|
43 | 33 | $field = $comparison->getField(); |
|
44 | 34 | $value = $comparison->getValue()->getValue(); // shortcut for walkValue() |
@@ -61,11 +51,9 @@
Loading
61 | 51 | /** |
|
62 | 52 | * Converts a composite expression into the target query language output. |
|
63 | 53 | * |
|
64 | - | * @return string |
|
65 | - | * |
|
66 | 54 | * @throws RuntimeException |
|
67 | 55 | */ |
|
68 | - | public function walkCompositeExpression(CompositeExpression $expr) |
|
56 | + | public function walkCompositeExpression(CompositeExpression $expr): string |
|
69 | 57 | { |
|
70 | 58 | $expressionList = []; |
|
71 | 59 |
@@ -73,24 +61,17 @@
Loading
73 | 61 | $expressionList[] = $this->dispatch($child); |
|
74 | 62 | } |
|
75 | 63 | ||
76 | - | switch ($expr->getType()) { |
|
77 | - | case CompositeExpression::TYPE_AND: |
|
78 | - | return '(' . implode(' AND ', $expressionList) . ')'; |
|
79 | - | ||
80 | - | case CompositeExpression::TYPE_OR: |
|
81 | - | return '(' . implode(' OR ', $expressionList) . ')'; |
|
82 | - | ||
83 | - | default: |
|
84 | - | throw new RuntimeException('Unknown composite ' . $expr->getType()); |
|
85 | - | } |
|
64 | + | return match ($expr->getType()) { |
|
65 | + | CompositeExpression::TYPE_AND => '(' . implode(' AND ', $expressionList) . ')', |
|
66 | + | CompositeExpression::TYPE_OR => '(' . implode(' OR ', $expressionList) . ')', |
|
67 | + | default => throw new RuntimeException('Unknown composite ' . $expr->getType()), |
|
68 | + | }; |
|
86 | 69 | } |
|
87 | 70 | ||
88 | 71 | /** |
|
89 | 72 | * Converts a value expression into the target query language part. |
|
90 | - | * |
|
91 | - | * @return string |
|
92 | 73 | */ |
|
93 | - | public function walkValue(Value $value) |
|
74 | + | public function walkValue(Value $value): string |
|
94 | 75 | { |
|
95 | 76 | return '?'; |
|
96 | 77 | } |
@@ -15,10 +15,10 @@
Loading
15 | 15 | class SqlValueVisitor extends ExpressionVisitor |
|
16 | 16 | { |
|
17 | 17 | /** @var mixed[] */ |
|
18 | - | private $values = []; |
|
18 | + | private array $values = []; |
|
19 | 19 | ||
20 | 20 | /** @var mixed[][] */ |
|
21 | - | private $types = []; |
|
21 | + | private array $types = []; |
|
22 | 22 | ||
23 | 23 | /** |
|
24 | 24 | * Converts a comparison expression into the target query language output. |
@@ -73,7 +73,7 @@
Loading
73 | 73 | * @return mixed[][] |
|
74 | 74 | * @psalm-return array{0: array, 1: array<array<mixed>>} |
|
75 | 75 | */ |
|
76 | - | public function getParamsAndTypes() |
|
76 | + | public function getParamsAndTypes(): array |
|
77 | 77 | { |
|
78 | 78 | return [$this->values, $this->types]; |
|
79 | 79 | } |
@@ -88,18 +88,11 @@
Loading
88 | 88 | { |
|
89 | 89 | $value = $comparison->getValue()->getValue(); |
|
90 | 90 | ||
91 | - | switch ($comparison->getOperator()) { |
|
92 | - | case Comparison::CONTAINS: |
|
93 | - | return '%' . $value . '%'; |
|
94 | - | ||
95 | - | case Comparison::STARTS_WITH: |
|
96 | - | return $value . '%'; |
|
97 | - | ||
98 | - | case Comparison::ENDS_WITH: |
|
99 | - | return '%' . $value; |
|
100 | - | ||
101 | - | default: |
|
102 | - | return $value; |
|
103 | - | } |
|
91 | + | return match ($comparison->getOperator()) { |
|
92 | + | Comparison::CONTAINS => '%' . $value . '%', |
|
93 | + | Comparison::STARTS_WITH => $value . '%', |
|
94 | + | Comparison::ENDS_WITH => '%' . $value, |
|
95 | + | default => $value, |
|
96 | + | }; |
|
104 | 97 | } |
|
105 | 98 | } |
@@ -11,7 +11,6 @@
Loading
11 | 11 | use Doctrine\ORM\PersistentCollection; |
|
12 | 12 | use Doctrine\ORM\Utility\PersisterHelper; |
|
13 | 13 | ||
14 | - | use function array_merge; |
|
15 | 14 | use function array_reverse; |
|
16 | 15 | use function array_values; |
|
17 | 16 | use function assert; |
@@ -52,7 +51,7 @@
Loading
52 | 51 | return; |
|
53 | 52 | } |
|
54 | 53 | ||
55 | - | public function get(PersistentCollection $collection, mixed $index): mixed |
|
54 | + | public function get(PersistentCollection $collection, mixed $index): object|null |
|
56 | 55 | { |
|
57 | 56 | $mapping = $collection->getMapping(); |
|
58 | 57 |
@@ -213,7 +212,7 @@
Loading
213 | 212 | $numDeleted = $this->conn->executeStatement($statement, $parameters); |
|
214 | 213 | ||
215 | 214 | // 3) Delete records on each table in the hierarchy |
|
216 | - | $classNames = array_merge($targetClass->parentClasses, [$targetClass->name], $targetClass->subClasses); |
|
215 | + | $classNames = [...$targetClass->parentClasses, ...[$targetClass->name], ...$targetClass->subClasses]; |
|
217 | 216 | ||
218 | 217 | foreach (array_reverse($classNames) as $className) { |
|
219 | 218 | $tableName = $this->quoteStrategy->getTableName($this->em->getClassMetadata($className), $this->platform); |
@@ -17,7 +17,6 @@
Loading
17 | 17 | use function array_fill; |
|
18 | 18 | use function array_pop; |
|
19 | 19 | use function count; |
|
20 | - | use function get_class; |
|
21 | 20 | use function implode; |
|
22 | 21 | use function in_array; |
|
23 | 22 | use function reset; |
@@ -74,7 +73,7 @@
Loading
74 | 73 | } |
|
75 | 74 | } |
|
76 | 75 | ||
77 | - | public function get(PersistentCollection $collection, mixed $index): mixed |
|
76 | + | public function get(PersistentCollection $collection, mixed $index): object|null |
|
78 | 77 | { |
|
79 | 78 | $mapping = $collection->getMapping(); |
|
80 | 79 |
@@ -207,7 +206,7 @@
Loading
207 | 206 | { |
|
208 | 207 | $mapping = $collection->getMapping(); |
|
209 | 208 | $owner = $collection->getOwner(); |
|
210 | - | $ownerMetadata = $this->em->getClassMetadata(get_class($owner)); |
|
209 | + | $ownerMetadata = $this->em->getClassMetadata($owner::class); |
|
211 | 210 | $id = $this->uow->getEntityIdentifier($owner); |
|
212 | 211 | $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); |
|
213 | 212 | $onConditions = $this->getOnConditionSQL($mapping); |
@@ -361,7 +360,7 @@
Loading
361 | 360 | { |
|
362 | 361 | $columns = []; |
|
363 | 362 | $mapping = $collection->getMapping(); |
|
364 | - | $class = $this->em->getClassMetadata(get_class($collection->getOwner())); |
|
363 | + | $class = $this->em->getClassMetadata($collection->getOwner()::class); |
|
365 | 364 | $joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform); |
|
366 | 365 | ||
367 | 366 | foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { |
@@ -441,7 +440,7 @@
Loading
441 | 440 | * @return mixed[] |
|
442 | 441 | * @psalm-return list<mixed> |
|
443 | 442 | */ |
|
444 | - | protected function getDeleteRowSQLParameters(PersistentCollection $collection, object $element) |
|
443 | + | protected function getDeleteRowSQLParameters(PersistentCollection $collection, object $element): array |
|
445 | 444 | { |
|
446 | 445 | return $this->collectJoinTableColumnParameters($collection, $element); |
|
447 | 446 | } |
@@ -514,7 +513,7 @@
Loading
514 | 513 | ||
515 | 514 | $class1 = $class2 = null; |
|
516 | 515 | if ($isComposite) { |
|
517 | - | $class1 = $this->em->getClassMetadata(get_class($collection->getOwner())); |
|
516 | + | $class1 = $this->em->getClassMetadata($collection->getOwner()::class); |
|
518 | 517 | $class2 = $collection->getTypeClass(); |
|
519 | 518 | } |
|
520 | 519 |
@@ -158,11 +158,11 @@
Loading
158 | 158 | /** |
|
159 | 159 | * The IdentifierFlattener used for manipulating identifiers |
|
160 | 160 | */ |
|
161 | - | private IdentifierFlattener $identifierFlattener; |
|
161 | + | private readonly IdentifierFlattener $identifierFlattener; |
|
162 | 162 | ||
163 | 163 | protected CachedPersisterContext $currentPersisterContext; |
|
164 | - | private CachedPersisterContext $limitsHandlingContext; |
|
165 | - | private CachedPersisterContext $noLimitsContext; |
|
164 | + | private readonly CachedPersisterContext $limitsHandlingContext; |
|
165 | + | private readonly CachedPersisterContext $noLimitsContext; |
|
166 | 166 | ||
167 | 167 | /** |
|
168 | 168 | * Initializes a new <tt>BasicEntityPersister</tt> that uses the given EntityManager |
@@ -338,7 +338,7 @@
Loading
338 | 338 | $types = []; |
|
339 | 339 | ||
340 | 340 | foreach ($id as $field => $value) { |
|
341 | - | $types = array_merge($types, $this->getTypes($field, $value, $versionedClass)); |
|
341 | + | $types = [...$types, ...$this->getTypes($field, $value, $versionedClass)]; |
|
342 | 342 | } |
|
343 | 343 | ||
344 | 344 | return $types; |
@@ -852,7 +852,7 @@
Loading
852 | 852 | ||
853 | 853 | foreach ($types as $type) { |
|
854 | 854 | [$field, $value] = $type; |
|
855 | - | $sqlTypes = array_merge($sqlTypes, $this->getTypes($field, $value, $this->class)); |
|
855 | + | $sqlTypes = [...$sqlTypes, ...$this->getTypes($field, $value, $this->class)]; |
|
856 | 856 | } |
|
857 | 857 | ||
858 | 858 | return [$sqlParams, $sqlTypes]; |
@@ -1791,7 +1791,7 @@
Loading
1791 | 1791 | continue; // skip null values. |
|
1792 | 1792 | } |
|
1793 | 1793 | ||
1794 | - | $types = array_merge($types, $this->getTypes($field, $value, $this->class)); |
|
1794 | + | $types = [...$types, ...$this->getTypes($field, $value, $this->class)]; |
|
1795 | 1795 | $params = array_merge($params, $this->getValues($value)); |
|
1796 | 1796 | } |
|
1797 | 1797 |
@@ -1820,7 +1820,7 @@
Loading
1820 | 1820 | continue; // skip null values. |
|
1821 | 1821 | } |
|
1822 | 1822 | ||
1823 | - | $types = array_merge($types, $this->getTypes($criterion['field'], $criterion['value'], $criterion['class'])); |
|
1823 | + | $types = [...$types, ...$this->getTypes($criterion['field'], $criterion['value'], $criterion['class'])]; |
|
1824 | 1824 | $params = array_merge($params, $this->getValues($criterion['value'])); |
|
1825 | 1825 | } |
|
1826 | 1826 |
@@ -1869,7 +1869,7 @@
Loading
1869 | 1869 | } |
|
1870 | 1870 | ||
1871 | 1871 | if (is_array($value)) { |
|
1872 | - | return array_map([$this, 'getArrayBindingType'], $types); |
|
1872 | + | return array_map($this->getArrayBindingType(...), $types); |
|
1873 | 1873 | } |
|
1874 | 1874 | ||
1875 | 1875 | return $types; |
@@ -1964,8 +1964,8 @@
Loading
1964 | 1964 | $sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions); |
|
1965 | 1965 | [$criteriaParams, $criteriaTypes] = $this->expandCriteriaParameters($extraConditions); |
|
1966 | 1966 | ||
1967 | - | $params = array_merge($params, $criteriaParams); |
|
1968 | - | $types = array_merge($types, $criteriaTypes); |
|
1967 | + | $params = [...$params, ...$criteriaParams]; |
|
1968 | + | $types = [...$types, ...$criteriaTypes]; |
|
1969 | 1969 | } |
|
1970 | 1970 | ||
1971 | 1971 | $filterSql = $this->generateFilterConditionSQL($this->class, $alias); |
@@ -18,20 +18,6 @@
Loading
18 | 18 | */ |
|
19 | 19 | class CachedPersisterContext |
|
20 | 20 | { |
|
21 | - | /** |
|
22 | - | * Metadata object that describes the mapping of the mapped entity class. |
|
23 | - | * |
|
24 | - | * @var \Doctrine\ORM\Mapping\ClassMetadata |
|
25 | - | */ |
|
26 | - | public $class; |
|
27 | - | ||
28 | - | /** |
|
29 | - | * ResultSetMapping that is used for all queries. Is generated lazily once per request. |
|
30 | - | * |
|
31 | - | * @var ResultSetMapping |
|
32 | - | */ |
|
33 | - | public $rsm; |
|
34 | - | ||
35 | 21 | /** |
|
36 | 22 | * The SELECT column list SQL fragment used for querying entities by this persister. |
|
37 | 23 | * This SQL fragment is only generated once per request, if at all. |
@@ -62,21 +48,19 @@
Loading
62 | 48 | */ |
|
63 | 49 | public $sqlTableAliases = []; |
|
64 | 50 | ||
65 | - | /** |
|
66 | - | * Whether this persistent context is considering limit operations applied to the selection queries |
|
67 | - | * |
|
68 | - | * @var bool |
|
69 | - | */ |
|
70 | - | public $handlesLimits; |
|
71 | - | ||
72 | - | /** @param bool $handlesLimits */ |
|
73 | 51 | public function __construct( |
|
74 | - | ClassMetadata $class, |
|
75 | - | ResultSetMapping $rsm, |
|
76 | - | $handlesLimits, |
|
52 | + | /** |
|
53 | + | * Metadata object that describes the mapping of the mapped entity class. |
|
54 | + | */ |
|
55 | + | public ClassMetadata $class, |
|
56 | + | /** |
|
57 | + | * ResultSetMapping that is used for all queries. Is generated lazily once per request. |
|
58 | + | */ |
|
59 | + | public ResultSetMapping $rsm, |
|
60 | + | /** |
|
61 | + | * Whether this persistent context is considering limit operations applied to the selection queries |
|
62 | + | */ |
|
63 | + | public bool $handlesLimits, |
|
77 | 64 | ) { |
|
78 | - | $this->class = $class; |
|
79 | - | $this->rsm = $rsm; |
|
80 | - | $this->handlesLimits = (bool) $handlesLimits; |
|
81 | 65 | } |
|
82 | 66 | } |
Files | Coverage |
---|---|
lib/Doctrine/ORM | 89.63% |
Project Totals (330 files) | 89.63% |
3526971339
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.