Skip to content

Commit

Permalink
Tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Mar 14, 2024
1 parent 808a48a commit 23934b2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"phpunit/phpunit": "^9.0",
"php-coveralls/php-coveralls": "^2.0",
"symfony/polyfill-mbstring": "^1.8",
"rector/rector": "^0.18.0",
"rector/rector": "^1.0.0",
"vimeo/psalm": "^5.4.0"
},
"autoload": {
Expand Down
1 change: 1 addition & 0 deletions src/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public function offsetGet($key);
*
* @title: Adds an item with a specified key to the collection.
*
* @psalm-suppress ParamNameMismatch
* @noRector \Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector
* @noinspection PhpParameterNameChangedDuringInheritanceInspection
*/
Expand Down
6 changes: 4 additions & 2 deletions src/CollectionInterfaceImplementationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ public function offsetGet($key) {
* @param string|int|null $key The requested key.
*
* @param mixed $val The value to set it to.
*
*
* @psalm-suppress ParamNameMismatch
*/
public function offsetSet($key, $val): void {

Expand Down Expand Up @@ -1566,7 +1567,7 @@ protected function performSort(
*
* @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 @@ -1644,6 +1645,7 @@ protected function performMultiSort(array $array_to_be_sorted, MultiSortParamete
// last parameter is the array to be sorted
/** @psalm-suppress UnsupportedReferenceUsage */
$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
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ protected function isRightTypeOrThrowInvalidTypeException($item, string $calling
* @param string|int|null $key The requested key.
* @param mixed $val The value to set it to.
*
* @psalm-suppress ParamNameMismatch
* @noinspection PhpDocSignatureInspection
* @noinspection PhpUnhandledExceptionInspection
*/
Expand Down
7 changes: 2 additions & 5 deletions src/helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* (the value of the propertie(s) with numeric key(s) in such \stdClass
* objects will be retrieved by this function).
*
* @param object $obj
* @param string|int $property
* @param mixed $default_val
* @param bool $access_private_or_protected true if value associated with private or protected property should be returned.
Expand Down Expand Up @@ -100,7 +99,6 @@ function get_object_property_value(object $obj, $property, $default_val=null, bo
* A more robust way than property_exists of checking if an instance of a class
* has a specified property.
*
* @param object $obj
* @param string|int $property
*
*
Expand Down Expand Up @@ -296,11 +294,10 @@ function var_to_string($var): string {

/**
*
* Generate a (screen/user)-friendly string representation of a variable and print it out to the screen.
* Generate a (screen/user)-friendly string representation of a variable and print it out to the screen.
*
* @param mixed $var
*
* @return void
*
* @noRector
*
*/
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 23934b2

Please sign in to comment.