@@ -475,43 +475,50 @@ private function checkUselessDocComment(\PHP_CodeSniffer_File $phpcsFile, int $f
475475 return TypeHintHelper::isSimpleTypeHint ($ typeHint ) || TypeHintHelper::getFullyQualifiedTypeHint ($ phpcsFile , $ functionPointer , $ typeHint ) === TypeHintHelper::getFullyQualifiedTypeHint ($ phpcsFile , $ functionPointer , $ typeHintInAnnotation );
476476 };
477477
478- $ returnTypeHint = FunctionHelper::findReturnTypeHint ($ phpcsFile , $ functionPointer );
479478 if ($ isAbstract || FunctionHelper::returnsValue ($ phpcsFile , $ functionPointer )) {
480- if ($ returnTypeHint === null ) {
481- return ;
482- }
483-
484- if ($ this ->isTraversableTypeHint (TypeHintHelper::getFullyQualifiedTypeHint ($ phpcsFile , $ functionPointer , $ returnTypeHint ->getTypeHint ()))) {
485- return ;
486- }
487-
479+ $ returnTypeHint = FunctionHelper::findReturnTypeHint ($ phpcsFile , $ functionPointer );
488480 $ returnAnnotation = FunctionHelper::findReturnAnnotation ($ phpcsFile , $ functionPointer );
481+
489482 if ($ returnAnnotation !== null ) {
490- if (preg_match ( ' ~^ \\ S+ \\ s+ \\ S+~ ' , $ returnAnnotation -> getContent ()) ) {
483+ if ($ returnTypeHint === null ) {
491484 return ;
492485 }
493486
494- $ returnTypeHintsDefinition = preg_split ('~ \\s+~ ' , $ returnAnnotation ->getContent ())[0 ];
495- if ($ this ->definitionContainsStaticOrThisTypeHint ($ returnTypeHintsDefinition )) {
487+ if ($ this ->isTraversableTypeHint (TypeHintHelper::getFullyQualifiedTypeHint ($ phpcsFile , $ functionPointer , $ returnTypeHint ->getTypeHint ()))) {
496488 return ;
497- } elseif ($ this ->enableNullableTypeHints && $ this ->definitionContainsJustTwoTypeHints ($ returnTypeHintsDefinition ) && $ this ->definitionContainsNullTypeHint ($ returnTypeHintsDefinition )) {
498- $ returnTypeHintDefinitionParts = explode ('| ' , $ returnTypeHintsDefinition );
499- $ returnTypeHintInAnnotation = strtolower ($ returnTypeHintDefinitionParts [0 ]) === 'null ' ? $ returnTypeHintDefinitionParts [1 ] : $ returnTypeHintDefinitionParts [0 ];
500- if (!$ typeHintEqualsAnnotation ($ returnTypeHint ->getTypeHint (), $ returnTypeHintInAnnotation )) {
489+ }
490+
491+ if ($ returnAnnotation !== null ) {
492+ if (preg_match ('~^ \\S+ \\s+ \\S+~ ' , $ returnAnnotation ->getContent ())) {
493+ return ;
494+ }
495+
496+ $ returnTypeHintsDefinition = preg_split ('~ \\s+~ ' , $ returnAnnotation ->getContent ())[0 ];
497+ if ($ this ->definitionContainsStaticOrThisTypeHint ($ returnTypeHintsDefinition )) {
498+ return ;
499+ } elseif ($ this ->enableNullableTypeHints && $ this ->definitionContainsJustTwoTypeHints ($ returnTypeHintsDefinition ) && $ this ->definitionContainsNullTypeHint ($ returnTypeHintsDefinition )) {
500+ $ returnTypeHintDefinitionParts = explode ('| ' , $ returnTypeHintsDefinition );
501+ $ returnTypeHintInAnnotation = strtolower ($ returnTypeHintDefinitionParts [0 ]) === 'null ' ? $ returnTypeHintDefinitionParts [1 ] : $ returnTypeHintDefinitionParts [0 ];
502+ if (!$ typeHintEqualsAnnotation ($ returnTypeHint ->getTypeHint (), $ returnTypeHintInAnnotation )) {
503+ return ;
504+ }
505+ } elseif (!$ this ->definitionContainsOneTypeHint ($ returnTypeHintsDefinition )) {
506+ return ;
507+ } elseif (!$ typeHintEqualsAnnotation ($ returnTypeHint ->getTypeHint (), $ returnTypeHintsDefinition )) {
501508 return ;
502509 }
503- } elseif (!$ this ->definitionContainsOneTypeHint ($ returnTypeHintsDefinition )) {
504- return ;
505- } elseif (!$ typeHintEqualsAnnotation ($ returnTypeHint ->getTypeHint (), $ returnTypeHintsDefinition )) {
506- return ;
507510 }
508511 }
509512 }
510513
511514 $ parametersTypeHintsDefinitions = $ this ->getFunctionParameterTypeHintsDefinitions ($ phpcsFile , $ functionPointer );
512515 foreach (FunctionHelper::getParametersTypeHints ($ phpcsFile , $ functionPointer ) as $ parameterName => $ parameterTypeHint ) {
513516 if ($ parameterTypeHint === null ) {
514- return ;
517+ if (array_key_exists ($ parameterName , $ parametersTypeHintsDefinitions )) {
518+ return ;
519+ } else {
520+ continue ;
521+ }
515522 }
516523
517524 if ($ this ->isTraversableTypeHint (TypeHintHelper::getFullyQualifiedTypeHint ($ phpcsFile , $ functionPointer , $ parameterTypeHint ->getTypeHint ()))) {
0 commit comments