@@ -276,7 +276,7 @@ protected function pStmt_ClassMethod(\PhpParser\Node\Stmt\ClassMethod $node): st
276276 . $ this ->pModifiers ($ node ->flags )
277277 . 'function ' . ($ node ->byRef ? '& ' : '' ) . $ node ->name
278278 . '( ' . $ this ->pCommaSeparated ($ node ->params ) . ') '
279- . ($ this ->functionShouldReturn ($ node ) ? ' : ' . $ this ->p ($ node ->returnType ) : '' )
279+ . ($ this ->functionShouldHaveReturnType ($ node ) ? ' : ' . $ this ->p ($ node ->returnType ) : '' )
280280 . (null !== $ node ->stmts ? '{ ' . $ this ->pStmts ($ node ->stmts ) . '} ' : '; ' );
281281 }
282282
@@ -288,7 +288,7 @@ protected function pStmt_Function(\PhpParser\Node\Stmt\Function_ $node): string
288288 return $ ret
289289 . 'function ' . ($ node ->byRef ? '& ' : '' ) . $ node ->name
290290 . '( ' . $ this ->pCommaSeparated ($ node ->params ) . ') '
291- . ($ this ->functionShouldReturn ($ node ) ? ' : ' . $ this ->p ($ node ->returnType ) : '' )
291+ . ($ this ->functionShouldHaveReturnType ($ node ) ? ' : ' . $ this ->p ($ node ->returnType ) : '' )
292292 . '{ ' . $ this ->pStmts ($ node ->stmts ) . '} ' ;
293293 }
294294
@@ -436,17 +436,9 @@ protected function addAttributeGroupsBeforeStatement(\PhpParser\Node\Stmt $node)
436436 * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $node
437437 * @noinspection PhpDocSignatureInspection - PHP 7.4 compatibility
438438 */
439- protected function functionShouldReturn (\PhpParser \Node \Stmt $ node ): bool
439+ protected function functionShouldHaveReturnType (\PhpParser \Node \Stmt $ node ): bool
440440 {
441- if ($ node ->returnType === null ) {
442- return false ;
443- }
444-
445- if ($ node ->returnType instanceof \PhpParser \Node \Identifier && $ node ->returnType ->name === 'never ' ) {
446- return false ;
447- }
448-
449- return true ;
441+ return $ node ->returnType !== null ;
450442 }
451443}
452444
@@ -2790,7 +2782,7 @@ public function rewriteStmt_ClassMethod(\PhpParser\Node\Stmt\ClassMethod $Node)
27902782 // $mm_callback = SoftMocks::getMockForGenerator();
27912783 // foreach ($mm_callback(...) as $mm_val) { yield $mm_val; }
27922784 //
2793- // also functions with void return type declarations cannot return values
2785+ // also functions with ' void' or 'never' return type declarations cannot return values
27942786 if ($ this ->has_yield ) {
27952787 $ args = [$ static , $ function ];
27962788
@@ -2845,9 +2837,12 @@ public function rewriteStmt_ClassMethod(\PhpParser\Node\Stmt\ClassMethod $Node)
28452837 new \PhpParser \Node \Expr \Variable ("__softmocksvariableforcode " )
28462838 );
28472839
2848- if ($ Node ->returnType instanceof \PhpParser \Node \Identifier && $ Node ->returnType ->name === 'void ' ) {
2840+ $ returnTypeName = $ Node ->returnType instanceof \PhpParser \Node \Identifier ? $ Node ->returnType ->name : null ;
2841+ if ($ returnTypeName === 'void ' ) {
28492842 $ body_stmts [] = new \PhpParser \Node \Stmt \Expression ($ eval );
28502843 $ body_stmts [] = new \PhpParser \Node \Stmt \Return_ ();
2844+ } elseif ($ returnTypeName === 'never ' ) {
2845+ $ body_stmts [] = new \PhpParser \Node \Stmt \Expression ($ eval );
28512846 } else {
28522847 $ body_stmts [] = new \PhpParser \Node \Stmt \Return_ ($ eval );
28532848 }
0 commit comments