@@ -235,9 +235,16 @@ private function isMethodReadable(\ReflectionMethod $method)
235235 if ('_ ' === substr ($ method ->getName (), 0 , 1 )) {
236236 return false ;
237237 }
238-
239- // if method has NoRoute annotation - skip
240- if ($ this ->readMethodAnnotation ($ method , 'NoRoute ' )) {
238+
239+ $ hasNoRouteMethod = (bool ) $ this ->readMethodAnnotation ($ method , 'NoRoute ' );
240+ $ hasNoRouteClass = (bool ) $ this ->readClassAnnotation ($ method ->getDeclaringClass (), 'NoRoute ' );
241+
242+ $ hasNoRoute = $ hasNoRoute = $ hasNoRouteMethod || $ hasNoRouteClass ;
243+ // since NoRoute extends Route we need to exclude all the method NoRoute annotations
244+ $ hasRoute = (bool ) $ this ->readMethodAnnotation ($ method , 'Route ' ) && !$ hasNoRouteMethod ;
245+
246+ // if method has NoRoute annotation and does not have Route annotation - skip
247+ if ($ hasNoRoute && !$ hasRoute ) {
241248 return false ;
242249 }
243250
@@ -426,6 +433,23 @@ private function readRouteAnnotation(\ReflectionMethod $reflection)
426433 }
427434 }
428435
436+ /**
437+ * Reads class annotations.
438+ *
439+ * @param ReflectionClass $reflection controller class
440+ * @param string $annotationName annotation name
441+ *
442+ * @return Annotation|null
443+ */
444+ private function readClassAnnotation (\ReflectionClass $ reflection , $ annotationName )
445+ {
446+ $ annotationClass = "FOS \\RestBundle \\Controller \\Annotations \\$ annotationName " ;
447+
448+ if ($ annotation = $ this ->annotationReader ->getClassAnnotation ($ reflection , $ annotationClass )) {
449+ return $ annotation ;
450+ }
451+ }
452+
429453 /**
430454 * Reads method annotations.
431455 *
0 commit comments