-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathRectorClassesSorter.php
More file actions
40 lines (32 loc) · 1.23 KB
/
RectorClassesSorter.php
File metadata and controls
40 lines (32 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace Rector\Util;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Contract\Rector\RectorInterface;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
final class RectorClassesSorter
{
/**
* @param array<class-string<RectorInterface|PostRectorInterface>> $rectorClasses
* @return array<class-string<RectorInterface|PostRectorInterface>>
*/
public static function sort(array $rectorClasses): array
{
$rectorClasses = array_unique($rectorClasses);
$mainRectorClasses = array_filter(
$rectorClasses,
fn (string $rectorClass): bool => is_a($rectorClass, RectorInterface::class, true)
);
sort($mainRectorClasses);
if (SimpleParameterProvider::provideBoolParameter(Option::INCLUDE_POST_RECTORS_IN_REPORTS)) {
$postRectorClasses = array_filter(
$rectorClasses,
fn (string $rectorClass): bool => is_a($rectorClass, PostRectorInterface::class, true)
);
sort($postRectorClasses);
return array_merge($mainRectorClasses, $postRectorClasses);
}
return $mainRectorClasses;
}
}