Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
511 changes: 314 additions & 197 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/AliasedExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AliasedExpression extends Expression
* @param ?array $columns The columns used by the expression
* @param mixed ...$values The values for the expression
*/
public function __construct(string $alias, string $statement, array $columns = null, ...$values)
public function __construct(string $alias, string $statement, ?array $columns = null, ...$values)
{
parent::__construct($statement, $columns, ...$values);

Expand Down
2 changes: 1 addition & 1 deletion src/Behavior/Binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
* {@see \ipl\Orm\Compat\FilterProcessor::requireAndResolveFilterColumns()}
*/
$column = $condition->metaData()->get('columnName');
if (isset($this->properties[$column])) {
if ($column !== null && isset($this->properties[$column])) {

Check failure on line 82 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Possibly invalid array key type mixed.

Check failure on line 82 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Possibly invalid array key type mixed.

Check failure on line 82 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Possibly invalid array key type mixed.

Check failure on line 82 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Possibly invalid array key type mixed.
$value = $condition->metaData()->get('originalValue');

if ($this->isPostgres && is_resource($value)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/InvalidRelationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class InvalidRelationException extends Exception
* Create a new InvalidRelationException
*
* @param string $relation The relation name
* @param Model $model The target model
* @param ?Model $model The target model
*/
public function __construct($relation, Model $model = null)
public function __construct($relation, ?Model $model = null)
{
$this->relation = (string) $relation;
$this->model = $model;
Expand Down
2 changes: 1 addition & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class Model implements \ArrayAccess, \IteratorAggregate
{
use PropertiesWithDefaults;

final public function __construct(array $properties = null)
final public function __construct(?array $properties = null)
{
if ($this->hasProperties()) {
$this->setProperties($properties);
Expand Down
6 changes: 3 additions & 3 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public function derive($relation, Model $source)
*
* @return static
*/
public function createSubQuery(Model $target, $targetPath, Model $from = null, bool $link = true)
public function createSubQuery(Model $target, $targetPath, ?Model $from = null, bool $link = true)
{
$subQuery = (new static())
->setDb($this->getDb())
Expand Down Expand Up @@ -744,9 +744,9 @@ protected function groupColumnsByTarget(Generator $columns)
$columnStorage = new SplObjectStorage();

foreach ($columns as list($target, $alias, $column)) {
if (! $columnStorage->contains($target)) {
if (! $columnStorage->offsetExists($target)) {
$resolved = new ArrayObject();
$columnStorage->attach($target, $resolved);
$columnStorage->offsetSet($target, $resolved);
} else {
$resolved = $columnStorage[$target];
}
Expand Down
56 changes: 28 additions & 28 deletions src/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public function __construct(Query $query)
*/
public function getRelations(Model $model)
{
if (! $this->relations->contains($model)) {
if (! $this->relations->offsetExists($model)) {
$relations = new Relations();
$model->createRelations($relations);
$this->relations->attach($model, $relations);
$this->relations->offsetSet($model, $relations);
}

return $this->relations[$model];
Expand All @@ -99,10 +99,10 @@ public function getRelations(Model $model)
*/
public function getBehaviors(Model $model)
{
if (! $this->behaviors->contains($model)) {
if (! $this->behaviors->offsetExists($model)) {
$behaviors = new Behaviors();
$model->createBehaviors($behaviors);
$this->behaviors->attach($model, $behaviors);
$this->behaviors->offsetSet($model, $behaviors);

foreach ($behaviors as $behavior) {
if ($behavior instanceof QueryAwareBehavior) {
Expand All @@ -123,10 +123,10 @@ public function getBehaviors(Model $model)
*/
public function getDefaults(Model $model): Defaults
{
if (! $this->defaults->contains($model)) {
if (! $this->defaults->offsetExists($model)) {
$defaults = new Defaults();
$model->createDefaults($defaults);
$this->defaults->attach($model, $defaults);
$this->defaults->offsetSet($model, $defaults);
}

return $this->defaults[$model];
Expand All @@ -143,7 +143,7 @@ public function getDefaults(Model $model): Defaults
*/
public function getAlias(Model $model)
{
if (! $this->aliases->contains($model)) {
if (! $this->aliases->offsetExists($model)) {
throw new OutOfBoundsException(sprintf(
"Can't get alias for model '%s'. Alias does not exist",
get_class($model)
Expand Down Expand Up @@ -202,7 +202,7 @@ public function setAliasPrefix($alias)
*/
public function hasSelectableColumn(Model $subject, $column)
{
if (! $this->selectableColumns->contains($subject)) {
if (! $this->selectableColumns->offsetExists($subject)) {
$this->collectColumns($subject);
}

Expand All @@ -223,7 +223,7 @@ public function hasSelectableColumn(Model $subject, $column)
*/
public function getSelectableColumns(Model $subject)
{
if (! $this->selectableColumns->contains($subject)) {
if (! $this->selectableColumns->offsetExists($subject)) {
$this->collectColumns($subject);
}

Expand All @@ -239,7 +239,7 @@ public function getSelectableColumns(Model $subject)
*/
public function getSelectColumns(Model $subject)
{
if (! $this->selectColumns->contains($subject)) {
if (! $this->selectColumns->offsetExists($subject)) {
$this->collectColumns($subject);
}

Expand All @@ -255,8 +255,8 @@ public function getSelectColumns(Model $subject)
*/
public function getColumnDefinitions(Model $subject)
{
if (! $this->metaData->contains($subject)) {
$this->metaData->attach($subject, $this->collectMetaData($subject));
if (! $this->metaData->offsetExists($subject)) {
$this->metaData->offsetSet($subject, $this->collectMetaData($subject));
}

return $this->metaData[$subject];
Expand Down Expand Up @@ -329,14 +329,14 @@ public function qualifyColumn($column, $tableName)
* Qualify the given columns by the specified model
*
* @param iterable $columns
* @param Model $model Leave null in case $columns is {@see Resolver::requireAndResolveColumns()}
* @param ?Model $model Leave null in case $columns is {@see Resolver::requireAndResolveColumns()}
*
* @return array
*
* @throws InvalidArgumentException If $columns is not iterable
* @throws InvalidArgumentException If $model is not passed and $columns is not a generator
*/
public function qualifyColumns($columns, Model $model = null)
public function qualifyColumns($columns, ?Model $model = null)
{
$target = $model ?: $this->query->getModel();
$targetAlias = $this->getAlias($target);
Expand Down Expand Up @@ -382,15 +382,15 @@ public function qualifyColumns($columns, Model $model = null)
* Qualify the given columns and aliases by the specified model
*
* @param iterable $columns
* @param Model $model Leave null in case $columns is {@see Resolver::requireAndResolveColumns()}
* @param ?Model $model Leave null in case $columns is {@see Resolver::requireAndResolveColumns()}
* @param bool $autoAlias Set an alias for columns which have none
*
* @return array
*
* @throws InvalidArgumentException If $columns is not iterable
* @throws InvalidArgumentException If $model is not passed and $columns is not a generator
*/
public function qualifyColumnsAndAliases($columns, Model $model = null, $autoAlias = true)
public function qualifyColumnsAndAliases($columns, ?Model $model = null, $autoAlias = true)
{
$target = $model ?: $this->query->getModel();
$targetAlias = $this->getAlias($target);
Expand Down Expand Up @@ -492,14 +492,14 @@ public function isDistinctRelation($path)
* Also resolves all other relations.
*
* @param string $path
* @param Model $subject
* @param ?Model $subject
*
* @return Relation
*/
public function resolveRelation($path, Model $subject = null)
public function resolveRelation($path, ?Model $subject = null)
{
$subject = $subject ?: $this->query->getModel();
if (! $this->resolvedRelations->contains($subject) || ! isset($this->resolvedRelations[$subject][$path])) {
if (! $this->resolvedRelations->offsetExists($subject) || ! isset($this->resolvedRelations[$subject][$path])) {
foreach ($this->resolveRelations($path, $subject) as $_) {
// run and exhaust generator
}
Expand All @@ -514,13 +514,13 @@ public function resolveRelation($path, Model $subject = null)
* Traverses the entire path and yields the path travelled so far as key and the relation as value.
*
* @param string $path
* @param Model $subject
* @param ?Model $subject
*
* @return Generator
* @throws InvalidArgumentException In case $path is not fully qualified
* @throws InvalidRelationException In case a relation is unknown
*/
public function resolveRelations($path, Model $subject = null)
public function resolveRelations($path, ?Model $subject = null)
{
$relations = explode('.', $path);
$subject = $subject ?: $this->query->getModel();
Expand All @@ -533,7 +533,7 @@ public function resolveRelations($path, Model $subject = null)
}

$resolvedRelations = [];
if ($this->resolvedRelations->contains($subject)) {
if ($this->resolvedRelations->offsetExists($subject)) {
$resolvedRelations = $this->resolvedRelations[$subject];
}

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

$this->resolvedRelations->attach($subject, $resolvedRelations);
$this->resolvedRelations->offsetSet($subject, $resolvedRelations);
}

/**
* Require and resolve columns
*
* Related models will be automatically added for eager-loading.
*
* @param array $columns
* @param Model $model
* @param array $columns
* @param ?Model $model
*
* @return Generator
*
* @throws InvalidColumnException If a column does not exist
*/
public function requireAndResolveColumns(array $columns, Model $model = null)
public function requireAndResolveColumns(array $columns, ?Model $model = null)
{
$model = $model ?: $this->query->getModel();
$tableName = $model->getTableAlias();
Expand Down Expand Up @@ -745,7 +745,7 @@ protected function collectColumns(Model $subject)
// Don't fail if Model::getColumns() also contains the primary key columns
$columns = array_merge((array) $subject->getKeyName(), (array) $subject->getColumns());

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

$selectable = [];

Expand All @@ -759,7 +759,7 @@ protected function collectColumns(Model $subject)
}
}

$this->selectableColumns->attach($subject, $selectable);
$this->selectableColumns->offsetSet($subject, $selectable);
}

/**
Expand Down
Loading