Skip to content

Commit fdd2aaf

Browse files
committed
Allow symfony 6 and add requirement typehints
1 parent bbcdf2f commit fdd2aaf

14 files changed

+48
-49
lines changed

.github/workflows/test-application.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ jobs:
3131
symfony-require: "5.0.*"
3232

3333
- php-version: "8.0"
34-
symfony-require: "*"
34+
symfony-require: "5.0.*"
35+
36+
- php-version: "8.0"
37+
symfony-require: "6.0.*"
3538

3639
steps:
3740
- name: "Checkout project"

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
],
1717
"require": {
1818
"php": "^7.2 || ^8.0",
19-
"symfony/routing": "^4.4 || ^5.0",
20-
"symfony/http-kernel": "^4.4 || ^5.0",
19+
"symfony/routing": "^4.4 || ^5.0 || ^6.0",
20+
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
2121
"psr/log": "^1.0 || ^2.0 || ^3.0"
2222
},
2323
"require-dev": {
24-
"symfony/phpunit-bridge": "^5.0",
25-
"symfony/dependency-injection": "^4.4 || ^5.0",
26-
"symfony/config": "^4.4 || ^5.0",
27-
"symfony/event-dispatcher": "^4.4 || ^5.0",
24+
"symfony/phpunit-bridge": "^5.4 || ^6.0",
25+
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
26+
"symfony/config": "^4.4 || ^5.0 || ^6.0",
27+
"symfony/event-dispatcher": "^4.4 || ^5.0 || ^6.0",
2828
"symfony-cmf/testing": "^3@dev"
2929
},
3030
"suggest": {

src/ChainRouteCollection.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,15 @@ public function __clone()
4343
*
4444
* @return \ArrayIterator An \ArrayIterator object for iterating over routes
4545
*/
46-
public function getIterator()
46+
public function getIterator(): \ArrayIterator
4747
{
4848
return new \ArrayIterator($this->all());
4949
}
5050

5151
/**
5252
* Gets the number of Routes in this collection.
53-
*
54-
* @return int The number of routes
5553
*/
56-
public function count()
54+
public function count(): int
5755
{
5856
$count = 0;
5957
foreach ($this->routeCollections as $routeCollection) {
@@ -81,7 +79,7 @@ public function add($name, Route $route, int $priority = 0)
8179
*
8280
* @return Route[] An array of routes
8381
*/
84-
public function all()
82+
public function all(): array
8583
{
8684
$routeCollectionAll = new RouteCollection();
8785
foreach ($this->routeCollections as $routeCollection) {
@@ -95,17 +93,17 @@ public function all()
9593
* Gets a route by name.
9694
*
9795
* @param string $name The route name
98-
*
99-
* @return Route|null A Route instance or null when not found
10096
*/
101-
public function get($name)
97+
public function get($name): ?Route
10298
{
10399
foreach ($this->routeCollections as $routeCollection) {
104100
$route = $routeCollection->get($name);
105101
if (null !== $route) {
106102
return $route;
107103
}
108104
}
105+
106+
return null;
109107
}
110108

111109
/**
@@ -240,7 +238,7 @@ public function setMethods($methods)
240238
*
241239
* @return ResourceInterface[] An array of resources
242240
*/
243-
public function getResources()
241+
public function getResources(): array
244242
{
245243
if (0 === count($this->routeCollections)) {
246244
return [];

src/ChainRouter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function __construct(LoggerInterface $logger = null)
7070
/**
7171
* @return RequestContext
7272
*/
73-
public function getContext()
73+
public function getContext(): RequestContext
7474
{
7575
if (!$this->context) {
7676
$this->context = new RequestContext();
@@ -143,7 +143,7 @@ protected function sortRouters()
143143
*
144144
* Note: You should use matchRequest if you can.
145145
*/
146-
public function match($pathinfo)
146+
public function match($pathinfo): array
147147
{
148148
return $this->doMatch($pathinfo);
149149
}
@@ -153,7 +153,7 @@ public function match($pathinfo)
153153
*
154154
* Loops through all routes and tries to match the passed request.
155155
*/
156-
public function matchRequest(Request $request)
156+
public function matchRequest(Request $request): array
157157
{
158158
return $this->doMatch($request->getPathInfo(), $request);
159159
}
@@ -213,7 +213,7 @@ private function doMatch($pathinfo, Request $request = null)
213213
/**
214214
* {@inheritdoc}
215215
*
216-
* @param mixed $name
216+
* @param string $name
217217
*
218218
* The CMF routing system used to allow to pass route objects as $name to generate the route.
219219
* Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract
@@ -224,7 +224,7 @@ private function doMatch($pathinfo, Request $request = null)
224224
* Loops through all registered routers and returns a router if one is found.
225225
* It will always return the first route generated.
226226
*/
227-
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
227+
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH): string
228228
{
229229
if (is_object($name)) {
230230
@trigger_error('Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`.', E_USER_DEPRECATED);

src/ContentAwareGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function setContentRepository(ContentRepositoryInterface $contentReposito
7171
*
7272
* @throws RouteNotFoundException If there is no such route in the database
7373
*/
74-
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
74+
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH): string
7575
{
7676
if ($name instanceof SymfonyRoute) {
7777
@trigger_error('Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT` resp the content id with content_id.', E_USER_DEPRECATED);

src/DynamicRouter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ public function getGenerator()
159159
* Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object
160160
* in the parameters with key RouteObjectInterface::ROUTE_OBJECT.
161161
*
162-
* @param string|Route $name The name of the route or the Route instance
162+
* @param string $name The name of the route
163163
*
164164
* @throws RouteNotFoundException if route doesn't exist
165165
*/
166-
public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
166+
public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string
167167
{
168168
if (is_object($name)) {
169169
@trigger_error('Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT', E_USER_DEPRECATED);
@@ -213,7 +213,7 @@ public function supports($name)
213213
*
214214
* @api
215215
*/
216-
public function match($pathinfo)
216+
public function match($pathinfo): array
217217
{
218218
@trigger_error(__METHOD__.'() is deprecated since version 1.3 and will be removed in 2.0. Use matchRequest() instead.', E_USER_DEPRECATED);
219219

@@ -252,7 +252,7 @@ public function match($pathinfo)
252252
* @throws MethodNotAllowedException If a matching resource was found but
253253
* the request method is not allowed
254254
*/
255-
public function matchRequest(Request $request)
255+
public function matchRequest(Request $request): array
256256
{
257257
if ($this->eventDispatcher) {
258258
$event = new RouterMatchEvent($request);
@@ -294,7 +294,7 @@ public function setContext(RequestContext $context)
294294
*
295295
* @api
296296
*/
297-
public function getContext()
297+
public function getContext(): RequestContext
298298
{
299299
return $this->context;
300300
}

src/LazyRouteCollection.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ public function __construct(RouteProviderInterface $provider)
3232
/**
3333
* {@inheritdoc}
3434
*/
35-
public function getIterator()
35+
public function getIterator(): \ArrayIterator
3636
{
3737
return new \ArrayIterator($this->all());
3838
}
3939

4040
/**
4141
* Gets the number of Routes in this collection.
42-
*
43-
* @return int The number of routes
4442
*/
45-
public function count()
43+
public function count(): int
4644
{
4745
return count($this->all());
4846
}
@@ -52,7 +50,7 @@ public function count()
5250
*
5351
* @return Route[] An array of routes
5452
*/
55-
public function all()
53+
public function all(): array
5654
{
5755
return $this->provider->getRoutesByNames(null);
5856
}
@@ -61,15 +59,13 @@ public function all()
6159
* Gets a route by name.
6260
*
6361
* @param string $name The route name
64-
*
65-
* @return Route|null A Route instance or null when not found
6662
*/
67-
public function get($name)
63+
public function get($name): ?Route
6864
{
6965
try {
7066
return $this->provider->getRouteByName($name);
7167
} catch (RouteNotFoundException $e) {
72-
return;
68+
return null;
7369
}
7470
}
7571
}

src/NestedMatcher/NestedMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function setFinalMatcher(FinalMatcherInterface $final)
135135
/**
136136
* {@inheritdoc}
137137
*/
138-
public function matchRequest(Request $request)
138+
public function matchRequest(Request $request): array
139139
{
140140
$collection = $this->routeProvider->getRouteCollectionForRequest($request);
141141
if (!count($collection)) {

src/NestedMatcher/UrlMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function finalMatch(RouteCollection $collection, Request $request)
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
protected function getAttributes(Route $route, $name, array $attributes)
46+
protected function getAttributes(Route $route, $name, array $attributes): array
4747
{
4848
if ($route instanceof RouteObjectInterface && is_string($route->getRouteKey())) {
4949
$name = $route->getRouteKey();

src/PagedRouteCollection.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ protected function loadNextElements($offset)
6969
}
7070

7171
/**
72-
* {@inheritdoc}
72+
* @return mixed
7373
*/
74+
#[\ReturnTypeWillChange]
7475
public function current()
7576
{
7677
return current($this->currentRoutes);
@@ -79,7 +80,7 @@ public function current()
7980
/**
8081
* {@inheritdoc}
8182
*/
82-
public function next()
83+
public function next(): void
8384
{
8485
$result = next($this->currentRoutes);
8586
if (false === $result) {
@@ -89,8 +90,9 @@ public function next()
8990
}
9091

9192
/**
92-
* {@inheritdoc}
93+
* @return mixed
9394
*/
95+
#[\ReturnTypeWillChange]
9496
public function key()
9597
{
9698
return key($this->currentRoutes);
@@ -99,15 +101,15 @@ public function key()
99101
/**
100102
* {@inheritdoc}
101103
*/
102-
public function valid()
104+
public function valid(): bool
103105
{
104-
return key($this->currentRoutes);
106+
return null !== key($this->currentRoutes);
105107
}
106108

107109
/**
108110
* {@inheritdoc}
109111
*/
110-
public function rewind()
112+
public function rewind(): void
111113
{
112114
$this->current = 0;
113115
$this->currentRoutes = null;

0 commit comments

Comments
 (0)