Skip to content

Commit

Permalink
some cleanup on datamodel::get
Browse files Browse the repository at this point in the history
  • Loading branch information
verfriemelt-dot-org committed Jun 2, 2024
1 parent d2d0b56 commit e6243c7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
14 changes: 1 addition & 13 deletions _/DataModel/DataModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ public static function buildCountQuery(): DataModelQueryBuilder
return $query;
}

/**
* creates an object with the given id as param
*/
public static function get(string|int $id): ?static
{
$pk = static::getPrimaryKey();
Expand All @@ -267,16 +264,7 @@ public static function get(string|int $id): ?static
throw new DatabaseException('::get is not possible without PK');
}

$result = static::fetchBy($pk, $id);

// for backwards compatibility
if ($result === null) {
throw new DatabaseObjectNotFound(
'no such object found in database with name ' . static::class . " and id {$id}",
);
}

return $result;
return static::fetchBy($pk, $id) ?? throw new DatabaseObjectNotFound('no such object found in database with name ' . static::class . " and id {$id}");
}

public function reload(): static
Expand Down
9 changes: 2 additions & 7 deletions phpstan.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ parameters:
path: _/DataModel/DataModel.php

-
message: "#^Class cognitive complexity is 71, keep it under 50$#"
message: "#^Class cognitive complexity is 70, keep it under 50$#"
count: 1
path: _/DataModel/DataModel.php

Expand All @@ -546,12 +546,7 @@ parameters:
path: _/DataModel/DataModel.php

-
message: "#^Method verfriemelt\\\\wrapped\\\\_\\\\DataModel\\\\DataModel\\:\\:count\\(\\) has parameter \\$and with no type specified\\.$#"
count: 1
path: _/DataModel/DataModel.php

-
message: "#^Method verfriemelt\\\\wrapped\\\\_\\\\DataModel\\\\DataModel\\:\\:count\\(\\) has parameter \\$params with no type specified\\.$#"
message: "#^Method verfriemelt\\\\wrapped\\\\_\\\\DataModel\\\\DataModel\\:\\:count\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
count: 1
path: _/DataModel/DataModel.php

Expand Down

0 comments on commit e6243c7

Please sign in to comment.