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
13 changes: 4 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ jobs:
fail-fast: false
matrix:
php: [
7.0,
7.1,
7.2,
7.3,
7.4,
8.0,
8.1
]
composer: [basic]
include:
- php: 7.3
- php: 8.0
composer: lowest
timeout-minutes: 10
steps:
Expand All @@ -44,10 +39,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 +89,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
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
}
],
"require": {
"php": ">=7.0.0",
"php": ">=8.0.0",
"ext-json": "*",
"symfony/polyfill-mbstring": "~1.0",
"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": "^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 @@ -276,7 +276,7 @@

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

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 @@ -316,13 +316,13 @@
) {
$this->array[$key][] = $value;
} else {
$this->array[$key] = $value;

Check failure on line 319 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Array (array<TKey of (int|string), T>) does not accept key int|string.
}
} else {
$this->array[] = $value;

Check failure on line 322 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Array (array<TKey of (int|string), T>) does not accept key int.
}

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 $this(Arrayy\Arrayy<TKey of (int|string), T>).
}

/**
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 $this(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 $this(Arrayy\Arrayy<TKey of (int|string), T>).
}

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

\natsort($this->array);

return $this;

Check failure on line 680 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

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

/**
Expand All @@ -698,7 +698,7 @@
*/
$that->natsort();

return $that;

Check failure on line 701 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, basic)

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

/**
Expand Down Expand Up @@ -731,7 +731,7 @@
* @psalm-suppress InvalidScalarArgument
*/
if (
$this->pathSeparator

Check failure on line 734 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Left side of && is always true.
&&
(string) $offset === $offset
&&
Expand Down Expand Up @@ -800,7 +800,7 @@
$this->checkType(null, $value);
}

$this->array[] = $value;

Check failure on line 803 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Array (array<TKey of (int|string), T>) does not accept key int.
} else {
$this->internalSet(
$offset,
Expand Down Expand Up @@ -840,7 +840,7 @@
* @psalm-suppress InvalidScalarArgument
*/
if (
$this->pathSeparator

Check failure on line 843 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Left side of && is always true.
&&
(string) $offset === $offset
&&
Expand Down Expand Up @@ -1076,12 +1076,12 @@
}
} else {
foreach ($values as $value) {
$this->array[$key] = $value;

Check failure on line 1079 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Array (array<TKey of (int|string), T>) does not accept key int|string.
}
}
} else {
foreach ($values as $value) {
$this->array[] = $value;

Check failure on line 1084 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Array (array<TKey of (int|string), T>) does not accept key int.
}
}

Expand Down Expand Up @@ -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 @@ -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 @@ -2645,10 +2645,10 @@
* @psalm-suppress MissingClosureReturnType
* @psalm-suppress MissingClosureParamType
*/
public function filterBy(

Check failure on line 2648 in src/Arrayy.php

View workflow job for this annotation

GitHub Actions / tests (8, lowest)

Method Arrayy\Arrayy::filterBy() has parameter $value with no value type specified in iterable type array.
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([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