@@ -31,10 +31,14 @@ public function register(): array {
3131 */
3232 public function process (File $ phpCsFile , $ stackPointer ): void {
3333 $ tokens = $ phpCsFile ->getTokens ();
34- if (($ stackPointer > 1 ) && ($ tokens [$ stackPointer - 2 ]['type ' ] === ' T_STATIC ' )) {
34+ if (($ stackPointer > 1 ) && ($ tokens [$ stackPointer - 2 ]['code ' ] === T_STATIC )) {
3535 return ; // Skip static function declarations
3636 }
3737
38+ if ($ tokens [$ stackPointer ]['code ' ] === T_FUNCTION && $ this ->isNonChainable ($ tokens , $ stackPointer )) {
39+ return ;
40+ }
41+
3842 $ docBlockEndIndex = $ this ->findRelatedDocBlock ($ phpCsFile , $ stackPointer );
3943
4044 if (!$ docBlockEndIndex ) {
@@ -70,11 +74,39 @@ public function process(File $phpCsFile, $stackPointer): void {
7074 continue ;
7175 }
7276
77+ if (strpos ($ content , '| ' ) !== false ) {
78+ return ;
79+ }
80+
7381 $ parts = explode ('| ' , $ content );
7482 $ this ->fixParts ($ phpCsFile , $ classNameIndex , $ parts , $ appendix );
7583 }
7684 }
7785
86+ /**
87+ * @param array<array<string, mixed>> $tokens
88+ * @param int $stackPointer
89+ *
90+ * @return bool
91+ */
92+ protected function isNonChainable (array $ tokens , int $ stackPointer ): bool {
93+ if (empty ($ tokens [$ stackPointer ]['scope_opener ' ])) {
94+ return false ;
95+ }
96+
97+ $ startIndex = $ tokens [$ stackPointer ]['scope_opener ' ];
98+ $ endIndex = $ tokens [$ stackPointer ]['scope_closer ' ];
99+ $ i = $ startIndex + 1 ;
100+ while ($ i < $ endIndex ) {
101+ if ($ tokens [$ i ]['code ' ] === T_NEW ) {
102+ return true ;
103+ }
104+ $ i ++;
105+ }
106+
107+ return false ;
108+ }
109+
78110 /**
79111 * @param \PHP_CodeSniffer\Files\File $phpCsFile
80112 * @param int $classNameIndex
0 commit comments