Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ jobs:
fail-fast: false
matrix:
php: [
7.0,
7.1,
7.2,
7.3,
7.4,
8.0,
Expand All @@ -44,10 +41,10 @@ jobs:

- name: Determine composer cache directory
id: composer-cache
run: echo "::set-output name=directory::$(composer config cache-dir)"
run: echo "directory=$(composer config cache-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v3.3.1
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.directory }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down Expand Up @@ -94,7 +91,7 @@ jobs:

- name: Archive logs artifacts
if: ${{ failure() }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: logs_composer-${{ matrix.composer }}_php-${{ matrix.php }}
path: |
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"phpdocumentor/reflection-docblock": "~4.3 || ~5.0"
},
"require-dev": {
"phpunit/phpunit": "~6.0 || ~7.0 || ~9.0"
"phpunit/phpunit": "~6.0 || ~7.0 || ~9.0",
"phpstan/phpstan": "*"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using "*" as a version constraint for phpstan/phpstan is not recommended as it can pull in major versions with breaking changes, potentially causing your CI/builds to fail unexpectedly. It's better to use a more restrictive constraint, for example "^1.0", to ensure stability.

Suggested change
"phpstan/phpstan": "*"
"phpstan/phpstan": "^1.0"

},
"support": {
"docs": "https://voku.github.io/Arrayy/",
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
parameters:
level: 8
reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: true
checkMissingIterableValueType: false
paths:
- %currentWorkingDirectory%/src/
- %currentWorkingDirectory%/tests/
Expand Down
23 changes: 12 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
Expand All @@ -13,12 +11,15 @@
<testsuite name="Arrayy Test Suite">
<directory>tests</directory>
</testsuite>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<junit outputFile="build/logs/junit.xml"/>
</logging>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
</phpunit>
34 changes: 17 additions & 17 deletions src/Arrayy.php
Original file line number Diff line number Diff line change
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, 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 @@ -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, 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 @@ -1941,7 +1941,7 @@
* @phpstan-return static<int,string>
* @psalm-mutation-free
*/
public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self
public static function createFromString(string $str, ?string $delimiter = null, ?string $regEx = null): self
{
if ($regEx) {
\preg_match_all($regEx, $str, $array);
Expand Down Expand Up @@ -2648,7 +2648,7 @@
public function filterBy(
string $property,
$value,
string $comparisonOp = null
?string $comparisonOp = null
): self {
if (!$comparisonOp) {
$comparisonOp = \is_array($value) ? 'contains' : 'eq';
Expand Down Expand Up @@ -2834,7 +2834,7 @@
* @phpstan-return static<TKey,T>
* @psalm-mutation-free
*/
public function firstsImmutable(int $number = null): self
public function firstsImmutable(?int $number = null): self
{
$arrayTmp = $this->toArray();

Expand Down Expand Up @@ -2863,7 +2863,7 @@
* @phpstan-return static<array-key,TKey>
* @psalm-mutation-free
*/
public function firstsKeys(int $number = null): self
public function firstsKeys(?int $number = null): self
{
$arrayTmp = $this->keys()->toArray();

Expand Down Expand Up @@ -2895,7 +2895,7 @@
*
* @phpstan-return ($number is null ? static<int,T> : static<TKey,T>)
*/
public function firstsMutable(int $number = null): self
public function firstsMutable(?int $number = null): self
{
$this->generatorToArray();

Expand Down Expand Up @@ -2972,7 +2972,7 @@
public function get(
$key = null,
$fallback = null,
array $array = null,
?array $array = null,
bool $useByReference = false
) {
if ($array === null && $key === null) {
Expand Down Expand Up @@ -4265,7 +4265,7 @@
* @phpstan-return static<TKey,T>
* @psalm-mutation-free
*/
public function lastsImmutable(int $number = null): self
public function lastsImmutable(?int $number = null): self
{
if ($this->isEmpty()) {
return static::create(
Expand Down Expand Up @@ -4310,7 +4310,7 @@
*
* @phpstan-return static<TKey,T>
*/
public function lastsMutable(int $number = null): self
public function lastsMutable(?int $number = null): self
{
if ($this->isEmpty()) {
return $this;
Expand Down Expand Up @@ -4724,7 +4724,7 @@
* @phpstan-return static<array-key,T>
* @psalm-mutation-free
*/
public function mostUsedValues(int $number = null): self
public function mostUsedValues(?int $number = null): self
{
return $this->countValues()->arsortImmutable()->firstsKeys($number);
}
Expand Down Expand Up @@ -5230,7 +5230,7 @@
*
* @phpstan-return static<array-key,T>
*/
public function randomImmutable(int $number = null): self
public function randomImmutable(?int $number = null): self
{
$this->generatorToArray();

Expand Down Expand Up @@ -5347,7 +5347,7 @@
*
* @phpstan-return static<TKey,T>
*/
public function randomMutable(int $number = null): self
public function randomMutable(?int $number = null): self
{
$this->generatorToArray();

Expand Down Expand Up @@ -5429,7 +5429,7 @@
* @phpstan-param array<(int&T)|(string&T),int> $array
* @phpstan-return static<array-key,T>
*/
public function randomWeighted(array $array, int $number = null): self
public function randomWeighted(array $array, ?int $number = null): self
{
// init
$options = [];
Expand Down Expand Up @@ -6248,7 +6248,7 @@
* @phpstan-param array<TKey,T> $array
* @phpstan-return static<TKey,T>
*/
public function shuffle(bool $secure = false, array $array = null): self
public function shuffle(bool $secure = false, ?array $array = null): self
{
if ($array === null) {
$array = $this->toArray(false);
Expand Down Expand Up @@ -6454,7 +6454,7 @@
* @phpstan-return static<array-key,T>
* @psalm-mutation-free
*/
public function slice(int $offset, int $length = null, bool $preserveKeys = false)
public function slice(int $offset, ?int $length = null, bool $preserveKeys = false)
{
return static::create(
\array_slice(
Expand Down Expand Up @@ -6719,7 +6719,7 @@
* @phpstan-return static<TKey,T>
* @psalm-mutation-free
*/
public function splice(int $offset, int $length = null, $replacement = []): self
public function splice(int $offset, ?int $length = null, $replacement = []): self
{
$tmpArray = $this->toArray();

Expand Down Expand Up @@ -6967,7 +6967,7 @@
*
* @phpstan-return static<int, static<TKey,T>>
*/
public function toPermutation(array $items = null, array $helper = []): self
public function toPermutation(?array $items = null, array $helper = []): self
{
// init
$return = [];
Expand Down Expand Up @@ -7891,7 +7891,7 @@
/**
* @psalm-suppress PossiblyInvalidArgument - the parameter is always some kind of array - false-positive from psalm?
*/
return \array_map(['static', 'objectToArray'], $object);
return \array_map(\Closure::fromCallable([static::class, 'objectToArray']), $object);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The use of \Closure::fromCallable() will cause a fatal error on PHP 7.0, as it was introduced in PHP 7.1. According to composer.json, this project still supports PHP 7.0.

To resolve this while maintaining compatibility, you can use [static::class, 'objectToArray'] which works on PHP 7.0 and is not deprecated.

        return \array_map([static::class, 'objectToArray'], $object);

}

/**
Expand Down
1 change: 1 addition & 0 deletions src/ArrayyMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Arrayy;

#[\AllowDynamicProperties]
final class ArrayyMeta
Comment on lines +7 to 8
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While #[AllowDynamicProperties] makes the code compatible with PHP 8.2, it's generally better to avoid dynamic properties for improved maintainability and type safety. Consider refactoring this class to use a private array for storing properties and leverage __get() and __set() magic methods to manage them. This would make the class structure more explicit and robust.

{
/** @noinspection MagicMethodsValidityInspection */
Expand Down
2 changes: 1 addition & 1 deletion src/ArrayyRewindableExtendedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ArrayyRewindableExtendedGenerator extends ArrayyRewindableGenerator
{
public function __construct(
callable $generatorConstructionFunction,
callable $onRewind = null,
?callable $onRewind = null,
string $class = ''
) {
parent::__construct(
Expand Down
2 changes: 1 addition & 1 deletion src/ArrayyRewindableGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ArrayyRewindableGenerator extends \ArrayIterator
*/
public function __construct(
callable $generatorConstructionFunction,
callable $onRewind = null,
?callable $onRewind = null,
string $class = ''
) {
$this->class = $class;
Expand Down
6 changes: 3 additions & 3 deletions src/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ class Collection extends AbstractCollection
*/
public function __construct(
$data = [],
string $iteratorClass = null,
bool $checkPropertiesInConstructor = null,
TypeInterface $type = null
?string $iteratorClass = null,
?bool $checkPropertiesInConstructor = null,
?TypeInterface $type = null
) {
// fallback
if ($iteratorClass === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public function set($key, $value);
*
* @phpstan-return CollectionInterface<array-key|TKey,T>
*/
public function slice(int $offset, int $length = null, bool $preserveKeys = false);
public function slice(int $offset, ?int $length = null, bool $preserveKeys = false);

/**
* Gets a native PHP array representation of the collection.
Expand Down
2 changes: 1 addition & 1 deletion src/StaticArrayy.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function __callStatic(string $name, $arguments)
* @psalm-suppress InvalidReturnStatement - why?
* @psalm-suppress InvalidReturnType - why?
*/
public static function range(int $base, int $stop = null, int $step = 1): Arrayy
public static function range(int $base, ?int $stop = null, int $step = 1): Arrayy
{
if ($stop !== null) {
$start = $base;
Expand Down
4 changes: 2 additions & 2 deletions src/Type/InstanceCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ final class InstanceCollection extends Collection implements TypeInterface
*/
public function __construct(
array $data = [],
string $iteratorClass = null,
bool $checkPropertiesInConstructor = null,
?string $iteratorClass = null,
?bool $checkPropertiesInConstructor = null,
$className = null
) {
// fallback
Expand Down
6 changes: 3 additions & 3 deletions src/Type/InstancesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ final class InstancesCollection extends Collection implements TypeInterface
*/
public function __construct(
array $data = [],
string $iteratorClass = null,
bool $checkPropertiesInConstructor = null,
array $classNames = null
?string $iteratorClass = null,
?bool $checkPropertiesInConstructor = null,
?array $classNames = null
) {
// fallback
if ($iteratorClass === null) {
Expand Down
Loading