File tree Expand file tree Collapse file tree 2 files changed +37
-5533
lines changed Expand file tree Collapse file tree 2 files changed +37
-5533
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,8 @@ public function enterNode(Node $node)
73
73
return null ;
74
74
}
75
75
76
+ $ node = $ this ->getCleanCommentsNode ($ node );
77
+
76
78
$ docComment = $ node ->getDocComment ();
77
79
78
80
if (! ($ docComment instanceof Doc)) {
@@ -870,4 +872,39 @@ static function (Node $node): bool {
870
872
}
871
873
return '' ;
872
874
}
875
+
876
+ private function getCleanCommentsNode (Node $ node ): Node
877
+ {
878
+ if (count ($ node ->getComments ()) === 0 ) {
879
+ return $ node ;
880
+ }
881
+
882
+ // Remove "//" comments.
883
+ $ comments = [];
884
+ foreach ($ node ->getComments () as $ comment ) {
885
+ if (strpos (trim ($ comment ->getText ()), '// ' ) === 0 ) {
886
+ continue ;
887
+ }
888
+ $ comments [] = $ comment ;
889
+ }
890
+
891
+ $ node ->setAttribute ('comments ' , $ comments );
892
+
893
+ if ($ node ->getDocComment () === null ) {
894
+ return $ node ;
895
+ }
896
+
897
+ // Remove file comments that are bound to the first node in a file.
898
+ $ comments = $ node ->getComments ();
899
+ if (
900
+ $ comments [0 ]->getText () !== (string )$ node ->getDocComment ()
901
+ && strpos ($ comments [0 ]->getText (), '/**#@ ' ) !== 0
902
+ ) {
903
+ array_shift ($ comments );
904
+ }
905
+
906
+ $ node ->setAttribute ('comments ' , $ comments );
907
+
908
+ return $ node ;
909
+ }
873
910
}
You can’t perform that action at this time.
0 commit comments