Skip to content

Commit

Permalink
Merge 846c04d into f015e26
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] committed Feb 5, 2023
2 parents f015e26 + 846c04d commit 129b8a1
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"marc-mabe/php-enum": "~4.6",
"mockery/mockery": ">=1.5.1",
"phpstan/extension-installer": "1.2.0",
"phpstan/phpstan": "1.8.0",
"phpstan/phpstan": "1.9.14",
"phpstan/phpstan-deprecation-rules": "1.0.0",
"phpstan/phpstan-nette": "1.1.0",
"phpstan/phpstan-mockery": "1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/ArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function fetchChecked(): IEntity

public function fetchAll()
{
return iterator_to_array($this->getIterator());
return iterator_to_array($this->getIterator(), preserve_keys: false);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Collection/DbalCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function fetchChecked(): IEntity

public function fetchAll()
{
return iterator_to_array($this->getIterator());
return iterator_to_array($this->getIterator(), preserve_keys: false);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Functions/IArrayFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface IArrayFunction
* Returns a value depending on values of entity; the expression passed by args is evaluated during this method
* execution.
* Usually returns a boolean for filtering evaluation.
* @phpstan-param array<int|string, mixed> $args
* @phpstan-param array<mixed> $args
* @phpstan-param IArrayAggregator<mixed>|null $aggregator
*/
public function processArrayExpression(
Expand Down
4 changes: 2 additions & 2 deletions src/Collection/Functions/JunctionFunctionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait JunctionFunctionTrait
{
/**
* Normalizes directly entered column => value expression to expression array.
* @phpstan-param array<string, mixed>|list<mixed> $args
* @phpstan-param array<mixed> $args
* @phpstan-return array{list<mixed>, IAggregator|null}
*/
protected function normalizeFunctions(array $args): array
Expand Down Expand Up @@ -54,7 +54,7 @@ protected function normalizeFunctions(array $args): array

/**
* @param literal-string $dbalModifier either %or or %and dbal modifier
* @param array<int|string, mixed> $args
* @param array<mixed> $args
*/
protected function processQueryBuilderExpressionWithModifier(
string $dbalModifier,
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/HasManyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function fetchChecked(): IEntity

public function fetchAll()
{
return iterator_to_array($this->getIterator());
return iterator_to_array($this->getIterator(), preserve_keys: false);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Helpers/ArrayCollectionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(IRepository $repository)


/**
* @phpstan-param array<string, mixed>|list<mixed> $expr
* @phpstan-param array<mixed> $expr
* @phpstan-param IArrayAggregator<mixed>|null $aggregator
* @phpstan-return Closure(IEntity): ArrayPropertyValueReference
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Collection/Helpers/ConditionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function array_shift;
use function explode;
use function is_subclass_of;
use function PHPStan\dumpType;
use function preg_match;
use function strpos;
use function trigger_error;
Expand All @@ -29,7 +30,6 @@ class ConditionParser
// language=PhpRegExp
protected const PATH_REGEXP = '(?:([\w\\\]+)::)?([\w\\\]++(?:->\w++)*+)';


/**
* @return array{class-string, string}
*/
Expand Down Expand Up @@ -78,6 +78,7 @@ public function parsePropertyExpr(string $propertyPath): array

/** @var string $source */
$source = array_shift($matches);
assert(count($matches) > 0);
$tokens = explode('->', array_shift($matches));

if ($source === '') {
Expand Down
11 changes: 6 additions & 5 deletions src/Collection/Helpers/DbalExpressionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Nextras\Orm\Entity\Reflection\PropertyMetadata;
use Nextras\Orm\Exception\InvalidArgumentException;
use function array_unshift;
use function array_values;


/**
Expand Down Expand Up @@ -77,12 +78,12 @@ class DbalExpressionResult


/**
* @phpstan-param literal-string $expression
* @param mixed[] $args
* @param DbalJoinEntry[] $joins
* @param array<array<mixed>> $groupBy
* @phpstan-param list<mixed> $args
* @param bool $isHavingClause
* @phpstan-param literal-string $expression
* @phpstan-param list<mixed> $args
* @phpstan-param literal-string $dbalModifier
*/
public function __construct(
Expand Down Expand Up @@ -117,11 +118,11 @@ public function __construct(
* Appends SQL expression to the original expression.
* If you need prepend or other complex expression, create new instance of DbalExpressionResult.
* @phpstan-param literal-string $expression
* @phpstan-param list<mixed> $args
* @phpstan-param mixed ...$args
*/
public function append(string $expression, ...$args): DbalExpressionResult
{
$args = array_merge($this->args, $args);
$args = array_values(array_merge($this->args, $args));
return $this->withArgs("{$this->expression} $expression", $args);
}

Expand All @@ -143,7 +144,7 @@ public function getArgumentsForExpansion(): array
* Creates a new DbalExpression from the passed $args and keeps the original expression
* properties (joins, aggregator, ...).
* @phpstan-param literal-string $expression
* @param array<mixed> $args
* @param list<mixed> $args
*/
public function withArgs(string $expression, array $args): DbalExpressionResult
{
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Helpers/DbalQueryBuilderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function processFilterFunction(


/**
* @phpstan-return array{string, list<mixed>}
* @phpstan-return list<mixed>
*/
public function processOrderDirection(DbalExpressionResult $expression, string $direction): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/ICollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function getByIdChecked($id): IEntity;
* ['property' => 'value2'],
* ]
* </code>
* @phpstan-param array<string, mixed>|array<int|string, mixed>|list<mixed> $conds
* @phpstan-param array<mixed> $conds
* @return static
*/
public function findBy(array $conds): ICollection;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Reflection/MetadataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected function parseAnnotations(ReflectionClass $reflection, array $methods)
$isReadonly = $access === '-read';

$property = new PropertyMetadata();
$property->name = (string) $variable;
$property->name = $variable;
$property->isReadonly = $isReadonly;

$this->parseAnnotationTypes($property, $type);
Expand Down
6 changes: 5 additions & 1 deletion src/Relationships/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Nextras\Orm\Exception\LogicException;
use Nextras\Orm\Mapper\IRelationshipMapper;
use Nextras\Orm\Repository\IRepository;
use function array_values;
use function assert;
use function is_array;
use function iterator_count;
Expand Down Expand Up @@ -113,10 +114,13 @@ public function convertToRawValue($value)
}


/**
* @param list<E>|list<string>|list<int>|mixed $value
*/
public function setRawValue($value): void
{
if (is_array($value)) {
$this->set($value);
$this->set(array_values($value));
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Repository/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use Nextras\Orm\Model\IModel;
use Nextras\Orm\Model\MetadataStorage;
use ReflectionClass;
use function array_values;
use function count;
use function sort;

Expand Down Expand Up @@ -260,7 +261,7 @@ public function findBy(array $conds): ICollection


/**
* @param array<mixed>|mixed $ids
* @param list<mixed>|mixed $ids
* @return ICollection<E>
* @deprecated Use {@see findByIds()}.
*/
Expand All @@ -269,7 +270,7 @@ public function findById($ids): ICollection
if (!is_array($ids)) {
return $this->findByIds([$ids]);
} else {
return $this->findByIds($ids);
return $this->findByIds(array_values($ids));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/cases/unit/Collection/ArrayCollectionTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ArrayCollectionTest extends TestCase
public function testPassingNonList(): void
{
Assert::throws(function (): void {
new ArrayCollection([
new ArrayCollection([ // @phpstan-ignore-line
1 => $this->e(Author::class),
], $this->orm->authors);
}, InvalidArgumentException::class);
Expand Down
3 changes: 2 additions & 1 deletion tests/cases/unit/Entity/AbstractEntity.getters_setters.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace NextrasTests\Orm\Entity\Fragments;

use Mockery;
use Nextras\Orm\Entity\AbstractEntity;
use Nextras\Orm\Entity\Entity;
use Nextras\Orm\Entity\Reflection\EntityMetadata;
use Nextras\Orm\Entity\Reflection\PropertyMetadata;
use NextrasTests\Orm\TestCase;
Expand All @@ -21,7 +22,7 @@ require_once __DIR__ . '/../../../bootstrap.php';
/**
* @property string|null $isMain
*/
class GetterSetterTestEntity extends AbstractEntity
class GetterSetterTestEntity extends Entity
{
protected function createMetadata(): EntityMetadata
{
Expand Down

0 comments on commit 129b8a1

Please sign in to comment.