Skip to content

Commit

Permalink
PHP 8.1 minimum version prep
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Mar 14, 2024
1 parent e774737 commit 4553f41
Show file tree
Hide file tree
Showing 19 changed files with 32 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
php: [8.2, 8.1]
php: [8.3, 8.2, 8.1]
# prefer-lowest is causing unit tests to fail when php 7.2 is run against PHPunit 7.x,
# PHPUnit 8.x is the latest stable release that supports PHP 7.2 and that runs fine
# dependency-version: [prefer-lowest, prefer-stable]
Expand All @@ -39,7 +39,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"phpunit/phpunit" : "^10.0",
"php-coveralls/php-coveralls" : "^2.0",
"symfony/polyfill-mbstring" : "^1.27",
"rector/rector" : "^0.18.0",
"rector/rector" : "^1.0.0",
"vimeo/psalm" : "^5.4.0"
},
"autoload" : {
Expand Down
7 changes: 2 additions & 5 deletions src/ArraysCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ public function __construct(array ...$arrays)
{
$this->versatile_collections_items = $arrays;
}

/**
* @param mixed $item
*/
public function checkType($item): bool

public function checkType(mixed $item): bool
{
return \is_array($item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/CallablesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(callable ...$callables)
$this->versatile_collections_items = $callables;
}

public function checkType($item): bool
public function checkType(mixed $item): bool
{
return \is_callable($item);
}
Expand Down
3 changes: 2 additions & 1 deletion src/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function __isset(string $key): bool;
*
* @title: Adds an item with a specified key to the collection.
*/
public function __set(string $key, $val): void;
public function __set(string $key, mixed $val): void;

/**
* Unset a key.
Expand Down Expand Up @@ -148,6 +148,7 @@ public function offsetGet(mixed $key): mixed;
*
* @title: Adds an item with a specified key to the collection.
*
* @psalm-suppress ParamNameMismatch
* @noinspection PhpParameterNameChangedDuringInheritanceInspection
*/
public function offsetSet($key, mixed $val): void;
Expand Down
5 changes: 3 additions & 2 deletions src/CollectionInterfaceImplementationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public function offsetGet(mixed $key):mixed
* @param string|int|null $key The requested key.
*
* @param mixed $val The value to set it to.
* @psalm-suppress ParamNameMismatch
*/
public function offsetSet($key, mixed $val): void
{
Expand Down Expand Up @@ -1320,13 +1321,12 @@ protected function performSort(
}

/**
* @psalm-suppress PossiblyInvalidArgument
* @psalm-suppress PossiblyInvalidIterator
* @psalm-suppress UnsupportedReferenceUsage
*
* @return mixed[]
*/
protected function performMultiSort(array $array_to_be_sorted, MultiSortParameters ...$param)
protected function performMultiSort(array $array_to_be_sorted, MultiSortParameters ...$param): array
{
if(\count($array_to_be_sorted) <= 0) {

Expand Down Expand Up @@ -1403,6 +1403,7 @@ protected function performMultiSort(array $array_to_be_sorted, MultiSortParamete

// last parameter is the array to be sorted
$multi_sort_args[] = &$array_to_be_sorted;
/** @psalm-suppress ArgumentTypeCoercion */
\array_multisort(...$multi_sort_args);
$sorted_array_with_preserved_keys_with_prefix = \array_pop($multi_sort_args);
$sorted_array_with_preserved_keys = [];
Expand Down
2 changes: 1 addition & 1 deletion src/FloatsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(float ...$numbers)
$this->versatile_collections_items = $numbers;
}

public function checkType($item): bool
public function checkType(mixed $item): bool
{
return \is_float($item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/IntsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(int ...$numbers)
$this->versatile_collections_items = $numbers;
}

public function checkType($item): bool
public function checkType(mixed $item): bool
{
return \is_int($item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/NonArrayIterablesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(iterable ...$iterableObjects)
parent::strictlyTypedCollectionTrait__construct(...$iterableObjects);
}

public function checkType($item): bool
public function checkType(mixed $item): bool
{
return parent::checkType($item) && \is_iterable($item);
}
Expand Down
6 changes: 2 additions & 4 deletions src/NumericsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ public function average(): ?float

/**
* This method should be overridden in sub-classes of this class
*
* @param mixed $item
*/
public function checkType($item): bool
public function checkType(mixed $item): bool
{
return \is_float($item) || \is_int($item);
}
Expand All @@ -64,7 +62,7 @@ public function getTypes(): StringsCollection
*
* @noinspection PhpMissingParamTypeInspection
*/
protected function itemFromString(string $str)
protected function itemFromString(string $str): float|int
{
if( str_contains($str, '.') ) {

Expand Down
2 changes: 1 addition & 1 deletion src/ObjectsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function __call(string $method_name, array $arguments=[])
}
}

public function checkType($item): bool
public function checkType(mixed $item): bool
{
return \is_object($item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ResourcesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ResourcesCollection implements StrictlyTypedCollectionInterface
{
use StrictlyTypedCollectionInterfaceImplementationTrait;

public function checkType($item): bool
public function checkType(mixed $item): bool
{
return \is_resource($item);
}
Expand Down
4 changes: 1 addition & 3 deletions src/ScalarsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class ScalarsCollection implements StrictlyTypedCollectionInterface

/**
* This method should be overridden in sub-classes of this class
*
* @param mixed $item
*/
public function checkType($item): bool
public function checkType(mixed $item): bool
{
return \is_scalar($item);
}
Expand Down
3 changes: 1 addition & 2 deletions src/SpecificObjectsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ public static function makeNewForSpecifiedClassName(?string $class_name=null, it
}

/**
* @param mixed $item
* @return bool true if $item is of the expected type, else false
*/
public function checkType($item): bool
public function checkType(mixed $item): bool
{
return \is_null($this->class_name)
? parent::checkType($item)
Expand Down
3 changes: 1 addition & 2 deletions src/StrictlyTypedCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
interface StrictlyTypedCollectionInterface extends CollectionInterface
{
/**
* @param mixed $item
* @return bool true if $item is of the expected type, else false
*/
public function checkType($item): bool;
public function checkType(mixed $item): bool;

/**
* @return \VersatileCollections\StringsCollection a collection of strings of type name(s) for items acceptable in a collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ protected function isRightTypeOrThrowInvalidTypeException(mixed $item, string $c
*
* @noinspection PhpDocSignatureInspection
* @noinspection PhpUnhandledExceptionInspection
* @psalm-suppress ParamNameMismatch
*/
public function offsetSet($key, mixed $val): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/StringsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(string ...$strings)
$this->versatile_collections_items = $strings;
}

public function checkType($item): bool
public function checkType(mixed $item): bool
{
return \is_string($item);
}
Expand Down
2 changes: 0 additions & 2 deletions src/helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ function var_to_string(mixed $var): string

/**
* Generate a (screen/user)-friendly string representation of a variable and print it out to the screen.
*
* @return void
*/
function dump_var(mixed $var): void
{
Expand Down
28 changes: 9 additions & 19 deletions tests/GenericCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -725,26 +725,16 @@ function ($key, $item) {
// to a Closure under the hood, though binding it to $this has no
// effect in this case.
$string_keys_and_vals_collection = new \VersatileCollections\GenericCollection();
$string_keys_and_vals_collection['5'] = '1';
$string_keys_and_vals_collection['4'] = '2';
$string_keys_and_vals_collection['3'] = '3';
$string_keys_and_vals_collection['2'] = '4';
$string_keys_and_vals_collection['1'] = '5';
$string_keys_and_vals_collection['5%s'] = '1';
$string_keys_and_vals_collection['4%s'] = '2';
$string_keys_and_vals_collection['3%s'] = '3';
$string_keys_and_vals_collection['2%s'] = '4';
$string_keys_and_vals_collection['1%s'] = '5';

if( PHP_OS_FAMILY === 'Windows' ) {

$this->assertEquals(
$string_keys_and_vals_collection->map('strcmp', true, true)->toArray(),
[ '5' => 1, '4' => 1, '3' => 0, '2' => -1, '1' => -1, ]
);

} else {

$this->assertEquals(
$string_keys_and_vals_collection->map('strcmp', true, true)->toArray(),
[ '5' => 4, '4' => 2, '3' => 0, '2' => -2, '1' => -4, ]
);
}
$this->assertEquals(
$string_keys_and_vals_collection->map('sprintf', true, true)->toArray(),
[ '5%s' => '51', '4%s' => '42', '3%s' => '33', '2%s' => '24', '1%s' => '15', ]
);
}

public function testThatToArrayWorksAsExpected() {
Expand Down

0 comments on commit 4553f41

Please sign in to comment.