Skip to content

Commit dc448c4

Browse files
committed
Fix up routes for new approach.
1 parent 8e884f1 commit dc448c4

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/Annotator/RoutesAnnotator.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

tests/TestCase/Annotator/RoutesAnnotatorTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)