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

Commit aebac3d

Browse files
committed
Update to use PHP 7.1 features
- Adds strict_types declarations to all class files - Updates to use scalar and return type hints, including nullable and void types, wherever possible. In some cases, where extending classes from components that have not updated to PHP 7.1 syntax yet, typehints were omitted for compatibility. - Ensures `ZendViewRenderer` implements v2 signature of zend-expressive-template `TemplateRendererInterface`.
1 parent 0facac6 commit aebac3d

15 files changed

+79
-110
lines changed

.docheader

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/**
22
* @see https://github.com/zendframework/zend-expressive-zendviewrenderer for the canonical source repository
3-
* @copyright Copyright (c) %regexp:(20\d{2}-)?20\d{2}% Zend Technologies USA Inc. (http://www.zend.com)
3+
* @copyright Copyright (c) %regexp:(20\d{2}-)?20\d{2}% Zend Technologies USA Inc. (https://www.zend.com)
44
* @license https://github.com/zendframework/zend-expressive-zendviewrenderer/blob/master/LICENSE.md New BSD License
55
*/
6+
7+
declare(strict_types=1);

src/Exception/ExceptionInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22
/**
33
* @see https://github.com/zendframework/zend-expressive-zendviewrenderer for the canonical source repository
4-
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
4+
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (https://www.zend.com)
55
* @license https://github.com/zendframework/zend-expressive-zendviewrenderer/blob/master/LICENSE.md New BSD License
66
*/
77

8+
declare(strict_types=1);
9+
810
namespace Zend\Expressive\ZendView\Exception;
911

1012
interface ExceptionInterface

src/Exception/MissingHelperException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22
/**
33
* @see https://github.com/zendframework/zend-expressive-zendviewrenderer for the canonical source repository
4-
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
4+
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (https://www.zend.com)
55
* @license https://github.com/zendframework/zend-expressive-zendviewrenderer/blob/master/LICENSE.md New BSD License
66
*/
77

8+
declare(strict_types=1);
9+
810
namespace Zend\Expressive\ZendView\Exception;
911

1012
use DomainException;

src/HelperPluginManagerFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22
/**
33
* @see https://github.com/zendframework/zend-expressive-zendviewrenderer for the canonical source repository
4-
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
4+
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (https://www.zend.com)
55
* @license https://github.com/zendframework/zend-expressive-zendviewrenderer/blob/master/LICENSE.md New BSD License
66
*/
77

8+
declare(strict_types=1);
9+
810
namespace Zend\Expressive\ZendView;
911

1012
use Psr\Container\ContainerInterface;
@@ -13,7 +15,7 @@
1315

