File tree Expand file tree Collapse file tree 3 files changed +20
-16
lines changed
Expand file tree Collapse file tree 3 files changed +20
-16
lines changed Original file line number Diff line number Diff line change 194194 "dump-soar-original-php-config" : " Guanguans\\ SoarPHP\\ Support\\ ComposerScripts::dumpSoarPHPConfig" ,
195195 "dump-soar-php-config" : [
196196 " @dump-soar-original-php-config" ,
197- " @rector-soar-options" ,
198- " @style-fix"
197+ " @rector-soar-options --no-diffs " ,
198+ " @style-fix --quiet "
199199 ],
200200 "dump-soar-yaml-config" : " Guanguans\\ SoarPHP\\ Support\\ ComposerScripts::dumpSoarYamlConfig" ,
201201 "facade-lint" : " @facade-update --lint" ,
Original file line number Diff line number Diff line change @@ -66,12 +66,12 @@ parameters:
6666 message : ' use config() instead'
6767 ignoreErrors :
6868 - identifier : argument.templateType
69- # - identifier: binaryOp.invalid
7069# - identifier: cast.string
7170# - identifier: method.nonObject
7271# - identifier: return.void
7372# - identifier: typePerfect.noMixedMethodCaller
7473 - identifier : argument.type
74+ - identifier : binaryOp.invalid
7575 - identifier : encapsedStringPart.nonString
7676 - identifier : logicalAnd.resultUnused
7777 - identifier : missingType.generics
Original file line number Diff line number Diff line change 1313
1414namespace Guanguans \SoarPHP \Support \Rectors ;
1515
16+ use Illuminate \Support \Collection ;
1617use PhpParser \Node ;
17- use PhpParser \Node \ArrayItem ;
1818use PhpParser \Node \Expr ;
1919use PhpParser \Node \Expr \Array_ ;
2020use PhpParser \Node \Scalar \Int_ ;
@@ -73,26 +73,30 @@ public function getNodeTypes(): array
7373 */
7474 public function refactor (Node $ node ): ?Node
7575 {
76- $ keys = collect ($ node ->items )->pluck ('key ' );
76+ $ keys = collect ($ node ->items )
77+ ->pluck ('key ' )
78+ ->map (fn (?Expr $ expr ): mixed => $ expr instanceof Expr ? $ this ->valueResolver ->getValue ($ expr ) : null );
7779
80+ /** @noinspection NullPointerExceptionInspection */
7881 if (
79- $ keys
80- ->filter (static fn (?Expr $ expr ): bool => !$ expr instanceof Int_)
81- ->isNotEmpty ()
82+ $ keys ->filter (static fn (mixed $ key ): bool => null !== $ key && !\is_int ($ key ))->isNotEmpty ()
83+ || !$ this ->isList (
84+ $ keys ->reduce (
85+ static fn (Collection $ carry , ?int $ key ): Collection => $ carry ->put (
86+ $ key ?? ($ carry ->isEmpty () ? 0 : $ carry ->keys ()->sortDesc (\SORT_NUMERIC )->first () + 1 ),
87+ $ key
88+ ),
89+ collect ()
90+ )->all ()
91+ )
8292 ) {
8393 return null ;
8494 }
8595
86- $ keyValues = $ keys ->mapWithKeys (fn (?Expr $ expr ): array => [
87- $ key = $ this ->valueResolver ->getValue ($ expr , true ) => $ key ,
88- ]);
89-
90- if ($ keyValues ->count () !== $ keys ->count () || !$ this ->isList ($ keyValues ->all ())) {
91- return null ;
96+ foreach ($ node ->items as $ item ) {
97+ $ item ->key instanceof Int_ and $ item ->key = null ;
9298 }
9399
94- collect ($ node ->items )->each (static fn (ArrayItem $ arrayItem ): mixed => $ arrayItem ->key = null );
95-
96100 return $ node ;
97101 }
98102
You can’t perform that action at this time.
0 commit comments