8000 feature #23262 Add scalar typehints/return types (chalasr, xabbuh) · symfony/routing@aa88469 · GitHub
[go: up one dir, main page]

Skip to content

Commit aa88469

Browse files
committed
feature #23262 Add scalar typehints/return types (chalasr, xabbuh)
This PR was merged into the 4.0-dev branch. Discussion ---------- Add scalar typehints/return types | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no (final, already breaks if doc not respected) | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony#23242 (comment) | License | MIT | Doc PR | n/a Commits ------- 7b1715b078 [Yaml] use scalar type hints where possible 6ce70e4bf9 Add scalar typehints/return types on final/internal/private code
2 parents a2193cc + a099785 commit aa88469

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

Matcher/Dumper/DumperRoute.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,18 @@ class DumperRoute
3232
*/
3333
private $route;
3434

35-
/**
36-
* Constructor.
37-
*
38-
* @param string $name The route name
39-
* @param Route $route The route
40-
*/
41-
public function __construct($name, Route $route)
35+
public function __construct(string $name, Route $route)
4236
{
4337
$this->name = $name;
4438
$this->route = $route;
4539
}
4640

47-
/**
48-
* Returns the route name.
49-
*
50-
* @return string The route name
51-
*/
52-
public function getName()
41+
public function getName(): string
5342
{
5443
return $this->name;
5544
}
5645

57-
/**
58-
* Returns the route.
59-
*
60-
* @return Route The route
61-
*/
62-
public function getRoute()
46+
public function getRoute(): Route
6347
{
6448
return $this->route;
6549
}

Matcher/Dumper/StaticPrefixCollection.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ class StaticPrefixCollection
3535
*/
3636
private $matchStart = 0;
3737

38-
public function __construct($prefix = '')
38+
public function __construct(string $prefix = '')
3939
{
4040
$this->prefix = $prefix;
4141
}
4242

43-
public function getPrefix()
43+
public function getPrefix(): string
4444
{
4545
return $this->prefix;
4646
}
4747

4848
/**
4949
* @return mixed[]|StaticPrefixCollection[]
5050
*/
51-
public function getItems()
51+
public function getItems(): array
5252
{
5353
return $this->items;
5454
}
@@ -59,7 +59,7 @@ public function getItems()
5959
* @param string $prefix
6060
* @param mixed $route
6161
*/
62-
public function addRoute($prefix, $route)
62+
public function addRoute(string $prefix, $route)
6363
{
6464
$prefix = '/' === $prefix ? $prefix : rtrim($prefix, '/');
6565
$this->guardAgainstAddingNotAcceptedRoutes($prefix);
@@ -108,7 +108,7 @@ public function addRoute($prefix, $route)
108108
*
109109
* @return null|StaticPrefixCollection
110110
*/
111-
private function groupWithItem($item, $prefix, $route)
111+
private function groupWithItem($item, string $prefix, $route)
112112
{
113113
$itemPrefix = $item instanceof self ? $item->prefix : $item[0];
114114
$commonPrefix = $this->detectCommonPrefix($prefix, $itemPrefix);
@@ -137,7 +137,7 @@ private function groupWithItem($item, $prefix, $route)
137137
*
138138
* @return bool Whether a prefix could belong in a given group
139139
*/
140-
private function accepts($prefix)
140+
private function accepts(string $prefix): bool
141141
{
142142
return '' === $this->prefix || strpos($prefix, $this->prefix) === 0;
143143
}
@@ -150,7 +150,7 @@ private function accepts($prefix)
150150
*
151151
* @return false|string A common prefix, longer than the base/group prefix, or false when none available
152152
*/
153-
private function detectCommonPrefix($prefix, $anotherPrefix)
153+
private function detectCommonPrefix(string $prefix, string $anotherPrefix)
154154
{
155155
$baseLength = strlen($this->prefix);
156156
$commonLength = $baseLength;
@@ -176,7 +176,7 @@ private function detectCommonPrefix($prefix, $anotherPrefix)
176176
/**
177177
* Optimizes the tree by inlining items from groups with less than 3 items.
178178
*/
179-
public function optimizeGroups()
179+
public function optimizeGroups(): void
180180
{
181181
$index = -1;
182182

@@ -199,7 +199,7 @@ public function optimizeGroups()
199199
}
200200
}
201201

202-
private function shouldBeInlined()
202+
private function shouldBeInlined(): bool
203203
{
204204
if (count($this->items) >= 3) {
205205
return false;
@@ -227,7 +227,7 @@ private function shouldBeInlined()
227227
*
228228
* @throws \LogicException When a prefix does not belong in a group.
229229
*/
230-
private function guardAgainstAddingNotAcceptedRoutes($prefix)
230+
private function guardAgainstAddingNotAcceptedRoutes(string $prefix)
231231
{
232232
if (!$this->accepts($prefix)) {
233233
$message = sprintf('Could not add route with prefix %s to collection with prefix %s', $prefix, $this->prefix);

RouteCollectionBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function setMethods($methods)
258258
*
259259
* @return $this
260260
*/
261-
private function addResource(ResourceInterface $resource)
261+
private function addResource(ResourceInterface $resource): RouteCollectionBuilder
262262
{
263263
$this->resources[] = $resource;
264264

@@ -356,7 +356,7 @@ private function generateRouteName(Route $route)
356356
*
357357
* @throws FileLoaderLoadException If no loader is found
358358
*/
359-
private function load($resource, $type = null)
359+
private function load($resource, string $type = null): array
360360
{
361361
if (null === $this->loader) {
362362
throw new \BadMethodCallException('Cannot import other routing resources: you must pass a LoaderInterface when constructing RouteCollectionBuilder.');

0 commit comments

Comments
 (0)
0