Skip to content

Commit

Permalink
[CodeQuality] Skip sort/ksort on TernaryFalseExpressionToIfRector (#…
Browse files Browse the repository at this point in the history
…5703)

* Create array_helper.php.inc

* [CodeQuality] Skip sort/ksort on TernaryFalseExpressionToIfRector

* fix

---------

Co-authored-by: Adamo Crespi <hello@aerendir.me>
  • Loading branch information
samsonasik and Aerendir committed Mar 9, 2024
1 parent c14f8d4 commit 3d02e3e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
@@ -0,0 +1,21 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Expression\TernaryFalseExpressionToIfRector\Fixture;

class SkipSortKsort
{
public static function mksort(array &$array): void
{
$keys = array_keys($array);
$isIndexedArray = array_reduce($keys, static fn ($result, $item): bool => $result && is_numeric($item), true);
$isIndexedArray
? sort($array)
: ksort($array);

foreach ($array as &$value) {
if (is_array($value)) {
self::mksort($value);
}
}
}
}
2 changes: 1 addition & 1 deletion rules/DeadCode/SideEffect/PureFunctionDetector.php
Expand Up @@ -114,7 +114,7 @@
'json_encode', 'json_decode', 'json_last_error',

// array
'array_pop', 'array_push', 'array_shift', 'array_splice', 'next', 'prev',
'array_pop', 'array_push', 'array_shift', 'array_splice', 'next', 'prev', 'sort', 'ksort',

// stream
'stream_filter_append',
Expand Down

0 comments on commit 3d02e3e

Please sign in to comment.