Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcae7ff1

Browse files
committed
add phpdoc and check aliases array content in setter
1 parent107a0c7 commitcae7ff1

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

‎src/Symfony/Component/Routing/Attribute/Route.php‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespaceSymfony\Component\Routing\Attribute;
1313

14+
useSymfony\Component\Routing\Exception\InvalidArgumentException;
15+
1416
/**
1517
* @author Fabien Potencier <fabien@symfony.com>
1618
* @author Alexander M. Turek <me@derrabus.de>
@@ -67,14 +69,6 @@ public function __construct(
6769
}
6870
$this->setMethods($methods);
6971
$this->setSchemes($schemes);
70-
71-
if (\is_array($alias)) {
72-
foreach ($aliasas$a) {
73-
if (!\is_string($a)) {
74-
thrownew \TypeError(\sprintf('The "alias" argument of the Route attribute must be a string or an array of strings, but got "%s".',\get_debug_type($a)));
75-
}
76-
}
77-
}
7872
$this->setAliases($alias);
7973

8074
if (null !==$locale) {
@@ -219,8 +213,20 @@ public function getAliases(): array
219213
return$this->aliases;
220214
}
221215

216+
/**
217+
* @param list<string>|string $aliases
218+
*
219+
* @throws InvalidArgumentException if the "alias" argument is not a string or an array of strings
220+
*/
222221
publicfunctionsetAliases(array|string$aliases):void
223222
{
223+
if (\is_array($aliases)) {
224+
foreach ($aliasesas$a) {
225+
if (!\is_string($a)) {
226+
thrownewInvalidArgumentException(\sprintf('The "alias" argument of the Route attribute must be a string or an array of strings. Got "%s".',\get_debug_type($a)));
227+
}
228+
}
229+
}
224230
$this->aliases = (array)$aliases;
225231
}
226232
}

‎src/Symfony/Component/Routing/Tests/Attribute/RouteTest.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
usePHPUnit\Framework\TestCase;
1515
useSymfony\Component\Routing\Attribute\Route;
16+
useSymfony\Component\Routing\Exception\InvalidArgumentException;
1617
useSymfony\Component\Routing\Tests\Fixtures\AttributeFixtures\FooController;
1718

1819
class RouteTestextends TestCase
@@ -29,8 +30,8 @@ public function testLoadFromAttribute(string $methodName, string $getter, mixed
2930

3031
publicfunctiontestAliasIsAnArrayOfString()
3132
{
32-
$this->expectException(\TypeError::class);
33-
$this->expectExceptionMessage('The "alias" argument of the Route attribute must be a string or an array of strings, but gotstdClass.');
33+
$this->expectException(InvalidArgumentException::class);
34+
$this->expectExceptionMessage('The "alias" argument of the Route attribute must be a string or an array of strings. Got "stdClass".');
3435

3536
newRoute('/hello', alias: ['alias',new \stdClass()]);
3637
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp