Skip to content

Commit 6c11408

Browse files
committed
Filter out internal PHP functions from set (#109)
* Filter out internal PHP functions
1 parent 451d8cd commit 6c11408

File tree

1 file changed

+50
-43
lines changed

1 file changed

+50
-43
lines changed

config/sets/laravel-array-str-functions-to-static-call.php

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,58 @@
1212

1313
return static function (RectorConfig $rectorConfig): void {
1414
$rectorConfig->import(__DIR__ . '/../config.php');
15+
16+
$internalFunctions = get_defined_functions()['internal'];
17+
1518
$rectorConfig
1619
->ruleWithConfiguration(
1720
FuncCallToStaticCallRector::class,
18-
[new FuncCallToStaticCall('array_add', 'Illuminate\Support\Arr', 'add'),
19-
new FuncCallToStaticCall('array_collapse', 'Illuminate\Support\Arr', 'collapse'),
20-
new FuncCallToStaticCall('array_divide', 'Illuminate\Support\Arr', 'divide'),
21-
new FuncCallToStaticCall('array_dot', 'Illuminate\Support\Arr', 'dot'),
22-
new FuncCallToStaticCall('array_except', 'Illuminate\Support\Arr', 'except'),
23-
new FuncCallToStaticCall('array_first', 'Illuminate\Support\Arr', 'first'),
24-
new FuncCallToStaticCall('array_flatten', 'Illuminate\Support\Arr', 'flatten'),
25-
new FuncCallToStaticCall('array_forget', 'Illuminate\Support\Arr', 'forget'),
26-
new FuncCallToStaticCall('array_get', 'Illuminate\Support\Arr', 'get'),
27-
new FuncCallToStaticCall('array_has', 'Illuminate\Support\Arr', 'has'),
28-
new FuncCallToStaticCall('array_last', 'Illuminate\Support\Arr', 'last'),
29-
new FuncCallToStaticCall('array_only', 'Illuminate\Support\Arr', 'only'),
30-
new FuncCallToStaticCall('array_pluck', 'Illuminate\Support\Arr', 'pluck'),
31-
new FuncCallToStaticCall('array_prepend', 'Illuminate\Support\Arr', 'prepend'),
32-
new FuncCallToStaticCall('array_pull', 'Illuminate\Support\Arr', 'pull'),
33-
new FuncCallToStaticCall('array_random', 'Illuminate\Support\Arr', 'random'),
34-
new FuncCallToStaticCall('array_sort', 'Illuminate\Support\Arr', 'sort'),
35-
new FuncCallToStaticCall('array_sort_recursive', 'Illuminate\Support\Arr', 'sortRecursive'),
36-
new FuncCallToStaticCall('array_where', 'Illuminate\Support\Arr', 'where'),
37-
new FuncCallToStaticCall('array_wrap', 'Illuminate\Support\Arr', 'wrap'),
38-
new FuncCallToStaticCall('array_set', 'Illuminate\Support\Arr', 'set'),
39-
new FuncCallToStaticCall('camel_case', 'Illuminate\Support\Str', 'camel'),
40-
new FuncCallToStaticCall('ends_with', 'Illuminate\Support\Str', 'endsWith'),
41-
new FuncCallToStaticCall('kebab_case', 'Illuminate\Support\Str', 'kebab'),
42-
new FuncCallToStaticCall('snake_case', 'Illuminate\Support\Str', 'snake'),
43-
new FuncCallToStaticCall('starts_with', 'Illuminate\Support\Str', 'startsWith'),
44-
new FuncCallToStaticCall('str_after', 'Illuminate\Support\Str', 'after'),
45-
new FuncCallToStaticCall('str_before', 'Illuminate\Support\Str', 'before'),
46-
new FuncCallToStaticCall('str_contains', 'Illuminate\Support\Str', 'contains'),
47-
new FuncCallToStaticCall('str_finish', 'Illuminate\Support\Str', 'finish'),
48-
new FuncCallToStaticCall('str_is', 'Illuminate\Support\Str', 'is'),
49-
new FuncCallToStaticCall('str_limit', 'Illuminate\Support\Str', 'limit'),
50-
new FuncCallToStaticCall('str_plural', 'Illuminate\Support\Str', 'plural'),
51-
new FuncCallToStaticCall('str_random', 'Illuminate\Support\Str', 'random'),
52-
new FuncCallToStaticCall('str_replace_array', 'Illuminate\Support\Str', 'replaceArray'),
53-
new FuncCallToStaticCall('str_replace_first', 'Illuminate\Support\Str', 'replaceFirst'),
54-
new FuncCallToStaticCall('str_replace_last', 'Illuminate\Support\Str', 'replaceLast'),
55-
new FuncCallToStaticCall('str_singular', 'Illuminate\Support\Str', 'singular'),
56-
new FuncCallToStaticCall('str_slug', 'Illuminate\Support\Str', 'slug'),
57-
new FuncCallToStaticCall('str_start', 'Illuminate\Support\Str', 'start'),
58-
new FuncCallToStaticCall('studly_case', 'Illuminate\Support\Str', 'studly'),
59-
new FuncCallToStaticCall('title_case', 'Illuminate\Support\Str', 'title'),
60-
]
21+
array_filter(
22+
[
23+
new FuncCallToStaticCall('array_add', 'Illuminate\Support\Arr', 'add'),
24+
new FuncCallToStaticCall('array_collapse', 'Illuminate\Support\Arr', 'collapse'),
25+
new FuncCallToStaticCall('array_divide', 'Illuminate\Support\Arr', 'divide'),
26+
new FuncCallToStaticCall('array_dot', 'Illuminate\Support\Arr', 'dot'),
27+
new FuncCallToStaticCall('array_except', 'Illuminate\Support\Arr', 'except'),
28+
new FuncCallToStaticCall('array_first', 'Illuminate\Support\Arr', 'first'),
29+
new FuncCallToStaticCall('array_flatten', 'Illuminate\Support\Arr', 'flatten'),
30+
new FuncCallToStaticCall('array_forget', 'Illuminate\Support\Arr', 'forget'),
31+
new FuncCallToStaticCall('array_get', 'Illuminate\Support\Arr', 'get'),
32+
new FuncCallToStaticCall('array_has', 'Illuminate\Support\Arr', 'has'),
33+
new FuncCallToStaticCall('array_last', 'Illuminate\Support\Arr', 'last'),
34+
new FuncCallToStaticCall('array_only', 'Illuminate\Support\Arr', 'only'),
35+
new FuncCallToStaticCall('array_pluck', 'Illuminate\Support\Arr', 'pluck'),
36+
new FuncCallToStaticCall('array_prepend', 'Illuminate\Support\Arr', 'prepend'),
37+
new FuncCallToStaticCall('array_pull', 'Illuminate\Support\Arr', 'pull'),
38+
new FuncCallToStaticCall('array_random', 'Illuminate\Support\Arr', 'random'),
39+
new FuncCallToStaticCall('array_sort', 'Illuminate\Support\Arr', 'sort'),
40+
new FuncCallToStaticCall('array_sort_recursive', 'Illuminate\Support\Arr', 'sortRecursive'),
41+
new FuncCallToStaticCall('array_where', 'Illuminate\Support\Arr', 'where'),
42+
new FuncCallToStaticCall('array_wrap', 'Illuminate\Support\Arr', 'wrap'),
43+
new FuncCallToStaticCall('array_set', 'Illuminate\Support\Arr', 'set'),
44+
new FuncCallToStaticCall('camel_case', 'Illuminate\Support\Str', 'camel'),
45+
new FuncCallToStaticCall('ends_with', 'Illuminate\Support\Str', 'endsWith'),
46+
new FuncCallToStaticCall('kebab_case', 'Illuminate\Support\Str', 'kebab'),
47+
new FuncCallToStaticCall('snake_case', 'Illuminate\Support\Str', 'snake'),
48+
new FuncCallToStaticCall('starts_with', 'Illuminate\Support\Str', 'startsWith'),
49+
new FuncCallToStaticCall('str_after', 'Illuminate\Support\Str', 'after'),
50+
new FuncCallToStaticCall('str_before', 'Illuminate\Support\Str', 'before'),
51+
new FuncCallToStaticCall('str_contains', 'Illuminate\Support\Str', 'contains'),
52+
new FuncCallToStaticCall('str_finish', 'Illuminate\Support\Str', 'finish'),
53+
new FuncCallToStaticCall('str_is', 'Illuminate\Support\Str', 'is'),
54+
new FuncCallToStaticCall('str_limit', 'Illuminate\Support\Str', 'limit'),
55+
new FuncCallToStaticCall('str_plural', 'Illuminate\Support\Str', 'plural'),
56+
new FuncCallToStaticCall('str_random', 'Illuminate\Support\Str', 'random'),
57+
new FuncCallToStaticCall('str_replace_array', 'Illuminate\Support\Str', 'replaceArray'),
58+
new FuncCallToStaticCall('str_replace_first', 'Illuminate\Support\Str', 'replaceFirst'),
59+
new FuncCallToStaticCall('str_replace_last', 'Illuminate\Support\Str', 'replaceLast'),
60+
new FuncCallToStaticCall('str_singular', 'Illuminate\Support\Str', 'singular'),
61+
new FuncCallToStaticCall('str_slug', 'Illuminate\Support\Str', 'slug'),
62+
new FuncCallToStaticCall('str_start', 'Illuminate\Support\Str', 'start'),
63+
new FuncCallToStaticCall('studly_case', 'Illuminate\Support\Str', 'studly'),
64+
new FuncCallToStaticCall('title_case', 'Illuminate\Support\Str', 'title'),
65+
],
66+
fn ($function) => ! in_array($function->getOldFuncName(), $internalFunctions, true)
67+
)
6168
);
6269
};

0 commit comments

Comments
 (0)