@@ -236,9 +236,9 @@ function (PhpDocChildNode $child): string {
236236 }
237237 if ($ node instanceof ArrayShapeUnsealedTypeNode) {
238238 if ($ node ->keyType !== null ) {
239- return sprintf ('<%s, %s> ' , $ this ->printType ($ node ->keyType ), $ this ->printType ($ node ->valueType ));
239+ return sprintf ('<%s, %s> ' , $ this ->print ($ node ->keyType ), $ this ->print ($ node ->valueType ));
240240 }
241- return sprintf ('<%s> ' , $ this ->printType ($ node ->valueType ));
241+ return sprintf ('<%s> ' , $ this ->print ($ node ->valueType ));
242242 }
243243 if ($ node instanceof DoctrineAnnotation) {
244244 return (string ) $ node ;
@@ -258,23 +258,23 @@ function (PhpDocChildNode $child): string {
258258 '%s%s: %s ' ,
259259 $ this ->print ($ node ->keyName ),
260260 $ node ->optional ? '? ' : '' ,
261- $ this ->printType ($ node ->valueType ),
261+ $ this ->print ($ node ->valueType ),
262262 );
263263 }
264264
265- return $ this ->printType ($ node ->valueType );
265+ return $ this ->print ($ node ->valueType );
266266 }
267267 if ($ node instanceof ObjectShapeItemNode) {
268268 if ($ node ->keyName !== null ) {
269269 return sprintf (
270270 '%s%s: %s ' ,
271271 $ this ->print ($ node ->keyName ),
272272 $ node ->optional ? '? ' : '' ,
273- $ this ->printType ($ node ->valueType ),
273+ $ this ->print ($ node ->valueType ),
274274 );
275275 }
276276
277- return $ this ->printType ($ node ->valueType );
277+ return $ this ->print ($ node ->valueType );
278278 }
279279
280280 throw new LogicException (sprintf ('Unknown node type %s ' , get_class ($ node )));
@@ -288,53 +288,53 @@ private function printTagValue(PhpDocTagValueNode $node): string
288288 if ($ node instanceof AssertTagMethodValueNode) {
289289 $ isNegated = $ node ->isNegated ? '! ' : '' ;
290290 $ isEquality = $ node ->isEquality ? '= ' : '' ;
291- $ type = $ this ->printType ($ node ->type );
291+ $ type = $ this ->print ($ node ->type );
292292 return trim ("{$ isNegated }{$ isEquality }{$ type } {$ node ->parameter }-> {$ node ->method }() {$ node ->description }" );
293293 }
294294 if ($ node instanceof AssertTagPropertyValueNode) {
295295 $ isNegated = $ node ->isNegated ? '! ' : '' ;
296296 $ isEquality = $ node ->isEquality ? '= ' : '' ;
297- $ type = $ this ->printType ($ node ->type );
297+ $ type = $ this ->print ($ node ->type );
298298 return trim ("{$ isNegated }{$ isEquality }{$ type } {$ node ->parameter }-> {$ node ->property } {$ node ->description }" );
299299 }
300300 if ($ node instanceof AssertTagValueNode) {
301301 $ isNegated = $ node ->isNegated ? '! ' : '' ;
302302 $ isEquality = $ node ->isEquality ? '= ' : '' ;
303- $ type = $ this ->printType ($ node ->type );
303+ $ type = $ this ->print ($ node ->type );
304304 return trim ("{$ isNegated }{$ isEquality }{$ type } {$ node ->parameter } {$ node ->description }" );
305305 }
306306 if ($ node instanceof ExtendsTagValueNode || $ node instanceof ImplementsTagValueNode) {
307- $ type = $ this ->printType ($ node ->type );
307+ $ type = $ this ->print ($ node ->type );
308308 return trim ("{$ type } {$ node ->description }" );
309309 }
310310 if ($ node instanceof MethodTagValueNode) {
311311 $ static = $ node ->isStatic ? 'static ' : '' ;
312- $ returnType = $ node ->returnType !== null ? $ this ->printType ($ node ->returnType ) . ' ' : '' ;
312+ $ returnType = $ node ->returnType !== null ? $ this ->print ($ node ->returnType ) . ' ' : '' ;
313313 $ parameters = implode (', ' , array_map (fn (MethodTagValueParameterNode $ parameter ): string => $ this ->print ($ parameter ), $ node ->parameters ));
314314 $ description = $ node ->description !== '' ? " {$ node ->description }" : '' ;
315315 $ templateTypes = count ($ node ->templateTypes ) > 0 ? '< ' . implode (', ' , array_map (fn (TemplateTagValueNode $ templateTag ): string => $ this ->print ($ templateTag ), $ node ->templateTypes )) . '> ' : '' ;
316316 return "{$ static }{$ returnType }{$ node ->methodName }{$ templateTypes }( {$ parameters }) {$ description }" ;
317317 }
318318 if ($ node instanceof MixinTagValueNode) {
319- $ type = $ this ->printType ($ node ->type );
319+ $ type = $ this ->print ($ node ->type );
320320 return trim ("{$ type } {$ node ->description }" );
321321 }
322322 if ($ node instanceof RequireExtendsTagValueNode) {
323- $ type = $ this ->printType ($ node ->type );
323+ $ type = $ this ->print ($ node ->type );
324324 return trim ("{$ type } {$ node ->description }" );
325325 }
326326 if ($ node instanceof RequireImplementsTagValueNode) {
327- $ type = $ this ->printType ($ node ->type );
327+ $ type = $ this ->print ($ node ->type );
328328 return trim ("{$ type } {$ node ->description }" );
329329 }
330330 if ($ node instanceof ParamOutTagValueNode) {
331- $ type = $ this ->printType ($ node ->type );
331+ $ type = $ this ->print ($ node ->type );
332332 return trim ("{$ type } {$ node ->parameterName } {$ node ->description }" );
333333 }
334334 if ($ node instanceof ParamTagValueNode) {
335335 $ reference = $ node ->isReference ? '& ' : '' ;
336336 $ variadic = $ node ->isVariadic ? '... ' : '' ;
337- $ type = $ this ->printType ($ node ->type );
337+ $ type = $ this ->print ($ node ->type );
338338 return trim ("{$ type } {$ reference }{$ variadic }{$ node ->parameterName } {$ node ->description }" );
339339 }
340340 if ($ node instanceof ParamImmediatelyInvokedCallableTagValueNode) {
@@ -350,43 +350,43 @@ private function printTagValue(PhpDocTagValueNode $node): string
350350 return trim ("{$ node ->parameterName } {$ node ->description }" );
351351 }
352352 if ($ node instanceof PropertyTagValueNode) {
353- $ type = $ this ->printType ($ node ->type );
353+ $ type = $ this ->print ($ node ->type );
354354 return trim ("{$ type } {$ node ->propertyName } {$ node ->description }" );
355355 }
356356 if ($ node instanceof ReturnTagValueNode) {
357- $ type = $ this ->printType ($ node ->type );
357+ $ type = $ this ->print ($ node ->type );
358358 return trim ("{$ type } {$ node ->description }" );
359359 }
360360 if ($ node instanceof SelfOutTagValueNode) {
361- $ type = $ this ->printType ($ node ->type );
361+ $ type = $ this ->print ($ node ->type );
362362 return trim ($ type . ' ' . $ node ->description );
363363 }
364364 if ($ node instanceof TemplateTagValueNode) {
365- $ upperBound = $ node ->bound !== null ? ' of ' . $ this ->printType ($ node ->bound ) : '' ;
366- $ lowerBound = $ node ->lowerBound !== null ? ' super ' . $ this ->printType ($ node ->lowerBound ) : '' ;
367- $ default = $ node ->default !== null ? ' = ' . $ this ->printType ($ node ->default ) : '' ;
365+ $ upperBound = $ node ->bound !== null ? ' of ' . $ this ->print ($ node ->bound ) : '' ;
366+ $ lowerBound = $ node ->lowerBound !== null ? ' super ' . $ this ->print ($ node ->lowerBound ) : '' ;
367+ $ default = $ node ->default !== null ? ' = ' . $ this ->print ($ node ->default ) : '' ;
368368 return trim ("{$ node ->name }{$ upperBound }{$ lowerBound }{$ default } {$ node ->description }" );
369369 }
370370 if ($ node instanceof ThrowsTagValueNode) {
371- $ type = $ this ->printType ($ node ->type );
371+ $ type = $ this ->print ($ node ->type );
372372 return trim ("{$ type } {$ node ->description }" );
373373 }
374374 if ($ node instanceof TypeAliasImportTagValueNode) {
375375 return trim (
376- "{$ node ->importedAlias } from " . $ this ->printType ($ node ->importedFrom )
376+ "{$ node ->importedAlias } from " . $ this ->print ($ node ->importedFrom )
377377 . ($ node ->importedAs !== null ? " as {$ node ->importedAs }" : '' ),
378378 );
379379 }
380380 if ($ node instanceof TypeAliasTagValueNode) {
381- $ type = $ this ->printType ($ node ->type );
381+ $ type = $ this ->print ($ node ->type );
382382 return trim ("{$ node ->alias } {$ type }" );
383383 }
384384 if ($ node instanceof UsesTagValueNode) {
385- $ type = $ this ->printType ($ node ->type );
385+ $ type = $ this ->print ($ node ->type );
386386 return trim ("{$ type } {$ node ->description }" );
387387 }
388388 if ($ node instanceof VarTagValueNode) {
389- $ type = $ this ->printType ($ node ->type );
389+ $ type = $ this ->print ($ node ->type );
390390 return trim ("{$ type } " . trim ("{$ node ->variableName } {$ node ->description }" ));
391391 }
392392
@@ -411,7 +411,7 @@ private function printType(TypeNode $node): string
411411 if ($ node ->returnType instanceof CallableTypeNode || $ node ->returnType instanceof UnionTypeNode || $ node ->returnType instanceof IntersectionTypeNode) {
412412 $ returnType = $ this ->wrapInParentheses ($ node ->returnType );
413413 } else {
414- $ returnType = $ this ->printType ($ node ->returnType );
414+ $ returnType = $ this ->print ($ node ->returnType );
415415 }
416416 $ template = $ node ->templateTypes !== []
417417 ? '< ' . implode (', ' , array_map (fn (TemplateTagValueNode $ templateNode ): string => $ this ->print ($ templateNode ), $ node ->templateTypes )) . '> '
@@ -424,19 +424,19 @@ private function printType(TypeNode $node): string
424424 '(%s %s %s ? %s : %s) ' ,
425425 $ node ->parameterName ,
426426 $ node ->negated ? 'is not ' : 'is ' ,
427- $ this ->printType ($ node ->targetType ),
428- $ this ->printType ($ node ->if ),
429- $ this ->printType ($ node ->else ),
427+ $ this ->print ($ node ->targetType ),
428+ $ this ->print ($ node ->if ),
429+ $ this ->print ($ node ->else ),
430430 );
431431 }
432432 if ($ node instanceof ConditionalTypeNode) {
433433 return sprintf (
434434 '(%s %s %s ? %s : %s) ' ,
435- $ this ->printType ($ node ->subjectType ),
435+ $ this ->print ($ node ->subjectType ),
436436 $ node ->negated ? 'is not ' : 'is ' ,
437- $ this ->printType ($ node ->targetType ),
438- $ this ->printType ($ node ->if ),
439- $ this ->printType ($ node ->else ),
437+ $ this ->print ($ node ->targetType ),
438+ $ this ->print ($ node ->if ),
439+ $ this ->print ($ node ->else ),
440440 );
441441 }
442442 if ($ node instanceof ConstTypeNode) {
@@ -448,7 +448,7 @@ private function printType(TypeNode $node): string
448448 foreach ($ node ->genericTypes as $ index => $ type ) {
449449 $ variance = $ node ->variances [$ index ] ?? GenericTypeNode::VARIANCE_INVARIANT ;
450450 if ($ variance === GenericTypeNode::VARIANCE_INVARIANT ) {
451- $ genericTypes [] = $ this ->printType ($ type );
451+ $ genericTypes [] = $ this ->print ($ type );
452452 } elseif ($ variance === GenericTypeNode::VARIANCE_BIVARIANT ) {
453453 $ genericTypes [] = '* ' ;
454454 } else {
@@ -473,7 +473,7 @@ private function printType(TypeNode $node): string
473473 continue ;
474474 }
475475
476- $ items [] = $ this ->printType ($ type );
476+ $ items [] = $ this ->print ($ type );
477477 }
478478
479479 return implode ($ node instanceof IntersectionTypeNode ? '& ' : '| ' , $ items );
@@ -483,18 +483,18 @@ private function printType(TypeNode $node): string
483483 }
484484 if ($ node instanceof NullableTypeNode) {
485485 if ($ node ->type instanceof IntersectionTypeNode || $ node ->type instanceof UnionTypeNode) {
486- return '?( ' . $ this ->printType ($ node ->type ) . ') ' ;
486+ return '?( ' . $ this ->print ($ node ->type ) . ') ' ;
487487 }
488488
489- return '? ' . $ this ->printType ($ node ->type );
489+ return '? ' . $ this ->print ($ node ->type );
490490 }
491491 if ($ node instanceof ObjectShapeNode) {
492492 $ items = array_map (fn (ObjectShapeItemNode $ item ): string => $ this ->print ($ item ), $ node ->items );
493493
494494 return 'object{ ' . implode (', ' , $ items ) . '} ' ;
495495 }
496496 if ($ node instanceof OffsetAccessTypeNode) {
497- return $ this ->printOffsetAccessType ($ node ->type ) . '[ ' . $ this ->printType ($ node ->offset ) . '] ' ;
497+ return $ this ->printOffsetAccessType ($ node ->type ) . '[ ' . $ this ->print ($ node ->offset ) . '] ' ;
498498 }
499499 if ($ node instanceof ThisTypeNode) {
500500 return (string ) $ node ;
@@ -505,7 +505,7 @@ private function printType(TypeNode $node): string
505505
506506 private function wrapInParentheses (TypeNode $ node ): string
507507 {
508- return '( ' . $ this ->printType ($ node ) . ') ' ;
508+ return '( ' . $ this ->print ($ node ) . ') ' ;
509509 }
510510
511511 private function printOffsetAccessType (TypeNode $ type ): string
@@ -519,7 +519,7 @@ private function printOffsetAccessType(TypeNode $type): string
519519 return $ this ->wrapInParentheses ($ type );
520520 }
521521
522- return $ this ->printType ($ type );
522+ return $ this ->print ($ type );
523523 }
524524
525525 private function printConstExpr (ConstExprNode $ node ): string
@@ -550,30 +550,23 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
550550
551551 foreach ($ diff as $ i => $ diffElem ) {
552552 $ diffType = $ diffElem ->type ;
553- $ arrItem = $ diffElem ->new ;
554- $ origArrayItem = $ diffElem ->old ;
553+ $ newNode = $ diffElem ->new ;
554+ $ originalNode = $ diffElem ->old ;
555555 if ($ diffType === DiffElem::TYPE_KEEP || $ diffType === DiffElem::TYPE_REPLACE ) {
556556 $ beforeFirstKeepOrReplace = false ;
557- if (!$ arrItem instanceof Node || !$ origArrayItem instanceof Node) {
557+ if (!$ newNode instanceof Node || !$ originalNode instanceof Node) {
558558 return null ;
559559 }
560560
561561 /** @var int $itemStartPos */
562- $ itemStartPos = $ origArrayItem ->getAttribute (Attribute::START_INDEX );
562+ $ itemStartPos = $ originalNode ->getAttribute (Attribute::START_INDEX );
563563
564564 /** @var int $itemEndPos */
565- $ itemEndPos = $ origArrayItem ->getAttribute (Attribute::END_INDEX );
566-
565+ $ itemEndPos = $ originalNode ->getAttribute (Attribute::END_INDEX );
567566 if ($ itemStartPos < 0 || $ itemEndPos < 0 || $ itemStartPos < $ tokenIndex ) {
568567 throw new LogicException ();
569568 }
570569
571- $ comments = $ arrItem ->getAttribute (Attribute::COMMENTS ) ?? [];
572- $ origComments = $ origArrayItem ->getAttribute (Attribute::COMMENTS ) ?? [];
573-
574- $ commentStartPos = count ($ origComments ) > 0 ? $ origComments [0 ]->startIndex : $ itemStartPos ;
575- assert ($ commentStartPos >= 0 );
576-
577570 $ result .= $ originalTokens ->getContentBetween ($ tokenIndex , $ itemStartPos );
578571
579572 if (count ($ delayedAdd ) > 0 ) {
@@ -583,15 +576,6 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
583576 if ($ parenthesesNeeded ) {
584577 $ result .= '( ' ;
585578 }
586-
587- if ($ insertNewline ) {
588- $ delayedAddComments = $ delayedAddNode ->getAttribute (Attribute::COMMENTS ) ?? [];
589- if (count ($ delayedAddComments ) > 0 ) {
590- $ result .= $ this ->printComments ($ delayedAddComments , $ beforeAsteriskIndent , $ afterAsteriskIndent );
591- $ result .= sprintf ('%s%s*%s ' , $ originalTokens ->getDetectedNewline () ?? "\n" , $ beforeAsteriskIndent , $ afterAsteriskIndent );
592- }
593- }
594-
595579 $ result .= $ this ->printNodeFormatPreserving ($ delayedAddNode , $ originalTokens );
596580 if ($ parenthesesNeeded ) {
597581 $ result .= ') ' ;
@@ -608,21 +592,14 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
608592 }
609593
610594 $ parenthesesNeeded = isset ($ this ->parenthesesListMap [$ mapKey ])
611- && in_array (get_class ($ arrItem ), $ this ->parenthesesListMap [$ mapKey ], true )
612- && !in_array (get_class ($ origArrayItem ), $ this ->parenthesesListMap [$ mapKey ], true );
595+ && in_array (get_class ($ newNode ), $ this ->parenthesesListMap [$ mapKey ], true )
596+ && !in_array (get_class ($ originalNode ), $ this ->parenthesesListMap [$ mapKey ], true );
613597 $ addParentheses = $ parenthesesNeeded && !$ originalTokens ->hasParentheses ($ itemStartPos , $ itemEndPos );
614598 if ($ addParentheses ) {
615599 $ result .= '( ' ;
616600 }
617601
618- if ($ comments !== $ origComments ) {
619- if (count ($ comments ) > 0 ) {
620- $ result .= $ this ->printComments ($ comments , $ beforeAsteriskIndent , $ afterAsteriskIndent );
621- $ result .= sprintf ('%s%s*%s ' , $ originalTokens ->getDetectedNewline () ?? "\n" , $ beforeAsteriskIndent , $ afterAsteriskIndent );
622- }
623- }
624-
625- $ result .= $ this ->printNodeFormatPreserving ($ arrItem , $ originalTokens );
602+ $ result .= $ this ->printNodeFormatPreserving ($ newNode , $ originalTokens );
626603 if ($ addParentheses ) {
627604 $ result .= ') ' ;
628605 }
@@ -632,58 +609,52 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
632609 if ($ insertStr === null ) {
633610 return null ;
634611 }
635- if (!$ arrItem instanceof Node) {
612+ if (!$ newNode instanceof Node) {
636613 return null ;
637614 }
638615
639- if ($ insertStr === ', ' && $ isMultiline || count ($ arrItem ->getAttribute (Attribute::COMMENTS ) ?? []) > 0 ) {
616+ if ($ insertStr === ', ' && $ isMultiline || count ($ newNode ->getAttribute (Attribute::COMMENTS ) ?? []) > 0 ) {
640617 $ insertStr = ', ' ;
641618 $ insertNewline = true ;
642619 }
643620
644621 if ($ beforeFirstKeepOrReplace ) {
645622 // Will be inserted at the next "replace" or "keep" element
646- $ delayedAdd [] = $ arrItem ;
623+ $ delayedAdd [] = $ newNode ;
647624 continue ;
648625 }
649626
650627 /** @var int $itemEndPos */
651628 $ itemEndPos = $ tokenIndex - 1 ;
652629 if ($ insertNewline ) {
653- $ comments = $ arrItem ->getAttribute (Attribute::COMMENTS ) ?? [];
654- $ result .= $ insertStr ;
655- if (count ($ comments ) > 0 ) {
656- $ result .= sprintf ('%s%s*%s ' , $ originalTokens ->getDetectedNewline () ?? "\n" , $ beforeAsteriskIndent , $ afterAsteriskIndent );
657- $ result .= $ this ->printComments ($ comments , $ beforeAsteriskIndent , $ afterAsteriskIndent );
658- }
659- $ result .= sprintf ('%s%s*%s ' , $ originalTokens ->getDetectedNewline () ?? "\n" , $ beforeAsteriskIndent , $ afterAsteriskIndent );
630+ $ result .= $ insertStr . sprintf ('%s%s*%s ' , $ originalTokens ->getDetectedNewline () ?? "\n" , $ beforeAsteriskIndent , $ afterAsteriskIndent );
660631 } else {
661632 $ result .= $ insertStr ;
662633 }
663634
664635 $ parenthesesNeeded = isset ($ this ->parenthesesListMap [$ mapKey ])
665- && in_array (get_class ($ arrItem ), $ this ->parenthesesListMap [$ mapKey ], true );
636+ && in_array (get_class ($ newNode ), $ this ->parenthesesListMap [$ mapKey ], true );
666637 if ($ parenthesesNeeded ) {
667638 $ result .= '( ' ;
668639 }
669640
670- $ result .= $ this ->printNodeFormatPreserving ($ arrItem , $ originalTokens );
641+ $ result .= $ this ->printNodeFormatPreserving ($ newNode , $ originalTokens );
671642 if ($ parenthesesNeeded ) {
672643 $ result .= ') ' ;
673644 }
674645
675646 $ tokenIndex = $ itemEndPos + 1 ;
676647
677648 } elseif ($ diffType === DiffElem::TYPE_REMOVE ) {
678- if (!$ origArrayItem instanceof Node) {
649+ if (!$ originalNode instanceof Node) {
679650 return null ;
680651 }
681652
682653 /** @var int $itemStartPos */
683- $ itemStartPos = $ origArrayItem ->getAttribute (Attribute::START_INDEX );
654+ $ itemStartPos = $ originalNode ->getAttribute (Attribute::START_INDEX );
684655
685656 /** @var int $itemEndPos */
686- $ itemEndPos = $ origArrayItem ->getAttribute (Attribute::END_INDEX );
657+ $ itemEndPos = $ originalNode ->getAttribute (Attribute::END_INDEX );
687658 if ($ itemStartPos < 0 || $ itemEndPos < 0 ) {
688659 throw new LogicException ();
689660 }
0 commit comments