Skip to content
Merged
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
22 changes: 2 additions & 20 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
parameters:
level: 8
reportUnmatchedIgnoredErrors: false
reportUnmatchedIgnoredErrors: true
paths:
- %currentWorkingDirectory%/src/
- %currentWorkingDirectory%/tests/
ignoreErrors:
-
message: ~has no return type specified~
identifier: missingType.return
path: %currentWorkingDirectory%/tests/*
-
message: '#assertContains|assertInternalType|assertStringContainsString|assertIsArray|expectExceptionMessage#'
path: %currentWorkingDirectory%/tests/*
-
message: ~Call to an undefined static method~
path: %currentWorkingDirectory%/tests/StaticArrayyTest.php
# false-positive?
- '/function call_user_func expects callable.*array\{.*\} given/'
- '/function call_user_func_array expects callable.*array\{.*\} given/'
- '/\(array<TKey of \(int\|string\), T>\) does not accept array<TKey of \(int\|string\)/'
- '/\(array<TKey of \(int\|string\), T>\) does not accept array<int, T>/'
- '/\(array<TKey of \(int\|string\), T>\) does not accept array<int\|string, T>/'
- '/array_map expects \(callable\(mixed\):/'
# ignore gernal errors
- '/Unsafe usage of new static/'
- '/should be compatible with return type \(bool\) of method ArrayObject/'
# ignore Iterator stuff
- '/__construct\(\) has parameter \$iteratorClass with generic/'
- '/create\(\) has parameter \$iteratorClass with generic/'
- '/parameter \$iteratorClass with generic class Arrayy\\ArrayyIterator/'
- '/generic class Arrayy\\ArrayyIterator does not specify its types/'
26 changes: 13 additions & 13 deletions src/Arrayy.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
/**
* @var string
*
* @phpstan-var class-string<\Arrayy\ArrayyIterator>
* @phpstan-var class-string<\Arrayy\ArrayyIterator<TKey,T>>
*/
protected $iteratorClass = ArrayyIterator::class;

Expand Down Expand Up @@ -111,7 +111,7 @@
* true, otherwise this option didn't not work anyway.
* </p>
*
* @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<TKey,T>> $iteratorClass
*/
public function __construct(
$data = [],
Expand Down Expand Up @@ -274,9 +274,9 @@
);
}

$this->internalSet($key, $value);

Check failure on line 277 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Parameter #2 $value of method Arrayy\Arrayy<TKey of (int|string),T>::internalSet() expects T, array|T given.

Check failure on line 277 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

Parameter #2 $value of method Arrayy\Arrayy<TKey of (int|string),T>::internalSet() expects T, array|T given.

return $this;

Check failure on line 279 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

Method Arrayy\Arrayy::add() should return static(Arrayy\Arrayy<TKey of (int|string), T>) but returns $this(Arrayy\Arrayy<TKey of (int|string), T>).
}

return $this->append($value);
Expand Down Expand Up @@ -314,7 +314,7 @@
&&
\is_array($this->array[$key])
) {
$this->array[$key][] = $value;
$this->array[$key][] = $value; // @phpstan-ignore assign.propertyType
} else {
$this->array[$key] = $value;
}
Expand All @@ -322,7 +322,7 @@
$this->array[] = $value;
}

return $this;

Check failure on line 325 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

Method Arrayy\Arrayy::append() should return static(Arrayy\Arrayy<TKey of (int|string), T>) but returns $this(Arrayy\Arrayy<TKey of (int|string), T>).
}

/**
Expand Down Expand Up @@ -392,7 +392,7 @@

\asort($this->array, $sort_flags);

return $this;

Check failure on line 395 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

Method Arrayy\Arrayy::asort() should return static(Arrayy\Arrayy<TKey of (int|string), T>) but returns $this(Arrayy\Arrayy<TKey of (int|string), T>).
}

/**
Expand All @@ -419,7 +419,7 @@
*/
$that->asort($sort_flags);

return $that;

Check failure on line 422 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

Method Arrayy\Arrayy::asortImmutable() should return static(Arrayy\Arrayy<TKey of (int|string), T>) but returns static(Arrayy\Arrayy<TKey of (int|string), T>).
}

