Skip to content

Commit d8ecdaa

Browse files
authored
Support PHP 8.5 (#154)
PHP 8.3 -> PHP 8.4: * Function parameters that are null by default must be declared nullable. PHP 8.4 -> PHP 8.5 * Several aliases of SplObjectStorage methods are deprecated in 8.5. * Using null as array key is deprecated. In addition the `phpstan-baseline.neon` has been updated, because some of it's errors were no longer reported.
2 parents 7e5c01a + be36f28 commit d8ecdaa

7 files changed

Lines changed: 350 additions & 233 deletions

File tree

phpstan-baseline.neon

Lines changed: 314 additions & 197 deletions
Large diffs are not rendered by default.

src/AliasedExpression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AliasedExpression extends Expression
1717
* @param ?array $columns The columns used by the expression
1818
* @param mixed ...$values The values for the expression
1919
*/
20-
public function __construct(string $alias, string $statement, array $columns = null, ...$values)
20+
public function __construct(string $alias, string $statement, ?array $columns = null, ...$values)
2121
{
2222
parent::__construct($statement, $columns, ...$values);
2323

src/Behavior/Binary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function rewriteCondition(Condition $condition, $relation = null)
7979
* {@see \ipl\Orm\Compat\FilterProcessor::requireAndResolveFilterColumns()}
8080
*/
8181
$column = $condition->metaData()->get('columnName');
82-
if (isset($this->properties[$column])) {
82+
if ($column !== null && isset($this->properties[$column])) {
8383
$value = $condition->metaData()->get('originalValue');
8484

8585
if ($this->isPostgres && is_resource($value)) {

src/Exception/InvalidRelationException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class InvalidRelationException extends Exception
1717
* Create a new InvalidRelationException
1818
*
1919
* @param string $relation The relation name
20-
* @param Model $model The target model
20+
* @param ?Model $model The target model
2121
*/
22-
public function __construct($relation, Model $model = null)
22+
public function __construct($relation, ?Model $model = null)
2323
{
2424
$this->relation = (string) $relation;
2525
$this->model = $model;

src/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ abstract class Model implements \ArrayAccess, \IteratorAggregate
1414
{
1515
use PropertiesWithDefaults;
1616

17-
final public function __construct(array $properties = null)
17+
final public function __construct(?array $properties = null)
1818
{
1919
if ($this->hasProperties()) {
2020
$this->setProperties($properties);

src/Query.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ public function derive($relation, Model $source)
602602
*
603603
* @return static
604604
*/
605-
public function createSubQuery(Model $target, $targetPath, Model $from = null, bool $link = true)
605+
public function createSubQuery(Model $target, $targetPath, ?Model $from = null, bool $link = true)
606606
{
607607
$subQuery = (new static())
608608
->setDb($this->getDb())
@@ -744,9 +744,9 @@ protected function groupColumnsByTarget(Generator $columns)
744744
$columnStorage = new SplObjectStorage();
745745

746746
foreach ($columns as list($target, $alias, $column)) {
747-
if (! $columnStorage->contains($target)) {
747+
if (! $columnStorage->offsetExists($target)) {
748748
$resolved = new ArrayObject();
749-
$columnStorage->attach($target, $resolved);
749+
$columnStorage->offsetSet($target, $resolved);
750750
} else {
751751
$resolved = $columnStorage[$target];
752752
}

src/Resolver.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public function __construct(Query $query)
8181
*/
8282
public function getRelations(Model $model)
8383
{
84-
if (! $this->relations->contains($model)) {
84+
if (! $this->relations->offsetExists($model)) {
8585
$relations = new Relations();
8686
$model->createRelations($relations);
87-
$this->relations->attach($model, $relations);
87+
$this->relations->offsetSet($model, $relations);
8888
}
8989

9090
return $this->relations[$model];
@@ -99,10 +99,10 @@ public function getRelations(Model $model)
9999
*/
100100
public function getBehaviors(Model $model)
101101
{
102-
if (! $this->behaviors->contains($model)) {
102+
if (! $this->behaviors->offsetExists($model)) {
103103
$behaviors = new Behaviors();
104104
$model->createBehaviors($behaviors);
105-
$this->behaviors->attach($model, $behaviors);
105+
$this->behaviors->offsetSet($model, $behaviors);
106106

107107
foreach ($behaviors as $behavior) {
108108
if ($behavior instanceof QueryAwareBehavior) {
@@ -123,10 +123,10 @@ public function getBehaviors(Model $model)
123123
*/
124124
public function getDefaults(Model $model): Defaults
125125
{
126-
if (! $this->defaults->contains($model)) {
126+
if (! $this->defaults->offsetExists($model)) {
127127
$defaults = new Defaults();
128128
$model->createDefaults($defaults);
129-
$this->defaults->attach($model, $defaults);
129+
$this->defaults->offsetSet($model, $defaults);
130130
}
131131

132132
return $this->defaults[$model];
@@ -143,7 +143,7 @@ public function getDefaults(Model $model): Defaults
143143
*/
144144
public function getAlias(Model $model)
145145
{
146-
if (! $this->aliases->contains($model)) {
146+
if (! $this->aliases->offsetExists($model)) {
147147
throw new OutOfBoundsException(sprintf(
148148
"Can't get alias for model '%s'. Alias does not exist",
149149
get_class($model)
@@ -202,7 +202,7 @@ public function setAliasPrefix($alias)
202202
*/
203203
public function hasSelectableColumn(Model $subject, $column)
204204
{
205-
if (! $this->selectableColumns->contains($subject)) {
205+
if (! $this->selectableColumns->offsetExists($subject)) {
206206
$this->collectColumns($subject);
207207
}
208208

@@ -223,7 +223,7 @@ public function hasSelectableColumn(Model $subject, $column)
223223
*/
224224
public function getSelectableColumns(Model $subject)
225225
{
226-
if (! $this->selectableColumns->contains($subject)) {
226+
if (! $this->selectableColumns->offsetExists($subject)) {
227227
$this->collectColumns($subject);
228228
}
229229

@@ -239,7 +239,7 @@ public function getSelectableColumns(Model $subject)
239239
*/
240240
public function getSelectColumns(Model $subject)
241241
{
242-
if (! $this->selectColumns->contains($subject)) {
242+
if (! $this->selectColumns->offsetExists($subject)) {
243243
$this->collectColumns($subject);
244244
}
245245

@@ -255,8 +255,8 @@ public function getSelectColumns(Model $subject)
255255
*/
256256
public function getColumnDefinitions(Model $subject)
257257
{
258-
if (! $this->metaData->contains($subject)) {
259-
$this->metaData->attach($subject, $this->collectMetaData($subject));
258+
if (! $this->metaData->offsetExists($subject)) {
259+
$this->metaData->offsetSet($subject, $this->collectMetaData($subject));
260260
}
261261

262262
return $this->metaData[$subject];
@@ -329,14 +329,14 @@ public function qualifyColumn($column, $tableName)
329329
* Qualify the given columns by the specified model
330330
*
331331
* @param iterable $columns
332-
* @param Model $model Leave null in case $columns is {@see Resolver::requireAndResolveColumns()}
332+
* @param ?Model $model Leave null in case $columns is {@see Resolver::requireAndResolveColumns()}
333333
*
334334
* @return array
335335
*
336336
* @throws InvalidArgumentException If $columns is not iterable
337337
* @throws InvalidArgumentException If $model is not passed and $columns is not a generator
338338
*/
339-
public function qualifyColumns($columns, Model $model = null)
339+
public function qualifyColumns($columns, ?Model $model = null)
340340
{
341341
$target = $model ?: $this->query->getModel();
342342
$targetAlias = $this->getAlias($target);
@@ -382,15 +382,15 @@ public function qualifyColumns($columns, Model $model = null)
382382
* Qualify the given columns and aliases by the specified model
383383
*
384384
* @param iterable $columns
385-
* @param Model $model Leave null in case $columns is {@see Resolver::requireAndResolveColumns()}
385+
* @param ?Model $model Leave null in case $columns is {@see Resolver::requireAndResolveColumns()}
386386
* @param bool $autoAlias Set an alias for columns which have none
387387
*
388388
* @return array
389389
*
390390
* @throws InvalidArgumentException If $columns is not iterable
391391
* @throws InvalidArgumentException If $model is not passed and $columns is not a generator
392392
*/
393-
public function qualifyColumnsAndAliases($columns, Model $model = null, $autoAlias = true)
393+
public function qualifyColumnsAndAliases($columns, ?Model $model = null, $autoAlias = true)
394394
{
395395
$target = $model ?: $this->query->getModel();
396396
$targetAlias = $this->getAlias($target);
@@ -492,14 +492,14 @@ public function isDistinctRelation($path)
492492
* Also resolves all other relations.
493493
*
494494
* @param string $path
495-
* @param Model $subject
495+
* @param ?Model $subject
496496
*
497497
* @return Relation
498498
*/
499-
public function resolveRelation($path, Model $subject = null)
499+
public function resolveRelation($path, ?Model $subject = null)
500500
{
501501
$subject = $subject ?: $this->query->getModel();
502-
if (! $this->resolvedRelations->contains($subject) || ! isset($this->resolvedRelations[$subject][$path])) {
502+
if (! $this->resolvedRelations->offsetExists($subject) || ! isset($this->resolvedRelations[$subject][$path])) {
503503
foreach ($this->resolveRelations($path, $subject) as $_) {
504504
// run and exhaust generator
505505
}
@@ -514,13 +514,13 @@ public function resolveRelation($path, Model $subject = null)
514514
* Traverses the entire path and yields the path travelled so far as key and the relation as value.
515515
*
516516
* @param string $path
517-
* @param Model $subject
517+
* @param ?Model $subject
518518
*
519519
* @return Generator
520520
* @throws InvalidArgumentException In case $path is not fully qualified
521521
* @throws InvalidRelationException In case a relation is unknown
522522
*/
523-
public function resolveRelations($path, Model $subject = null)
523+
public function resolveRelations($path, ?Model $subject = null)
524524
{
525525
$relations = explode('.', $path);
526526
$subject = $subject ?: $this->query->getModel();
@@ -533,7 +533,7 @@ public function resolveRelations($path, Model $subject = null)
533533
}
534534

535535
$resolvedRelations = [];
536-
if ($this->resolvedRelations->contains($subject)) {
536+
if ($this->resolvedRelations->offsetExists($subject)) {
537537
$resolvedRelations = $this->resolvedRelations[$subject];
538538
}
539539

@@ -585,22 +585,22 @@ public function resolveRelations($path, Model $subject = null)
585585
$resolvedRelations[$pathBeingResolved] = $relation;
586586
}
587587

588-
$this->resolvedRelations->attach($subject, $resolvedRelations);
588+
$this->resolvedRelations->offsetSet($subject, $resolvedRelations);
589589
}
590590

591591
/**
592592
* Require and resolve columns
593593
*
594594
* Related models will be automatically added for eager-loading.
595595
*
596-
* @param array $columns
597-
* @param Model $model
596+
* @param array $columns
597+
* @param ?Model $model
598598
*
599599
* @return Generator
600600
*
601601
* @throws InvalidColumnException If a column does not exist
602602
*/
603-
public function requireAndResolveColumns(array $columns, Model $model = null)
603+
public function requireAndResolveColumns(array $columns, ?Model $model = null)
604604
{
605605
$model = $model ?: $this->query->getModel();
606606
$tableName = $model->getTableAlias();
@@ -745,7 +745,7 @@ protected function collectColumns(Model $subject)
745745
// Don't fail if Model::getColumns() also contains the primary key columns
746746
$columns = array_merge((array) $subject->getKeyName(), (array) $subject->getColumns());
747747

748-
$this->selectColumns->attach($subject, $columns);
748+
$this->selectColumns->offsetSet($subject, $columns);
749749

750750
$selectable = [];
751751

@@ -759,7 +759,7 @@ protected function collectColumns(Model $subject)
759759
}
760760
}
761761

762-
$this->selectableColumns->attach($subject, $selectable);
762+
$this->selectableColumns->offsetSet($subject, $selectable);
763763
}
764764

765765
/**

0 commit comments

Comments
 (0)