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
2 changes: 1 addition & 1 deletion src/AliasedExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class AliasedExpression extends Expression
{
/** @var string */
protected $alias;
protected string $alias;

/**
* Create a new database expression
Expand Down
4 changes: 1 addition & 3 deletions src/Behavior/Binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
use ipl\Stdlib\Filter\Condition;
use UnexpectedValueException;

use function ipl\Stdlib\get_php_type;

/**
* Support hex filters for binary columns and PHP resource (in) / bytea hex format (out) transformation for PostgreSQL
*/
class Binary extends PropertyBehavior implements QueryAwareBehavior, RewriteFilterBehavior
{
/** @var bool Whether the query is using a pgsql adapter */
protected $isPostgres = true;
protected bool $isPostgres = true;

public function fromDb($value, $key, $_)
{
Expand Down Expand Up @@ -79,7 +77,7 @@
* {@see \ipl\Orm\Compat\FilterProcessor::requireAndResolveFilterColumns()}
*/
$column = $condition->metaData()->get('columnName');
if ($column !== null && isset($this->properties[$column])) {

Check failure on line 80 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.

Check failure on line 80 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 80 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 80 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.
$value = $condition->metaData()->get('originalValue');

if ($this->isPostgres && is_resource($value)) {
Expand Down
16 changes: 8 additions & 8 deletions src/Behavior/BoolCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
class BoolCast extends PropertyBehavior
{
/** @var mixed Database value for boolean `false` */
protected $falseValue = 'n';
protected mixed $falseValue = 'n';

/** @var mixed Database value for boolean `true` */
protected $trueValue = 'y';
protected mixed $trueValue = 'y';

/** @var bool Whether to throw an exception if the value is not equal to the value for false or true */
protected $strict = true;
protected bool $strict = true;

/**
* Get the database value representing boolean `false`
*
* @return mixed
*/
public function getFalseValue()
public function getFalseValue(): mixed
{
return $this->falseValue;
}
Expand All @@ -44,7 +44,7 @@ public function getFalseValue()
*
* @return $this
*/
public function setFalseValue($falseValue): self
public function setFalseValue(mixed $falseValue): static
{
$this->falseValue = $falseValue;

Expand All @@ -56,7 +56,7 @@ public function setFalseValue($falseValue): self
*
* @return mixed
*/
public function getTrueValue()
public function getTrueValue(): mixed
{
return $this->trueValue;
}
Expand All @@ -68,7 +68,7 @@ public function getTrueValue()
*
* @return $this
*/
public function setTrueValue($trueValue): self
public function setTrueValue(mixed $trueValue): static
{
$this->trueValue = $trueValue;

Expand All @@ -92,7 +92,7 @@ public function isStrict(): bool
*
* @return $this
*/
public function setStrict(bool $strict): self
public function setStrict(bool $strict): static
{
$this->strict = $strict;

Expand Down
48 changes: 27 additions & 21 deletions src/Behaviors.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

namespace ipl\Orm;
Expand All @@ -16,32 +16,34 @@
class Behaviors implements IteratorAggregate
{
/** @var array Registered behaviors */
protected $behaviors = [];
protected array $behaviors = [];

/** @var RetrieveBehavior[] Registered retrieve behaviors */
protected $retrieveBehaviors = [];
protected array $retrieveBehaviors = [];

/** @var PersistBehavior[] Registered persist behaviors */
protected $persistBehaviors = [];
protected array $persistBehaviors = [];

/** @var PropertyBehavior[] Registered property behaviors */
protected $propertyBehaviors = [];
protected array $propertyBehaviors = [];

/** @var RewriteFilterBehavior[] Registered rewrite filter behaviors */
protected $rewriteFilterBehaviors = [];
protected array $rewriteFilterBehaviors = [];

/** @var RewriteColumnBehavior[] Registered rewrite column behaviors */
protected $rewriteColumnBehaviors = [];
protected array $rewriteColumnBehaviors = [];

/** @var RewritePathBehavior[] Registered rewrite path behaviors */
protected $rewritePathBehaviors = [];
protected array $rewritePathBehaviors = [];

/**
* Add a behavior
*
* @param PersistBehavior|PropertyBehavior|RetrieveBehavior|RewriteFilterBehavior $behavior
* @param Behavior $behavior
*
* @return void
*/
public function add(Behavior $behavior)
public function add(Behavior $behavior): void
{
$this->behaviors[] = $behavior;

Expand Down Expand Up @@ -86,8 +88,10 @@
* Apply all retrieve behaviors on the given model
*
* @param Model $model
*
* @return void
*/
public function retrieve(Model $model)
public function retrieve(Model $model): void
{
foreach ($this->retrieveBehaviors as $behavior) {
$behavior->retrieve($model);
Expand All @@ -98,8 +102,10 @@
* Apply all persist behaviors on the given model
*
* @param Model $model
*
* @return void
*/
public function persist(Model $model)
public function persist(Model $model): void
{
foreach ($this->persistBehaviors as $behavior) {
$behavior->persist($model);
Expand All @@ -114,7 +120,7 @@
*
* @return mixed
*/
public function retrieveProperty($value, $key)
public function retrieveProperty(mixed $value, string $key): mixed
{
foreach ($this->propertyBehaviors as $behavior) {
$value = $behavior->retrieveProperty($value, $key);
Expand All @@ -131,7 +137,7 @@
*
* @return mixed
*/
public function persistProperty($value, $key)
public function persistProperty(mixed $value, string $key): mixed
{
foreach ($this->propertyBehaviors as $behavior) {
$value = $behavior->persistProperty($value, $key);
Expand All @@ -144,11 +150,11 @@
* Rewrite the given filter condition
*
* @param Filter\Condition $condition
* @param string $relation Absolute path (with a trailing dot) of the model
* @param ?string $relation Absolute path (with a trailing dot) of the model
*
* @return Filter\Rule|null
*/
public function rewriteCondition(Filter\Condition $condition, $relation = null)
public function rewriteCondition(Filter\Condition $condition, ?string $relation = null): ?Filter\Rule
{
$filter = null;
foreach ($this->rewriteFilterBehaviors as $behavior) {
Expand All @@ -164,12 +170,12 @@
/**
* Rewrite the given relation path
*
* @param string $path
* @param string $relation Absolute path of the model
* @param string $path
* @param ?string $relation Absolute path of the model
*
* @return string|null
*/
public function rewritePath($path, $relation = null)
public function rewritePath(string $path, ?string $relation = null): ?string
{
$newPath = null;
foreach ($this->rewritePathBehaviors as $behavior) {
Expand All @@ -185,12 +191,12 @@
/**
* Rewrite the given column
*
* @param string $column
* @param string $relation Absolute path of the model
* @param string $column
* @param ?string $relation Absolute path of the model
*
* @return mixed
*/
public function rewriteColumn($column, $relation = null)
public function rewriteColumn(string $column, ?string $relation = null): mixed
{
$newColumn = null;
foreach ($this->rewriteColumnBehaviors as $behavior) {
Expand Down
13 changes: 7 additions & 6 deletions src/ColumnDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace ipl\Orm;

use InvalidArgumentException;
use LogicException;

class ColumnDefinition
{
/** @var string The name of the column */
protected $name;
protected string $name;

/** @var ?string The label of the column */
protected $label;
protected ?string $label = null;

/**
* Create a new column definition
Expand Down Expand Up @@ -50,7 +49,7 @@
*
* @return $this
*/
public function setLabel(?string $label): self
public function setLabel(?string $label): static
{
$this->label = $label;

Expand All @@ -62,9 +61,11 @@
*
* @param array $options
*
* @return self
* @return static
*
* @throws InvalidArgumentException If the given options do not provide a name
*/
public static function fromArray(array $options): self
public static function fromArray(array $options): static
{
if (! isset($options['name'])) {
throw new InvalidArgumentException('$options must provide a name');
Expand All @@ -72,7 +73,7 @@

$self = new static($options['name']);
if (isset($options['label'])) {
$self->setLabel($options['label']);

Check failure on line 76 in src/ColumnDefinition.php

View workflow job for this annotation

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

Parameter #1 $label of method ipl\Orm\ColumnDefinition::setLabel() expects string|null, mixed given.

Check failure on line 76 in src/ColumnDefinition.php

View workflow job for this annotation

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

Parameter #1 $label of method ipl\Orm\ColumnDefinition::setLabel() expects string|null, mixed given.

Check failure on line 76 in src/ColumnDefinition.php

View workflow job for this annotation

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

Parameter #1 $label of method ipl\Orm\ColumnDefinition::setLabel() expects string|null, mixed given.

Check failure on line 76 in src/ColumnDefinition.php

View workflow job for this annotation

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

Parameter #1 $label of method ipl\Orm\ColumnDefinition::setLabel() expects string|null, mixed given.
}

return $self;
Expand Down
7 changes: 4 additions & 3 deletions src/Common/PropertiesWithDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

use Closure;
use Traversable;
use ipl\Stdlib\Properties;

trait PropertiesWithDefaults
{
use \ipl\Stdlib\Properties {
\ipl\Stdlib\Properties::getProperty as private parentGetProperty;
use Properties {
Properties::getProperty as private parentGetProperty;
}

protected function getProperty($key)
protected function getProperty(string $key): mixed
{
if (isset($this->properties[$key]) && $this->properties[$key] instanceof Closure) {
$this->setProperty($key, $this->properties[$key]($this, $key));
Expand Down
16 changes: 8 additions & 8 deletions src/Common/SortUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
/**
* Create the sort column(s) and direction(s) from the given sort spec
*
* @param array|string $sort
* @param string|array $sort
*
* @return array<int, mixed> Sort column(s) and direction(s) suitable for {@link OrderByInterface::orderBy()}
*/
public static function createOrderBy($sort): array
public static function createOrderBy(string|array $sort): array
{
$columnsAndDirections = static::explodeSortSpec($sort);
$orderBy = [];

foreach ($columnsAndDirections as $columnAndDirection) {
list($column, $direction) = static::splitColumnAndDirection($columnAndDirection);
[$column, $direction] = static::splitColumnAndDirection($columnAndDirection);

Check failure on line 22 in src/Common/SortUtil.php

View workflow job for this annotation

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

Parameter #1 $sort of static method ipl\Orm\Common\SortUtil::splitColumnAndDirection() expects string, mixed given.

Check failure on line 22 in src/Common/SortUtil.php

View workflow job for this annotation

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

Parameter #1 $sort of static method ipl\Orm\Common\SortUtil::splitColumnAndDirection() expects string, mixed given.

Check failure on line 22 in src/Common/SortUtil.php

View workflow job for this annotation

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

Parameter #1 $sort of static method ipl\Orm\Common\SortUtil::splitColumnAndDirection() expects string, mixed given.

Check failure on line 22 in src/Common/SortUtil.php

View workflow job for this annotation

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

Parameter #1 $sort of static method ipl\Orm\Common\SortUtil::splitColumnAndDirection() expects string, mixed given.

$orderBy[] = [$column, $direction];
}
Expand All @@ -30,23 +30,23 @@
/**
* Explode the given sort spec into its sort parts
*
* @param array|string $sort
* @param string|array $sort
*
* @return array
*/
public static function explodeSortSpec($sort)
public static function explodeSortSpec(string|array $sort): array
{
return Str::trimSplit(implode(',', (array) $sort));
}

/**
* Normalize the given sort spec to a sort string
*
* @param array|string $sort
* @param string|array $sort
*
* @return string
*/
public static function normalizeSortSpec($sort)
public static function normalizeSortSpec(string|array $sort): string
{
return implode(',', static::explodeSortSpec($sort));
}
Expand All @@ -58,7 +58,7 @@
*
* @return array
*/
public static function splitColumnAndDirection($sort)
public static function splitColumnAndDirection(string $sort): array
{
return Str::symmetricSplit($sort, ' ', 2);
}
Expand Down
Loading
Loading