- Some minors adjustments to match PHP 8.x coding styles

This commit is contained in:
Dave M. 2023-11-01 09:55:19 -04:00
parent 3736fbe0f6
commit fed7d2e302
4 changed files with 23 additions and 19 deletions

View File

@ -62,7 +62,7 @@ trait EntityTrait {
$data = json_decode($value, true); $data = json_decode($value, true);
if (json_last_error() !== \JSON_ERROR_NONE) { if (json_last_error() !== \JSON_ERROR_NONE) {
throw new \Exception(sprintf("JSON error while decoding in EntityTrait : '%s' given %s with field %s", json_last_error_msg(), $value, json_encode($field))); throw new \Exception(sprintf("JSON error while decoding in EntityTrait : '%s' given %s", json_last_error_msg(), $value));
} }
$this->{$field['name']} = $data; $this->{$field['name']} = $data;
@ -123,11 +123,9 @@ trait EntityTrait {
public function resetVirtualProperties() : self public function resetVirtualProperties() : self
{ {
foreach($this->resolveEntity()->properties as $prop => $property) { foreach($this->resolveEntity()->properties as $prop => $property) {
if ( empty($property['builtin']) ) { foreach($property['tags'] as $tag) {
foreach($property['tags'] as $tag) { if ( in_array(strtolower($tag['tag']), [ 'relation', 'join', 'virtual' ] ) ) {
if ( in_array(strtolower($tag['tag']), [ 'relation', 'join', 'virtual' ] ) ) { unset($this->$prop);
unset($this->$prop);
}
} }
} }
} }

View File

@ -16,7 +16,7 @@ class Where extends Fragment {
const COMPARISON_IS = "IS"; const COMPARISON_IS = "IS";
const COMPARISON_NULL = "NULL"; const COMPARISON_NULL = "NULL";
const SQL_TOKEN = "WHERE"; const SQL_TOKEN = "WHERE";
public int $order = 50; public int $order = 50;
@ -35,7 +35,7 @@ class Where extends Fragment {
$this->parent = $queryBuilder->where ?? null; $this->parent = $queryBuilder->where ?? null;
} }
public function add($field, $value, string $operator, string $condition, bool $not = false) : self public function add($field, mixed $value, string $operator, string $condition, bool $not = false) : self
{ {
$this->validateFieldType($field); $this->validateFieldType($field);
# $this->validateValueType($value); # $this->validateValueType($value);
@ -73,7 +73,7 @@ class Where extends Fragment {
]); ]);
} }
protected function whereCondition($field, $value, string $operator = self::OPERATOR_EQUAL, string $condition = self::CONDITION_AND, bool $not = false) { protected function whereCondition($field, mixed $value, string $operator = self::OPERATOR_EQUAL, string $condition = self::CONDITION_AND, bool $not = false) {
return new class($this->queryBuilder, $field, $value, $operator, $condition, $not) { return new class($this->queryBuilder, $field, $value, $operator, $condition, $not) {
public mixed $value; public mixed $value;
@ -123,7 +123,7 @@ class Where extends Fragment {
$stack = []; $stack = [];
if ($this->value) { if ($this->value) {
foreach ($this->value as $item) { foreach($this->value as $item) {
$stack[] = $this->filterValue($item); $stack[] = $this->filterValue($item);
} }
} }

View File

@ -198,9 +198,9 @@ class QueryBuilder implements Query\QueryBuilderInterface
public function where(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL, string $condition = Query\Where::CONDITION_AND, bool $not = false) : self public function where(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL, string $condition = Query\Where::CONDITION_AND, bool $not = false) : self
{ {
# Empty IN case # Empty IN case
#if ( [] === $value ) { # if ( [] === $value ) {
# return $this; # return $this;
#} # }
if ( $this->where ?? false ) { if ( $this->where ?? false ) {
$where = $this->where; $where = $this->where;

View File

@ -47,7 +47,7 @@ class RelationBuilder
} }
} }
public function searchRelation(string $name) : object|bool public function searchRelation(string $name) : mixed
{ {
# Resolve relations here if one is called # Resolve relations here if one is called
if ( $this->entity->isLoaded() ) { if ( $this->entity->isLoaded() ) {
@ -55,7 +55,13 @@ class RelationBuilder
return $dataset; return $dataset;
} }
return $this->resolveRelation($name) ?: $this->resolveVirtual($name) ?: false; if ( false !== $value = $this->resolveRelation($name) ) {
return $value;
}
elseif ( false !== $value = $this->resolveVirtual($name) ) {
return $value;
}
} }
else { else {
if ( $relation = $this->resolver->searchFieldAnnotation($name, [ Attribute\Property\Relation::class , Relation::class ] ) ) { if ( $relation = $this->resolver->searchFieldAnnotation($name, [ Attribute\Property\Relation::class , Relation::class ] ) ) {
@ -69,7 +75,7 @@ class RelationBuilder
return false; return false;
} }
protected function resolveVirtual(string $name) : bool|object protected function resolveVirtual(string $name) : mixed
{ {
if (null !== ($virtual = $this->resolver->searchFieldAnnotation($name, [ Attribute\Property\Virtual::class, Annotation\Property\Virtual::class ]))) { if (null !== ($virtual = $this->resolver->searchFieldAnnotation($name, [ Attribute\Property\Virtual::class, Annotation\Property\Virtual::class ]))) {
if ($virtual->closure ?? false) { if ($virtual->closure ?? false) {
@ -82,7 +88,7 @@ class RelationBuilder
return false; return false;
} }
protected function resolveRelation(string $name) : bool|object protected function resolveRelation(string $name) : mixed
{ {
if ( null !== ( $relation = $this->resolver->searchFieldAnnotation($name, [ Attribute\Property\Relation::class, Relation::class ] ) ) ) { if ( null !== ( $relation = $this->resolver->searchFieldAnnotation($name, [ Attribute\Property\Relation::class, Relation::class ] ) ) ) {
$this->orders = $this->resolver->searchFieldAnnotationList($name, [ Attribute\Property\OrderBy::class, OrderBy::class ] ); $this->orders = $this->resolver->searchFieldAnnotationList($name, [ Attribute\Property\OrderBy::class, OrderBy::class ] );
@ -109,14 +115,14 @@ class RelationBuilder
$this->entity->eventExecute(Event\EntityRelationLoadInterface::class, $name, $this->repository); $this->entity->eventExecute(Event\EntityRelationLoadInterface::class, $name, $this->repository);
return call_user_func([ $this->repository, $relation->function() ]); return call_user_func([ $this->repository, $relation->function() ]);
case $relation->isManyToMany(): case $relation->isManyToMany():
$this->manyToMany($name, $relation, $relationRelation); $this->manyToMany($name, $relation, $relationRelation);
$this->entity->eventExecute(Event\EntityRelationLoadInterface::class, $name, $this->repository); $this->entity->eventExecute(Event\EntityRelationLoadInterface::class, $name, $this->repository);
$results = call_user_func([ $this->repository, 'loadAll' ]); $results = call_user_func([ $this->repository, $relationRelation->function() ]);
if ($relation->bridgeField ?? false) { if ($relation->bridgeField ?? false) {
$collection = $relation->bridge::entityCollection(); $collection = $relation->bridge::entityCollection();