Skip to content

Commit 3c66164

Browse files
committed
code improved
1 parent f9cc3b8 commit 3c66164

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/Attribute/Route.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ private function assertValidMethods() : void
286286
throw new InvalidDescriptorArgumentException('#[Route.methods] must contain at least one element.');
287287
}
288288

289-
foreach ($this->methods as $method) {
290-
if ('' === $method || !is_string($method)) {
289+
foreach ($this->methods as $value) {
290+
if ('' === $value || !is_string($value)) {
291291
throw new InvalidDescriptorArgumentException('#[Route.methods] must contain non-empty strings.');
292292
}
293293
}
@@ -306,13 +306,11 @@ private function assertValidMiddlewares() : void
306306
return;
307307
}
308308

309-
foreach ($this->middlewares as $middleware) {
310-
if ('' === $middleware || !is_string($middleware)) {
311-
throw new InvalidDescriptorArgumentException('#[Route.middlewares] must contain non-empty strings.');
312-
}
313-
314-
if (!is_subclass_of($middleware, MiddlewareInterface::class)) {
315-
throw new InvalidDescriptorArgumentException('#[Route.middlewares] must contain existing middlewares.');
309+
foreach ($this->middlewares as $value) {
310+
if ('' === $value || !is_string($value) || !is_subclass_of($value, MiddlewareInterface::class)) {
311+
throw new InvalidDescriptorArgumentException(
312+
'#[Route.middlewares] must contain the class names of existing middlewares.'
313+
);
316314
}
317315
}
318316
}
@@ -330,8 +328,8 @@ private function assertValidTags() : void
330328
return;
331329
}
332330

333-
foreach ($this->tags as $tag) {
334-
if ('' === $tag || !is_string($tag)) {
331+
foreach ($this->tags as $value) {
332+
if ('' === $value || !is_string($value)) {
335333
throw new InvalidDescriptorArgumentException('#[Route.tags] must contain non-empty strings.');
336334
}
337335
}

tests/Attribute/RouteTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function testConstructorWithInvalidMethod($invalidMethod) : void
162162
public function testConstructorWithInvalidMiddleware($invalidMiddleware) : void
163163
{
164164
$this->expectException(InvalidDescriptorArgumentException::class);
165-
$this->expectExceptionMessage('#[Route.middlewares] must contain non-empty strings.');
165+
$this->expectExceptionMessage('#[Route.middlewares] must contain the class names of existing middlewares.');
166166

167167
new Route('foo', null, '/foo', ['GET'], [$invalidMiddleware]);
168168
}
@@ -186,7 +186,7 @@ public function testConstructorWithInvalidTag($invalidTag) : void
186186
public function testConstructorWithNonexistentMiddleware() : void
187187
{
188188
$this->expectException(InvalidDescriptorArgumentException::class);
189-
$this->expectExceptionMessage('#[Route.middlewares] must contain existing middlewares.');
189+
$this->expectExceptionMessage('#[Route.middlewares] must contain the class names of existing middlewares.');
190190

191191
new Route('foo', null, '/foo', ['GET'], ['nonexistentClass']);
192192
}
@@ -197,7 +197,7 @@ public function testConstructorWithNonexistentMiddleware() : void
197197
public function testConstructorWithNonMiddlewareMiddleware() : void
198198
{
199199
$this->expectException(InvalidDescriptorArgumentException::class);
200-
$this->expectExceptionMessage('#[Route.middlewares] must contain existing middlewares.');
200+
$this->expectExceptionMessage('#[Route.middlewares] must contain the class names of existing middlewares.');
201201

202202
new Route('foo', null, '/foo', ['GET'], [stdClass::class]);
203203
}

0 commit comments

Comments
 (0)