Skip to content

Commit

Permalink
Improve types in pool interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ilijastuden committed Apr 24, 2022
1 parent 21043ab commit ec70acb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
10 changes: 7 additions & 3 deletions src/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getType(): string

public function getSelectSql(): string
{
return $this->getSelectFieldsSql($this->pool->getEscapedTypeFields($this->type));
return $this->getSelectFieldsSql($this->pool->getTypeFieldsReadStatement($this->type));
}

public function getSelectIdsSql(): string
Expand Down Expand Up @@ -279,9 +279,13 @@ private function loadByTypeField(): bool
return $this->load_by_type_field;
}

private function getSelectFieldsSql(string $escaped_field_names): string
private function getSelectFieldsSql(string $fields_read_statement): string
{
$result = "SELECT $escaped_field_names FROM " . $this->getEscapedTableName();
$result = sprintf(
'SELECT %s FROM %s',
$fields_read_statement,
$this->getEscapedTableName()
);

if ($this->join) {
$result .= " $this->join";
Expand Down
7 changes: 2 additions & 5 deletions src/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function forget(string $type, int ...$ids_to_forget): void
*
* @param array|string|null $conditions
*/
public function count(string $type, $conditions = null): int
public function count(string $type, mixed $conditions = null): int
{
$this->requireRegisteredType($type);

Expand Down Expand Up @@ -359,10 +359,7 @@ public function getDefaultFinderClass(): string
return Finder::class;
}

/**
* {@inheritdoc}
*/
public function findBySql(string $type, string $sql, ...$arguments)
public function findBySql(string $type, string $sql, mixed ...$arguments): mixed
{
if (empty($type)) {
throw new InvalidArgumentException('Type is required');
Expand Down
10 changes: 2 additions & 8 deletions src/PoolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ public function forget(string $type, int ...$ids_to_forget): void;
/**
* Return number of records of the given type that match the given conditions.
*
* @param string $type
* @param array|string|null $conditions
* @return int
*/
public function count(string $type, $conditions = null): int;
public function count(string $type, mixed $conditions = null): int;

/**
* Return true if object of the given type with the given ID exists.
Expand All @@ -62,13 +60,9 @@ public function find(string $type): FinderInterface;
/**
* Return result by a prepared SQL statement.
*
* @param string $type
* @param string $sql
* @param mixed $arguments
* @return ResultInterface|EntityInterface[]|null
*/
public function findBySql(string $type, string $sql, ...$arguments);

public function findBySql(string $type, string $sql, mixed ...$arguments): mixed;
public function getTypeTable(string $type, bool $escaped = false): string;

/**
Expand Down

0 comments on commit ec70acb

Please sign in to comment.