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
7 changes: 5 additions & 2 deletions src/Behavior/Binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use ipl\Orm\Query;
use ipl\Sql\Adapter\Pgsql;
use ipl\Stdlib\Filter\Condition;
use ipl\Stdlib\Filter\Rule;
use UnexpectedValueException;

use function ipl\Stdlib\get_php_type;
Expand Down Expand Up @@ -65,21 +66,21 @@
return sprintf('\\x%s', bin2hex($value));
}

public function setQuery(Query $query)
public function setQuery(Query $query): static
{
$this->isPostgres = $query->getDb()->getAdapter() instanceof Pgsql;

return $this;
}

public function rewriteCondition(Condition $condition, $relation = null)
public function rewriteCondition(Condition $condition, ?string $relation = null): null
{
/**
* TODO(lippserd): Duplicate code because {@see RewriteFilterBehavior}s come after {@see PropertyBehavior}s.
* {@see \ipl\Orm\Compat\FilterProcessor::requireAndResolveFilterColumns()}
*/
$column = $condition->metaData()->get('columnName');
if ($column !== null && isset($this->properties[$column])) {

Check failure on line 83 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 83 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 83 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 83 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 All @@ -100,5 +101,7 @@
}
}
}

return null;
}
}
2 changes: 1 addition & 1 deletion src/Behavior/MillisecondTimestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
return null;
}

$datetime = DateTime::createFromFormat('U.u', sprintf('%F', $value / 1000.0));

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

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

Binary operation "/" between mixed and 1000.0 results in an error.

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

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

Binary operation "/" between mixed and 1000.0 results in an error.

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

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

Binary operation "/" between mixed and 1000.0 results in an error.

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

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

Binary operation "/" between mixed and 1000.0 results in an error.
$datetime->setTimezone(new DateTimeZone(date_default_timezone_get()));

return $datetime;
Expand All @@ -31,7 +31,7 @@
if (! $value instanceof DateTime) {
try {
$value = new DateTime($value);
} catch (Exception $err) {
} catch (Exception) {
throw new ValueConversionException(sprintf('Invalid date time format provided: %s', $value));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/QueryAwareBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ interface QueryAwareBehavior extends Behavior
*
* @return $this
*/
public function setQuery(Query $query);
public function setQuery(Query $query): static;
}
2 changes: 1 addition & 1 deletion src/Contract/RewriteColumnBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface RewriteColumnBehavior extends RewriteFilterBehavior
*
* @return mixed
*/
public function rewriteColumn($column, ?string $relation = null);
public function rewriteColumn(mixed $column, ?string $relation = null): mixed;

/**
* Get whether {@see rewriteColumn} might return an otherwise unknown column or expression
Expand Down
6 changes: 3 additions & 3 deletions src/Contract/RewriteFilterBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ interface RewriteFilterBehavior extends Behavior
* Processing of the condition will be restarted, hence the column has to be an absolute path again.
*
* @param Filter\Condition $condition
* @param string $relation The absolute path (with a trailing dot) of the model
* @param ?string $relation The absolute path (with a trailing dot) of the model
*
* @return Filter\Rule|null
* @return ?Filter\Rule
*/
public function rewriteCondition(Filter\Condition $condition, $relation = null);
public function rewriteCondition(Filter\Condition $condition, ?string $relation = null): ?Filter\Rule;
}
28 changes: 14 additions & 14 deletions src/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
namespace ipl\Orm;

use ArrayIterator;
use Generator;
use Iterator;
use Traversable;

class ResultSet implements Iterator
{
protected $cache;
protected ArrayIterator $cache;

/** @var bool Whether cache is disabled */
protected $isCacheDisabled = false;
protected bool $isCacheDisabled = false;

protected $generator;
protected Generator $generator;

protected $limit;
protected ?int $limit;

protected $position;
protected ?int $position = null;

public function __construct(Traversable $traversable, $limit = null)
public function __construct(Traversable $traversable, ?int $limit = null)
{
$this->cache = new ArrayIterator();
$this->generator = $this->yieldTraversable($traversable);
Expand All @@ -33,7 +34,7 @@ public function __construct(Traversable $traversable, $limit = null)
*
* @return static
*/
public static function fromQuery(Query $query)
public static function fromQuery(Query $query): static
{
return new static($query->yieldResults(), $query->getLimit());
}
Expand All @@ -45,25 +46,24 @@ public static function fromQuery(Query $query)
*
* @return $this
*/
public function disableCache()
public function disableCache(): static
{
$this->isCacheDisabled = true;

return $this;
}

public function hasMore()
public function hasMore(): bool
{
return $this->generator->valid();
}

public function hasResult()
public function hasResult(): bool
{
return $this->generator->valid();
}

#[\ReturnTypeWillChange]
public function current()
public function current(): mixed
{
if ($this->position === null) {
$this->advance();
Expand Down Expand Up @@ -117,7 +117,7 @@ public function rewind(): void
}
}

protected function advance()
protected function advance(): void
{
if (! $this->generator->valid()) {
return;
Expand All @@ -134,7 +134,7 @@ protected function advance()
}
}

protected function yieldTraversable(Traversable $traversable)
protected function yieldTraversable(Traversable $traversable): Generator
{
foreach ($traversable as $key => $value) {
yield $key => $value;
Expand Down
4 changes: 2 additions & 2 deletions src/UnionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class UnionModel extends Model
*
* @return UnionQuery
*/
public static function on(Connection $db)
public static function on(Connection $db): UnionQuery
{
return (new UnionQuery())
->setDb($db)
Expand All @@ -25,5 +25,5 @@ public static function on(Connection $db)
*
* @return array
*/
abstract public function getUnions();
abstract public function getUnions(): array;
}
8 changes: 6 additions & 2 deletions tests/ApiIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Stdlib\Filter\Condition;
use ipl\Stdlib\Filter\Rule;

class ApiIdentity extends Model
{
Expand All @@ -33,12 +34,14 @@ public function getColumns()
public function createBehaviors(Behaviors $behaviors)
{
$rewriteBehavior = new class () implements RewriteColumnBehavior {
public function rewriteColumn($column, $relation = null)
public function rewriteColumn(mixed $column, ?string $relation = null): ?AliasedExpression
{
if ($column === 'api_token') {
$relation = str_replace('.', '_', $relation);
return new AliasedExpression("{$relation}_api_token", '"api_token retrieval not permitted"');
}

return null;
}

public function rewriteColumnDefinition(ColumnDefinition $def, string $relation): void
Expand All @@ -50,8 +53,9 @@ public function isSelectableColumn(string $name): bool
return $name === 'api_token';
}

public function rewriteCondition(Condition $condition, $relation = null)
public function rewriteCondition(Condition $condition, ?string $relation = null): ?Rule
{
return null;
}
};

Expand Down
Loading