Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 0401758

Browse files
committed
Merge branch 'feature/538-more-types' into release-3.0.0
Close #538
2 parents c2f9e32 + 70b9e18 commit 0401758

24 files changed

+68
-236
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ All notable changes to this project will be documented in this file, in reverse
99
- [#529](https://github.com/zendframework/zend-expressive/pull/529) adds support
1010
for PSR-15.
1111

12+
- [#538](https://github.com/zendframework/zend-expressive/pull/538) adds scalar
13+
and return type hints to methods wherever possible.
14+
1215
### Changed
1316

1417
- Nothing.

src/AppFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ final class AppFactory
4141
* instance
4242
* @param null|Router\RouterInterface $router Router implementation to use;
4343
* defaults to the FastRoute router bridge.
44-
* @return Application
4544
* @throws Exception\MissingDependencyException if the container was not
4645
* provided and the ServiceManager class is not present.
4746
* @throws Exception\MissingDependencyException if the router was not
@@ -50,7 +49,7 @@ final class AppFactory
5049
public static function create(
5150
ContainerInterface $container = null,
5251
Router\RouterInterface $router = null
53-
) {
52+
) : Application {
5453
if (! $container && ! class_exists(ServiceManager::class)) {
5554
throw new Exception\MissingDependencyException(sprintf(
5655
'%s requires a container, but none was provided and %s is not installed',

src/Application.php

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,9 @@ class Application extends MiddlewarePipe
8181
private $responsePrototype;
8282

8383
/**
84-
* Constructor
85-
*
8684
* Calls on the parent constructor, and then uses the provided arguments
8785
* to set internal properties.
8886
*
89-
* @param Router\RouterInterface $router
9087
* @param null|ContainerInterface $container IoC container from which to pull services, if any.
9188
* @param null|RequestHandlerInterface $defaultDelegate Default delegate
9289
* to use when $out is not provided on invocation / run() is invoked.
@@ -109,67 +106,55 @@ public function __construct(
109106
}
110107

111108
/**
112-
* @param string|Router\Route $path
113109
* @param callable|string $middleware Middleware (or middleware service name) to associate with route.
114110
* @param null|string $name The name of the route.
115-
* @return Router\Route
116111
*/
117-
public function get($path, $middleware, $name = null)
112+
public function get(string $path, $middleware, string $name = null) : Router\Route
118113
{
119114
return $this->route($path, $middleware, ['GET'], $name);
120115
}
121116

122117
/**
123-
* @param string|Router\Route $path
124118
* @param callable|string $middleware Middleware (or middleware service name) to associate with route.
125119
* @param null|string $name The name of the route.
126-
* @return Router\Route
127120
*/
128-
public function post($path, $middleware, $name = null)
121+
public function post(string $path, $middleware, $name = null) : Router\Route
129122
{
130123
return $this->route($path, $middleware, ['POST'], $name);
131124
}
132125

133126
/**
134-
* @param string|Router\Route $path
135127
* @param callable|string $middleware Middleware (or middleware service name) to associate with route.
136128
* @param null|string $name The name of the route.
137-
* @return Router\Route
138129
*/
139-
public function put($path, $middleware, $name = null)
130+
public function put(string $path, $middleware, string $name = null) : Router\Route
140131
{
141132
return $this->route($path, $middleware, ['PUT'], $name);
142133
}
143134

144135
/**
145-
* @param string|Router\Route $path
146136
* @param callable|string $middleware Middleware (or middleware service name) to associate with route.
147137
* @param null|string $name The name of the route.
148-
* @return Router\Route
149138
*/
150-
public function patch($path, $middleware, $name = null)
139+
public function patch(string $path, $middleware, string $name = null) : Router\Route
151140
{
152141
return $this->route($path, $middleware, ['PATCH'], $name);
153142
}
154143

155144
/**
156-
* @param string|Router\Route $path
157145
* @param callable|string $middleware Middleware (or middleware service name) to associate with route.
158146
* @param null|string $name The name of the route.
159-
* @return Router\Route
160147
*/
161-
public function delete($path, $middleware, $name = null)
148+
public function delete(string $path, $middleware, string $name = null) : Router\Route
162149
{
163150
return $this->route($path, $middleware, ['DELETE'], $name);
164151
}
165152

166153
/**
167-
* @param string|Router\Route $path
168154
* @param callable|string $middleware Middleware (or middleware service name) to associate with route.
169155
* @param null|string $name The name of the route.
170-
* @return Router\Route
171156
*/
172-
public function any($path, $middleware, $name = null)
157+
public function any(string $path, $middleware, string $name = null) : Router\Route
173158
{
174159
return $this->route($path, $middleware, null, $name);
175160
}
@@ -206,7 +191,7 @@ public function any($path, $middleware, $name = null)
206191
*
207192
* @param string|array|callable $path Either a URI path prefix, or middleware.
208193
* @param null|string|array|callable $middleware Middleware
209-
* @return self
194+
* @return $this
210195
*/
211196
public function pipe($path, $middleware = null) : parent
212197
{
@@ -254,10 +239,8 @@ public function pipe($path, $middleware = null) : parent
254239

255240
/**
256241
* Register the routing middleware in the middleware pipeline.
257-
*
258-
* @return void
259242
*/
260-
public function pipeRoutingMiddleware()
243+
public function pipeRoutingMiddleware() : void
261244
{
262245
if ($this->routeMiddlewareIsRegistered) {
263246
return;
@@ -267,10 +250,8 @@ public function pipeRoutingMiddleware()
267250

268251
/**
269252
* Register the dispatch middleware in the middleware pipeline.
270-
*
271-
* @return void
272253
*/
273-
public function pipeDispatchMiddleware()
254+
public function pipeDispatchMiddleware() : void
274255
{
275256
if ($this->dispatchMiddlewareIsRegistered) {
276257
return;
@@ -317,7 +298,7 @@ public function route(string $path, $middleware, array $methods = null, string $
317298
*
318299
* @return Router\Route[]
319300
*/
320-
public function getRoutes()
301+
public function getRoutes() : array
321302
{
322303
return $this->routes;
323304
}
@@ -334,12 +315,8 @@ public function getRoutes()
334315
*
335316
* Once it has processed itself, it emits the returned response using the
336317
* composed emitter.
337-
*
338-
* @param null|ServerRequestInterface $request
339-
* @param null|ResponseInterface $response
340-
* @return void
341318
*/
342-
public function run(ServerRequestInterface $request = null, ResponseInterface $response = null)
319+
public function run(ServerRequestInterface $request = null, ResponseInterface $response = null) : void
343320
{
344321
try {
345322
$request = $request ?: ServerRequestFactory::fromGlobals();
@@ -364,10 +341,9 @@ public function run(ServerRequestInterface $request = null, ResponseInterface $r
364341
*
365342
* If no IoC container is registered, we raise an exception.
366343
*
367-
* @return ContainerInterface
368344
* @throws Exception\ContainerNotRegisteredException
369345
*/
370-
public function getContainer()
346+
public function getContainer() : ContainerInterface
371347
{
372348
if (null === $this->container) {
373349
throw new Exception\ContainerNotRegisteredException();
@@ -384,10 +360,8 @@ public function getContainer()
384360
* service, pulls that service, assigns it, and returns it.
385361
* - If no container is composed, creates an instance of Delegate\NotFoundDelegate
386362
* using the current response prototype only (i.e., no templating).
387-
*
388-
* @return RequestHandlerInterface
389363
*/
390-
public function getDefaultDelegate()
364+
public function getDefaultDelegate() : RequestHandlerInterface
391365
{
392366
if ($this->defaultDelegate) {
393367
return $this->defaultDelegate;
@@ -413,10 +387,8 @@ public function getDefaultDelegate()
413387
*
414388
* If none was registered during instantiation, this will lazy-load an
415389
* EmitterStack composing an SapiEmitter instance.
416-
*
417-
* @return EmitterInterface
418390
*/
419-
public function getEmitter()
391+
public function getEmitter() : EmitterInterface
420392
{
421393
if (! $this->emitter) {
422394
$this->emitter = new Emitter\EmitterStack();
@@ -432,11 +404,9 @@ public function getEmitter()
432404
* if so, and it responds to any of the $methods indicated, raises
433405
* a DuplicateRouteException indicating a duplicate route.
434406
*
435-
* @param string $path
436-
* @param null|array $methods
437407
* @throws Exception\DuplicateRouteException on duplicate route detection.
438408
*/
439-
private function checkForDuplicateRoute($path, $methods = null)
409+
private function checkForDuplicateRoute(string $path, array $methods = null) : void
440410
{
441411
if (null === $methods) {
442412
$methods = Router\Route::HTTP_METHOD_ANY;
@@ -463,11 +433,7 @@ private function checkForDuplicateRoute($path, $methods = null)
463433
}
464434
}
465435

466-
/**
467-
* @param Throwable $exception
468-
* @return void
469-
*/
470-
private function emitMarshalServerRequestException(Throwable $exception)
436+
private function emitMarshalServerRequestException(Throwable $exception) : void
471437
{
472438
if ($this->container && $this->container->has(Middleware\ErrorResponseGenerator::class)) {
473439
$generator = $this->container->get(Middleware\ErrorResponseGenerator::class);

src/ApplicationConfigInjectionTrait.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ trait ApplicationConfigInjectionTrait
6767
*
6868
* @param null|array $config If null, attempts to pull the 'config' service
6969
* from the composed container.
70-
* @return void
7170
*/
72-
public function injectPipelineFromConfig(array $config = null)
71+
public function injectPipelineFromConfig(array $config = null) : void
7372
{
7473
if (null === $config) {
7574
$config = $this->container->has('config') ? $this->container->get('config') : [];
@@ -136,10 +135,9 @@ public function injectPipelineFromConfig(array $config = null)
136135
*
137136
* @param null|array $config If null, attempts to pull the 'config' service
138137
* from the composed container.
139-
* @return void
140138
* @throws Exception\InvalidArgumentException
141139
*/
142-
public function injectRoutesFromConfig(array $config = null)
140+
public function injectRoutesFromConfig(array $config = null) : void
143141
{
144142
if (null === $config) {
145143
$config = $this->container->has('config') ? $this->container->get('config') : [];
@@ -202,10 +200,9 @@ public function injectRoutesFromConfig(array $config = null)
202200
* If the 'middleware' value is missing, or not viable as middleware, it
203201
* raises an exception, to ensure the pipeline is built correctly.
204202
*
205-
* @return callable
206203
* @throws Exception\InvalidArgumentException
207204
*/
208-
private function createCollectionMapper()
205+
private function createCollectionMapper() : callable
209206
{
210207
$appMiddlewares = [
211208
Application::ROUTING_MIDDLEWARE,
@@ -240,10 +237,8 @@ private function createCollectionMapper()
240237
*
241238
* The function is useful to reduce an array of pipeline middleware to a
242239
* priority queue.
243-
*
244-
* @return callable
245240
*/
246-
private function createPriorityQueueReducer()
241+
private function createPriorityQueueReducer() : callable
247242
{
248243
// $serial is used to ensure that items of the same priority are enqueued
249244
// in the order in which they are inserted.

src/Container/ApplicationFactory.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,8 @@ class ApplicationFactory
5454
*
5555
* See the class level docblock for information on what services this
5656
* factory will optionally consume.
57-
*
58-
* @param ContainerInterface $container
59-
* @return Application
6057
*/
61-
public function __invoke(ContainerInterface $container)
58+
public function __invoke(ContainerInterface $container) : Application
6259
{
6360
$config = $container->has('config') ? $container->get('config') : [];
6461
$config = $config instanceof ArrayObject ? $config->getArrayCopy() : $config;
@@ -86,12 +83,8 @@ public function __invoke(ContainerInterface $container)
8683

8784
/**
8885
* Injects routes and the middleware pipeline into the application.
89-
*
90-
* @param Application $app
91-
* @param array $config
92-
* @return void
9386
*/
94-
private function injectRoutesAndPipeline(Application $app, array $config)
87+
private function injectRoutesAndPipeline(Application $app, array $config) : void
9588
{
9689
$app->injectRoutesFromConfig($config);
9790
$app->injectPipelineFromConfig($config);

src/Container/ErrorHandlerFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616

1717
class ErrorHandlerFactory
1818
{
19-
/**
20-
* @param ContainerInterface $container
21-
* @return ErrorHandler
22-
*/
23-
public function __invoke(ContainerInterface $container)
19+
public function __invoke(ContainerInterface $container) : ErrorHandler
2420
{
2521
$generator = $container->has(ErrorResponseGenerator::class)
2622
? $container->get(ErrorResponseGenerator::class)

src/Container/ErrorResponseGeneratorFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515

1616
class ErrorResponseGeneratorFactory
1717
{
18-
/**
19-
* @param ContainerInterface $container
20-
* @return ErrorResponseGenerator
21-
*/
22-
public function __invoke(ContainerInterface $container)
18+
public function __invoke(ContainerInterface $container) : ErrorResponseGenerator
2319
{
2420
$config = $container->has('config') ? $container->get('config') : [];
2521

src/Container/NotFoundDelegateFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616

1717
class NotFoundDelegateFactory
1818
{
19-
/**
20-
* @param ContainerInterface $container
21-
* @return NotFoundDelegate
22-
*/
23-
public function __invoke(ContainerInterface $container)
19+
public function __invoke(ContainerInterface $container) : NotFoundDelegate
2420
{
2521
$config = $container->has('config') ? $container->get('config') : [];
2622
$renderer = $container->has(TemplateRendererInterface::class)

src/Container/NotFoundHandlerFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515

1616
class NotFoundHandlerFactory
1717
{
18-
/**
19-
* @param ContainerInterface $container
20-
* @return NotFoundHandler
21-
*/
22-
public function __invoke(ContainerInterface $container)
18+
public function __invoke(ContainerInterface $container) : NotFoundHandler
2319
{
2420
return new NotFoundHandler($container->get(NotFoundDelegate::class));
2521
}

src/Container/WhoopsErrorResponseGeneratorFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414

1515
class WhoopsErrorResponseGeneratorFactory
1616
{
17-
/**
18-
* @param ContainerInterface $container
19-
* @return WhoopsErrorResponseGenerator
20-
*/
21-
public function __invoke(ContainerInterface $container)
17+
public function __invoke(ContainerInterface $container) : WhoopsErrorResponseGenerator
2218
{
2319
return new WhoopsErrorResponseGenerator(
2420
$container->get('Zend\Expressive\Whoops')

0 commit comments

Comments
 (0)