File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ public function annotate(string $path): bool {
2020 throw new RuntimeException ('Cannot read file ' );
2121 }
2222
23- if ($ this ->hasAnnotation ($ content )) {
23+ if ($ this ->hasAnnotation ($ content ) || ! $ this -> needsAnnotation ( $ content ) ) {
2424 return false ;
2525 }
2626
@@ -56,4 +56,13 @@ protected function hasAnnotation(string $content): bool {
5656 return (bool )preg_match ('/\* @var .+ \\\\RouteBuilder \\$routes/ ' , $ content );
5757 }
5858
59+ /**
60+ * @param string $content
61+ *
62+ * @return bool
63+ */
64+ protected function needsAnnotation (string $ content ): bool {
65+ return !(bool )preg_match ('/return\s*(static)?\s*function \(RouteBuilder \$\w+\)/ ' , $ content );
66+ }
67+
5968}
Original file line number Diff line number Diff line change @@ -136,6 +136,44 @@ public function testHasAnnotation() {
136136 $ this ->assertTrue ($ result );
137137 }
138138
139+ /**
140+ * @return void
141+ */
142+ public function testNeedsAnnotationTrue () {
143+ $ annotator = $ this ->_getAnnotatorMock ([]);
144+
145+ $ content = <<<'PHP'
146+ /**
147+ */
148+ $routes->scope()
149+ PHP;
150+ $ result = $ this ->invokeMethod ($ annotator , 'needsAnnotation ' , [$ content ]);
151+ $ this ->assertTrue ($ result );
152+ }
153+
154+ /**
155+ * @return void
156+ */
157+ public function testNeedsAnnotationFalse () {
158+ $ annotator = $ this ->_getAnnotatorMock ([]);
159+
160+ $ content = <<<'PHP'
161+ /**
162+ */
163+ return static function (RouteBuilder $x) {
164+ PHP;
165+ $ result = $ this ->invokeMethod ($ annotator , 'needsAnnotation ' , [$ content ]);
166+ $ this ->assertFalse ($ result );
167+
168+ $ content = <<<'PHP'
169+ /**
170+ */
171+ return function (RouteBuilder $y) {
172+ PHP;
173+ $ result = $ this ->invokeMethod ($ annotator , 'needsAnnotation ' , [$ content ]);
174+ $ this ->assertFalse ($ result );
175+ }
176+
139177 /**
140178 * @param array $params
141179 * @return \IdeHelper\Annotator\RoutesAnnotator|\PHPUnit\Framework\MockObject\MockObject
You can’t perform that action at this time.
0 commit comments