make phpstan happy

master
Josha von Gizycki 2 days ago
parent 8d86f09feb
commit 29972a6982

@ -27,6 +27,7 @@ readonly class EntityResult
*/ */
public function fieldsWithoutId(): array public function fieldsWithoutId(): array
{ {
/** @var list<EntityField> */
return array_filter($this->fields, static fn(EntityField $field) => !$field->isIdField); return array_filter($this->fields, static fn(EntityField $field) => !$field->isIdField);
} }
} }

@ -9,6 +9,7 @@ use Kartierung\Analyze\Result\EntityResult;
use Kartierung\Analyze\Result\FieldAccess; use Kartierung\Analyze\Result\FieldAccess;
use Kartierung\Analyze\Result\Type\ArrayType; use Kartierung\Analyze\Result\Type\ArrayType;
use Kartierung\Analyze\Result\Type\ClassType; use Kartierung\Analyze\Result\Type\ClassType;
use Kartierung\Repository\InvalidCall;
class EntityToDataMapper class EntityToDataMapper
{ {
@ -47,7 +48,8 @@ class EntityToDataMapper
{ {
return match ($field->readAccess) { return match ($field->readAccess) {
FieldAccess::PUBLIC => $entity->{$field->name}, FieldAccess::PUBLIC => $entity->{$field->name},
FieldAccess::GETTER => $entity->{'get' . ucfirst($field->name)}() FieldAccess::GETTER => $entity->{'get' . ucfirst($field->name)}(),
FieldAccess::NONE => throw new InvalidCall("Field $field->name cannot be accessed.")
}; };
} }
} }

@ -41,6 +41,10 @@ readonly class InsertEntity
return $newEntity; return $newEntity;
} }
/**
* @param EntityResult<object> $entityResult
* @param array<string, mixed> $data
*/
private function insertWithNewId(EntityResult $entityResult, array $data): string|false private function insertWithNewId(EntityResult $entityResult, array $data): string|false
{ {
$cols = implode(", ", array_map( $cols = implode(", ", array_map(

@ -34,7 +34,10 @@ readonly class UpdateEntity
); );
$id = $data[$entityResult->idField->columnName] ?? null; $id = $data[$entityResult->idField->columnName] ?? null;
$params[] = $id; $params[] = $id;
// reindex keys for pdo /**
* reindex for pdo
* @phpstan-ignore arrayValues.list
*/
$params = array_values($params); $params = array_values($params);
$sql = "UPDATE $entityResult->tableName SET $pairs WHERE $idWhere"; $sql = "UPDATE $entityResult->tableName SET $pairs WHERE $idWhere";
@ -56,8 +59,10 @@ readonly class UpdateEntity
$entity = (new SelectEntityById($this->pdo))->select($entityResult, $id); $entity = (new SelectEntityById($this->pdo))->select($entityResult, $id);
if (!$entity) { if (!$entity) {
/** @phpstan-ignore argument.type */
$idStr = strval($id);
throw new InvalidCall( throw new InvalidCall(
"Entity of type $entityResult->classFqcn with id $id can not be selected." "Entity of type $entityResult->classFqcn with id $idStr can not be selected."
); );
} }

@ -22,8 +22,10 @@ readonly class FindById implements ResolutionStrategy
static function (PDO $pdo) use ($method, $parameters) { static function (PDO $pdo) use ($method, $parameters) {
$id = array_first($parameters); $id = array_first($parameters);
if($id === null || count($parameters) !== 1) { if($id === null || count($parameters) !== 1) {
/** @phpstan-ignore argument.type */
$idStr = strval($id);
throw new InvalidCall( throw new InvalidCall(
"Expected exactly on parameter as id of an entity to find. $id was given." "Expected exactly on parameter as id of an entity to find. $idStr was given."
); );
} }

Loading…
Cancel
Save