Skip to content

Navigation Menu

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

Appearance settings

Commit cae7ff1

Browse filesBrowse files
committed
add phpdoc and check aliases array content in setter
1 parent 107a0c7 commit cae7ff1
Copy full SHA for cae7ff1

File tree

2 files changed

+17
-10
lines changed
Filter options

2 files changed

+17
-10
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Attribute/Route.php
+14-8Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Routing\Attribute;
1313

14+
use Symfony\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 ($alias as $a) {
73-
if (!\is_string($a)) {
74-
throw new \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
public function setAliases(array|string $aliases): void
223222
{
223+
if (\is_array($aliases)) {
224+
foreach ($aliases as $a) {
225+
if (!\is_string($a)) {
226+
throw new InvalidArgumentException(\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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Attribute/RouteTest.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

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

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

3031
public function testAliasIsAnArrayOfString()
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 got stdClass.');
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
new Route('/hello', alias: ['alias', new \stdClass()]);
3637
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.