/**
Expand Down Expand Up @@ -473,7 +473,7 @@
return \iterator_count($this->generator);
}

return \count($this->toArray(), $mode);

Check failure on line 476 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Parameter #2 $mode of function count expects 0|1, int given.

Check failure on line 476 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

Parameter #2 $mode of function count expects 0|1, int given.
}

/**
Expand Down Expand Up @@ -594,7 +594,7 @@

\ksort($this->array, $sort_flags);

return $this;

Check failure on line 597 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

Method Arrayy\Arrayy::ksort() should return static(Arrayy\Arrayy<TKey of (int|string), T>) but returns $this(Arrayy\Arrayy<TKey of (int|string), T>).
}

/**
Expand All @@ -620,7 +620,7 @@
*/
$that->ksort($sort_flags);

return $that;

Check failure on line 623 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

Method Arrayy\Arrayy::ksortImmutable() should return static(Arrayy\Arrayy<TKey of (int|string), T>) but returns static(Arrayy\Arrayy<TKey of (int|string), T>).
}

/**
Expand All @@ -638,7 +638,7 @@

\natcasesort($this->array);

return $this;

Check failure on line 641 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

Method Arrayy\Arrayy::natcasesort() should return static(Arrayy\Arrayy<TKey of (int|string), T>) but returns $this(Arrayy\Arrayy<TKey of (int|string), T>).
}

/**
Expand All @@ -659,7 +659,7 @@
*/
$that->natcasesort();

return $that;

Check failure on line 662 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

Method Arrayy\Arrayy::natcasesortImmutable() should return static(Arrayy\Arrayy<TKey of (int|string), T>) but returns static(Arrayy\Arrayy<TKey of (int|string), T>).
}

/**
Expand Down Expand Up @@ -738,7 +738,7 @@
\strpos($offset, $this->pathSeparator) !== false
) {
$explodedPath = \explode($this->pathSeparator, (string) $offset);
if ($explodedPath !== false) {

Check failure on line 741 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Strict comparison using !== between non-empty-list<string> and false will always evaluate to true.
/** @var string $lastOffset - helper for phpstan */
$lastOffset = \array_pop($explodedPath);
$containerPath = \implode($this->pathSeparator, $explodedPath);
Expand Down Expand Up @@ -848,7 +848,7 @@
) {
$path = \explode($this->pathSeparator, (string) $offset);

if ($path !== false) {

Check failure on line 851 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Strict comparison using !== between non-empty-list<string> and false will always evaluate to true.
$pathToUnset = \array_pop($path);

/**
Expand Down Expand Up @@ -884,7 +884,7 @@
{
$this->generatorToArray();

if (\PHP_VERSION_ID < 70400) {

Check failure on line 887 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Comparison operation "<" between int<80000, 80499> and 70400 is always false.
return parent::serialize();
}

Expand All @@ -900,7 +900,7 @@
*
* @return void
*
* @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<TKey,T>> $iteratorClass
*/
#[\ReturnTypeWillChange]
public function setIteratorClass($iteratorClass)
Expand Down Expand Up @@ -943,7 +943,7 @@
#[\ReturnTypeWillChange]
public function uasort($callable): self
{
if (!\is_callable($callable)) {

Check failure on line 946 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Call to function is_callable() with callable(T, T): int will always evaluate to true.
throw new \InvalidArgumentException('Passed function must be callable');
}

Expand Down Expand Up @@ -1035,7 +1035,7 @@
#[\ReturnTypeWillChange]
public function unserialize($string): self
{
if (\PHP_VERSION_ID < 70400) {

Check failure on line 1038 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Comparison operation "<" between int<80000, 80499> and 70400 is always false.
parent::unserialize($string);

return $this;
Expand Down Expand Up @@ -1734,7 +1734,7 @@
* @return static
* <p>(Immutable) Returns an new instance of the Arrayy object.</p>
*
* @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<TKey,T>> $iteratorClass
* @phpstan-return static<TKey,T>
* @psalm-mutation-free
*/
Expand All @@ -1743,7 +1743,7 @@
string $iteratorClass = ArrayyIterator::class,
bool $checkPropertiesInConstructor = true
) {
return new static(
return new static( // @phpstan-ignore new.static
$data,
$iteratorClass,
$checkPropertiesInConstructor
Expand All @@ -1766,7 +1766,7 @@
*
* @return array
*/
public function flatten($delimiter = '.', $prepend = '', $items = null)

Check failure on line 1769 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Method Arrayy\Arrayy::flatten() return type has no value type specified in iterable type array.

Check failure on line 1769 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Method Arrayy\Arrayy::flatten() has parameter $items with no value type specified in iterable type array.
{
// init
$flatten = [];
Expand Down Expand Up @@ -1799,7 +1799,7 @@
* <p>(Mutable) Return this Arrayy object.</p>
*
* @phpstan-param array<TKey,T> $array
* @phpstan-return $this<TKey,T>

Check failure on line 1802 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

PHPDoc tag @phpstan-return has invalid value ($this<TKey,T>): Unexpected token "<", expected TOKEN_HORIZONTAL_WS at offset 265 on line 10
*
* @internal this will not check any types because it's set directly as reference
*/
Expand Down Expand Up @@ -1893,7 +1893,7 @@
public static function createFromObject(\Traversable $object): self
{
// init
$arrayy = new static();
$arrayy = static::create();

if ($object instanceof self) {
$objectArray = $object->getGenerator();
Expand Down Expand Up @@ -5050,7 +5050,7 @@
if ($key === null) {
\array_unshift($this->array, $value);
} else {
$this->array = [$key => $value] + $this->array;
$this->array = [$key => $value] + $this->array; // @phpstan-ignore assign.propertyType
}

return $this;
Expand Down Expand Up @@ -5241,7 +5241,7 @@
}
}

\array_push($this->array, ...$args);
\array_push($this->array, ...$args); // @phpstan-ignore assign.propertyType

return $this;
}
Expand Down Expand Up @@ -5391,7 +5391,7 @@

if ($number === null) {
$arrayRandValue = [$this->array[\array_rand($this->array)]];
$this->array = $arrayRandValue;
$this->array = $arrayRandValue; // @phpstan-ignore assign.propertyType

return $this;
}
Expand Down Expand Up @@ -5535,15 +5535,15 @@

foreach ($this->getGenerator() as $val) {
if (\is_array($val)) {
$result[] = (new static($val))->reduce_dimension($unique)->toArray();
$result[] = static::create($val)->reduce_dimension($unique)->toArray();
} else {
$result[] = [$val];
}
}

$result = $result === [] ? [] : \array_merge(...$result);

$resultArrayy = new static($result);
$resultArrayy = static::create($result);

/**
* @psalm-suppress ImpureMethodCall - object is already re-created
Expand Down Expand Up @@ -7157,7 +7157,7 @@
}
}

\array_unshift($this->array, ...$args);
\array_unshift($this->array, ...$args); // @phpstan-ignore assign.propertyType

return $this;
}
Expand Down
6 changes: 4 additions & 2 deletions src/ArrayyIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function current()
$value = parent::current();

if (\is_array($value)) {
$value = \call_user_func([$this->class, 'create'], $value, static::class, false);
$class = $this->class;
$value = $class::create($value, static::class, false);
}

return $value;
Expand All @@ -62,7 +63,8 @@ public function offsetGet($offset)
$value = parent::offsetGet($offset);

if (\is_array($value)) {
$value = \call_user_func([$this->class, 'create'], $value, static::class, false);
$class = $this->class;
$value = $class::create($value, static::class, false);
}

return $value;
Expand Down
3 changes: 2 additions & 1 deletion src/ArrayyRewindableExtendedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function current()
$value = $this->generator->current();

if (\is_array($value)) {
$value = \call_user_func([$this->class, 'create'], $value, static::class, false);
$class = $this->class;
$value = $class::create($value, static::class, false);
}

return $value;
Expand Down
6 changes: 3 additions & 3 deletions src/Collection/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class AbstractCollection extends Arrayy implements CollectionInterface
* </p>
*
* @phpstan-param array<TKey,T>|\Arrayy\Arrayy<TKey,T>|\Closure():array<TKey,T>|mixed $data
* @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<TKey,T>> $iteratorClass
*/
public function __construct(
$data = [],
Expand Down Expand Up @@ -263,7 +263,7 @@ public function merge(CollectionInterface ...$collections): self
* @template TKeyCreate as TKey
* @template TCreate as T
* @phpstan-param array<TKeyCreate,TCreate> $data
* @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<TKeyCreate,TCreate>> $iteratorClass
* @phpstan-return static<TKeyCreate,TCreate>
*
* @psalm-mutation-free
Expand All @@ -273,7 +273,7 @@ public static function create(
string $iteratorClass = ArrayyIterator::class,
bool $checkPropertiesInConstructor = true
) {
return new static(
return new static( // @phpstan-ignore new.static
$data,
$iteratorClass,
$checkPropertiesInConstructor
Expand Down
4 changes: 2 additions & 2 deletions src/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Collection extends AbstractCollection
* @param TypeInterface|null $type
*
* @phpstan-param array<array-key,T>|array<TKey,T>|\Arrayy\Arrayy<TKey,T> $data
* @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<TKey,T>> $iteratorClass
*/
public function __construct(
$data = [],
Expand Down Expand Up @@ -145,7 +145,7 @@ public static function construct(
): self {
$type = self::convertIntoTypeCheckArray($type);

return new static(
return new static( // @phpstan-ignore new.static
$data,
ArrayyIterator::class,
$checkPropertiesInConstructorAndType,
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function containsValueRecursive($value): bool;
* @template TKeyCreate as TKey
* @template TCreate as T
* @phpstan-param array<TKeyCreate,TCreate> $data
* @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<TKeyCreate,TCreate>> $iteratorClass
* @phpstan-return static<TKeyCreate,TCreate>
*
* @psalm-mutation-free
Expand Down
2 changes: 1 addition & 1 deletion src/StaticArrayy.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function __callStatic(string $name, $arguments)

$arrayy = Arrayy::create($array);

return \call_user_func_array([$arrayy, $name], $args);
return $arrayy->{$name}(...$args);
}

////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/Type/DetectFirstValueTypeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class DetectFirstValueTypeCollection extends Collection implements TypeInt
* @param bool $checkPropertiesInConstructor
*
* @phpstan-param array<TKey,T>|Arrayy<TKey,T> $data
* @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<TKey,T>> $iteratorClass
*/
public function __construct(
$data = [],
Expand Down
2 changes: 1 addition & 1 deletion src/Type/InstanceCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class InstanceCollection extends Collection implements TypeInterface
* @param string|null $className
*
* @phpstan-param array<TKey,T> $data
* @phpstan-param class-string<\Arrayy\ArrayyIterator>|null $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<TKey,T>>|null $iteratorClass
* @phpstan-param class-string<T>|null $className
*/
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Type/InstancesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class InstancesCollection extends Collection implements TypeInterface
* @param string[]|null $classNames
*
* @phpstan-param array<TKey,T> $data
* @phpstan-param class-string<\Arrayy\ArrayyIterator>|null $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<TKey,T>>|null $iteratorClass
* @phpstan-param array<class-string<T>>|null $classNames
*/
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/TypeCheck/TypeCheckArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TypeCheckArray extends \Arrayy\ArrayyStrict
* true, otherwise this option didn't not work anyway.
* </p>
*
* @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<TKey,T>> $iteratorClass
*/
public function __construct(
$data = [],
Expand Down
2 changes: 1 addition & 1 deletion tests/ModelA.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ModelA extends \Arrayy\Arrayy implements ModelInterface
* @param array $array
* @param string $iteratorClass
*
* @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass
* @phpstan-param class-string<\Arrayy\ArrayyIterator<array-key,mixed>> $iteratorClass
*/
public function __construct($array = [], $iteratorClass = ArrayyIterator::class)
{
Expand Down
10 changes: 5 additions & 5 deletions tests/StaticArrayyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ public function testBadMethodCall()

/** @noinspection PhpUndefinedMethodInspection */
/** @noinspection PhpUnusedLocalVariableInspection */
$result = A::invalidMethod('foo');
$result = A::invalidMethod('foo'); // @phpstan-ignore staticMethod.notFound
}

public function testEmptyArgsInvocation()
{
/** @noinspection PhpUndefinedMethodInspection */
$result = A::first();
$result = A::first(); // @phpstan-ignore staticMethod.notFound
static::assertNull($result);
}

public function testInvocation()
{
/** @noinspection PhpUndefinedMethodInspection */
$result = A::first(['lall', 'FOOBAR'], 1);
$result = A::first(['lall', 'FOOBAR'], 1); // @phpstan-ignore staticMethod.notFound
static::assertSame('lall', $result);
}

public function testPartialArgsInvocation()
{
/** @noinspection PhpUndefinedMethodInspection */
$result = A::replaceOneValue(['foo', 'bar'], 'foo');
$result = A::replaceOneValue(['foo', 'bar'], 'foo'); // @phpstan-ignore staticMethod.notFound
static::assertSame(['', 'bar'], $result->getArray());
}

public function testFullArgsInvocation()
{
/** @noinspection PhpUndefinedMethodInspection */
$result = A::replaceOneValue(['foo', 'bar'], 'foo', 'test');
$result = A::replaceOneValue(['foo', 'bar'], 'foo', 'test'); // @phpstan-ignore staticMethod.notFound
static::assertSame(['test', 'bar'], $result->getArray());
}

Expand Down