1416
class HelperPluginManagerFactory
1517
{
16-
public function __invoke(ContainerInterface $container)
18+
public function __invoke(ContainerInterface $container) : HelperPluginManager
1719
{
1820
$manager = new HelperPluginManager($container);
1921

src/NamespacedPathStackResolver.php

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22
/**
33
* @see https://github.com/zendframework/zend-expressive-zendviewrenderer for the canonical source repository
4-
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
4+
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (https://www.zend.com)
55
* @license https://github.com/zendframework/zend-expressive-zendviewrenderer/blob/master/LICENSE.md New BSD License
66
*/
77

8+
declare(strict_types=1);
9+
810
namespace Zend\Expressive\ZendView;
911

1012
use SplFileInfo;
@@ -39,10 +41,8 @@ class NamespacedPathStackResolver extends TemplatePathStack
3941
*
4042
* Overrides parent constructor to allow specifying paths as an associative
4143
* array.
42-
*
43-
* @param null|array|Traversable $options
4444
*/
45-
public function __construct($options = null)
45+
public function __construct(iterable $options = null)
4646
{
4747
$this->useViewStream = (bool) ini_get('short_open_tag');
4848
if ($this->useViewStream) {
@@ -60,12 +60,10 @@ public function __construct($options = null)
6060
* Add a path to the stack with the given namespace.
6161
*
6262
* @param string $path
63-
* @param string $namespace
64-
* @return void
6563
* @throws ViewException\InvalidArgumentException for an invalid path
6664
* @throws ViewException\InvalidArgumentException for an invalid namespace
6765
*/
68-
public function addPath($path, $namespace = self::DEFAULT_NAMESPACE)
66+
public function addPath($path, ?string $namespace = self::DEFAULT_NAMESPACE) : void
6967
{
7068
if (! is_string($path)) {
7169
throw new ViewException\InvalidArgumentException(sprintf(
@@ -93,11 +91,8 @@ public function addPath($path, $namespace = self::DEFAULT_NAMESPACE)
9391

9492
/**
9593
* Add many paths to the stack at once.
96-
*
97-
* @param array $paths
98-
* @return void
9994
*/
100-
public function addPaths(array $paths)
95+
public function addPaths(array $paths) : void
10196
{
10297
foreach ($paths as $namespace => $path) {
10398
if (! is_string($namespace)) {
@@ -111,11 +106,10 @@ public function addPaths(array $paths)
111106
/**
112107
* Overwrite all existing paths with the provided paths.
113108
*
114-
* @param array|Traversable $paths
115-
* @return void
109+
* @param SplStack|array $paths
116110
* @throws ViewException\InvalidArgumentException for invalid path types.
117111
*/
118-
public function setPaths($paths)
112+
public function setPaths($paths) : void
119113
{
120114
if ($paths instanceof Traversable) {
121115
$paths = iterator_to_array($paths);
@@ -134,10 +128,8 @@ public function setPaths($paths)
134128

135129
/**
136130
* Clear all paths.
137-
*
138-
* @return void
139131
*/
140-
public function clearPaths()
132+
public function clearPaths() : void
141133
{
142134
$this->paths = [];
143135
}
@@ -146,11 +138,9 @@ public function clearPaths()
146138
* Retrieve the filesystem path to a view script
147139
*
148140
* @param string $name
149-
* @param null|RendererInterface $renderer
150-
* @return false|string
151141
* @throws ViewException\DomainException
152142
*/
153-
public function resolve($name, RendererInterface $renderer = null)
143+
public function resolve($name, RendererInterface $renderer = null) : ?string
154144
{
155145
$namespace = self::DEFAULT_NAMESPACE;
156146
$template = $name;
@@ -169,7 +159,7 @@ public function resolve($name, RendererInterface $renderer = null)
169159

170160
if (! count($this->paths)) {
171161
$this->lastLookupFailure = static::FAILURE_NO_PATHS;
172-
return false;
162+
return null;
173163
}
174164

175165
// Ensure we have the expected file extension
@@ -190,20 +180,18 @@ public function resolve($name, RendererInterface $renderer = null)
190180
}
191181

192182
$this->lastLookupFailure = static::FAILURE_NOT_FOUND;
193-
return false;
183+
return null;
194184
}
195185

196186
/**
197187
* Fetch a template path from a given namespace.
198188
*
199-
* @param string $template
200-
* @param string $namespace
201-
* @return false|string String path on success; false on failure
189+
* @return null|string String path on success; null on failure
202190
*/
203-
private function getPathFromNamespace($template, $namespace)
191+
private function getPathFromNamespace(string $template, string $namespace) : ?string
204192
{
205193
if (! array_key_exists($namespace, $this->paths)) {
206-
return false;
194+
return null;
207195
}
208196

209197
foreach ($this->paths[$namespace] as $path) {
@@ -226,6 +214,6 @@ private function getPathFromNamespace($template, $namespace)
226214
}
227215
}
228216

229-
return false;
217+
return null;
230218
}
231219
}

src/ServerUrlHelper.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22
/**
33
* @see https://github.com/zendframework/zend-expressive-zendviewrenderer for the canonical source repository
4-
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
4+
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (https://www.zend.com)
55
* @license https://github.com/zendframework/zend-expressive-zendviewrenderer/blob/master/LICENSE.md New BSD License
66
*/
77

8+
declare(strict_types=1);
9+
810
namespace Zend\Expressive\ZendView;
911

1012
use Psr\Http\Message\UriInterface;
@@ -21,9 +23,6 @@ class ServerUrlHelper extends AbstractHelper
2123
*/
2224
private $helper;
2325

24-
/**
25-
* @param BaseHelper $helper
26-
*/
2726
public function __construct(BaseHelper $helper)
2827
{
2928
$this->helper = $helper;
@@ -33,21 +32,16 @@ public function __construct(BaseHelper $helper)
3332
* Return a path relative to the current request URI.
3433
*
3534
* Proxies to `Zend\Expressive\Helper\ServerUrlHelper::generate()`.
36-
*
37-
* @param null|string $path
38-
* @return string
3935
*/
40-
public function __invoke($path = null)
36+
public function __invoke(?string $path = null) : string
4137
{
4238
return $this->helper->generate($path);
4339
}
4440

4541
/**
4642
* Proxies to `Zend\Expressive\Helper\ServerUrlHelper::setUri()`
47-
* @param UriInterface $uri
48-
* @return void
4943
*/
50-
public function setUri(UriInterface $uri)
44+
public function setUri(UriInterface $uri) : void
5145
{
5246
$this->helper->setUri($uri);
5347
}

src/UrlHelper.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22
/**
33
* @see https://github.com/zendframework/zend-expressive-zendviewrenderer for the canonical source repository
4-
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
4+
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (https://www.zend.com)
55
* @license https://github.com/zendframework/zend-expressive-zendviewrenderer/blob/master/LICENSE.md New BSD License
66
*/
77

8+
declare(strict_types=1);
9+
810
namespace Zend\Expressive\ZendView;
911

1012
use Zend\Expressive\Helper\UrlHelper as BaseHelper;
@@ -28,21 +30,17 @@ public function __construct(BaseHelper $helper)
2830
/**
2931
* Proxies to `Zend\Expressive\Helper\UrlHelper::generate()`
3032
*
31-
* @param null|string $routeName
32-
* @param array $routeParams
33-
* @param array $queryParams
34-
* @param null|string $fragmentIdentifier
3533
* @param array $options Can have the following keys:
3634
* - router (array): contains options to be passed to the router
3735
* - reuse_result_params (bool): indicates if the current RouteResult
3836
* parameters will be used, defaults to true
3937
* @return string
4038
*/
4139
public function __invoke(
42-
$routeName = null,
40+
?string $routeName = null,
4341
array $routeParams = [],
4442
array $queryParams = [],
45-
$fragmentIdentifier = null,
43+
?string $fragmentIdentifier = null,
4644
array $options = []
4745
) {
4846
return $this->helper->generate($routeName, $routeParams, $queryParams, $fragmentIdentifier, $options);

0 commit comments

Comments
 (0)