diff --git a/composer.lock b/composer.lock index 41563431f..db91cc917 100644 --- a/composer.lock +++ b/composer.lock @@ -3047,16 +3047,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "10.1.8", + "version": "10.1.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "84838eed9ded511f61dc3e8b5944a52d9017b297" + "reference": "a56a9ab2f680246adcf3db43f38ddf1765774735" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/84838eed9ded511f61dc3e8b5944a52d9017b297", - "reference": "84838eed9ded511f61dc3e8b5944a52d9017b297", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/a56a9ab2f680246adcf3db43f38ddf1765774735", + "reference": "a56a9ab2f680246adcf3db43f38ddf1765774735", "shasum": "" }, "require": { @@ -3113,7 +3113,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.8" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.9" }, "funding": [ { @@ -3121,7 +3121,7 @@ "type": "github" } ], - "time": "2023-11-15T13:31:15+00:00" + "time": "2023-11-23T12:23:20+00:00" }, { "name": "phpunit/php-file-iterator", @@ -5497,16 +5497,16 @@ }, { "name": "vimeo/psalm", - "version": "5.15.0", + "version": "5.16.0", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "5c774aca4746caf3d239d9c8cadb9f882ca29352" + "reference": "2897ba636551a8cb61601cc26f6ccfbba6c36591" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/5c774aca4746caf3d239d9c8cadb9f882ca29352", - "reference": "5c774aca4746caf3d239d9c8cadb9f882ca29352", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/2897ba636551a8cb61601cc26f6ccfbba6c36591", + "reference": "2897ba636551a8cb61601cc26f6ccfbba6c36591", "shasum": "" }, "require": { @@ -5531,8 +5531,8 @@ "php": "^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0", "sebastian/diff": "^4.0 || ^5.0", "spatie/array-to-xml": "^2.17.0 || ^3.0", - "symfony/console": "^4.1.6 || ^5.0 || ^6.0", - "symfony/filesystem": "^5.4 || ^6.0" + "symfony/console": "^4.1.6 || ^5.0 || ^6.0 || ^7.0", + "symfony/filesystem": "^5.4 || ^6.0 || ^7.0" }, "conflict": { "nikic/php-parser": "4.17.0" @@ -5554,7 +5554,7 @@ "psalm/plugin-phpunit": "^0.18", "slevomat/coding-standard": "^8.4", "squizlabs/php_codesniffer": "^3.6", - "symfony/process": "^4.4 || ^5.0 || ^6.0" + "symfony/process": "^4.4 || ^5.0 || ^6.0 || ^7.0" }, "suggest": { "ext-curl": "In order to send data to shepherd", @@ -5567,7 +5567,7 @@ "psalm-refactor", "psalter" ], - "type": "library", + "type": "project", "extra": { "branch-alias": { "dev-master": "5.x-dev", @@ -5599,10 +5599,11 @@ "static analysis" ], "support": { + "docs": "https://psalm.dev/docs", "issues": "https://github.com/vimeo/psalm/issues", - "source": "https://github.com/vimeo/psalm/tree/5.15.0" + "source": "https://github.com/vimeo/psalm" }, - "time": "2023-08-20T23:07:30+00:00" + "time": "2023-11-22T20:38:47+00:00" }, { "name": "webimpress/coding-standard", diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 8e1e77db4..48231da82 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + $closingBracket @@ -41,9 +41,6 @@ Cycle Cycle - - __toString - Iterator @@ -103,21 +100,18 @@ null === static::$registeredDoctypes - - __toString - registry['doctypes'][$type]]]> - - array - string - getDoctype()]]]> + + registry['doctype']]]> registry['doctypes']]]> - + array + string + $registry @@ -172,9 +166,6 @@ $flag === null - - __toString - $attributes $email @@ -244,9 +235,6 @@ $type $value - - $index - $index view]]> @@ -353,9 +341,6 @@ parent::__call($method, $args) parent::__call($method, $args) - - $index - (bool) $flag @@ -390,9 +375,6 @@ $content $index - - $index - is_string($content) @@ -419,11 +401,7 @@ - - is_array($content) - - $content $options @@ -547,9 +525,6 @@ Navigation\Exception\ExceptionInterface - - __toString - $container $container @@ -583,14 +558,11 @@ bool - string $label - $message - $message last()]]> @@ -618,8 +590,6 @@ acl === null && static::$defaultAcl !== null]]> - is_int($maxDepth) - is_int($minDepth) container]]> static::$defaultAcl !== null @@ -1077,7 +1047,15 @@ containerClass($value)]]> + + + Container + + + + is_scalar($key) + $this @@ -1090,24 +1068,25 @@ nextIndex()]]> $this[$key] .= $data + + TKey + max($keys) + 1 int - - __toString - $items - getArrayCopy()]]> - $values $this[$key] max($keys) + + captureKey]]> + (string) $postfix (string) $prefix @@ -1115,9 +1094,23 @@ - - __toString - + + $container + containerClass()]]> + + + container]]> + + + ]]> + + + ]]> + |null]]> + + + getContainer()]]> + $return @@ -1307,12 +1300,18 @@ - $reuseMatchedParams + + $params + $reuseMatchedParams + $options + + $reuseMatchedParams + @@ -1322,9 +1321,6 @@ ! $events ! $events - - get - get('EventManager')]]> get('MvcTranslator')]]> @@ -1453,11 +1449,9 @@ $values - $setting $value - $setting getFilterChain()->filter($values['result'])]]> @@ -1468,6 +1462,9 @@ + + (array) $nameOrModel + @@ -1477,6 +1474,9 @@ $type + + $values + is_string($nameOrModel) @@ -1488,15 +1488,16 @@ $jsonpCallback - - $nameOrModel - $child $value + + $nameOrModel + $nameOrModel + $childValues $children @@ -1513,11 +1514,14 @@ ! is_object($nameOrModel) jsonpCallback]]> + + $nameOrModel instanceof Traversable + + gettype($helpers) - gettype($variables) __templateResolver->resolve($name, $this)]]> @@ -1529,51 +1533,27 @@ string|Resolver - $__vars __template]]> __template]]> __varsCache)]]> - - $vars[$name] - $vars[$name] - - - $vars[$name] - - - __vars[$key]]]> - __vars[$key]]]> - $includeReturn - $setting __template]]> - __vars]]> $value $value $variablesAsArray[$key] - $vars - $vars - $vars - $vars $vars[$name] - - vars()]]> - string - getArrayCopy new $helpers(new ServiceManager()) - - $setting - __filterChain->filter($this->__content)]]> + __vars[$key]]]> __templateResolver]]> @@ -1590,10 +1570,8 @@ __vars[$key]]]> - __vars[$key]]]> - __vars]]> __vars]]> resolve @@ -1602,7 +1580,6 @@ is_object($helpers) - is_object($variables) __file]]> @@ -1758,15 +1735,13 @@ - - Variables - - $key $value $key + $key + ArrayIterator::class $return @@ -1834,35 +1809,22 @@ - - $vars - $vars - - - setStrictVars - - - $vars - $vars - $vars - - - varName1]]> - varName1]]> - varName2]]> - varName2]]> - varName3]]> - varName3]]> - varName4]]> - varName4]]> - varName5]]> - addPath + + assertTrue + assertTrue + assertTrue + addPath + + varName2]]> + varName3]]> + varName5]]> + @@ -2533,9 +2495,6 @@ $value $value - - vars()]]> - getVariables()]]> getVariables()]]> @@ -2580,6 +2539,9 @@ addPath addPath + + vars()->message]]> + @@ -2715,6 +2677,13 @@ new stdClass() new stdClass() + + $options + $vars + + + $variables + @@ -2727,21 +2696,12 @@ $foo $return - - assign - assign - assign - assign - assign - getArrayCopy - getArrayCopy - - - renderer->vars()->foo]]> - + + renderer->vars()->foo]]> + $errno $errstr @@ -2859,43 +2819,12 @@ - - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - content]]> result->content]]> - - $result[] - - - getModel - getModel - getResult - getResult - getResult - getResult - getResult - null - - $e - $e - $e - $e - diff --git a/src/Helper/HeadLink.php b/src/Helper/HeadLink.php index 8f34f209a..bdbea923c 100644 --- a/src/Helper/HeadLink.php +++ b/src/Helper/HeadLink.php @@ -241,12 +241,12 @@ public function append($value) /** * offsetSet() * - * @param int $index + * @param int $offset * @param object $value - * @throws Exception\InvalidArgumentException * @return void + * @throws Exception\InvalidArgumentException */ - public function offsetSet($index, $value) + public function offsetSet($offset, $value) { if (! $this->isValid($value)) { throw new Exception\InvalidArgumentException( @@ -254,7 +254,7 @@ public function offsetSet($index, $value) ); } - $this->getContainer()->offsetSet($index, $value); + $this->getContainer()->offsetSet($offset, $value); } /** diff --git a/src/Helper/HeadMeta.php b/src/Helper/HeadMeta.php index d6ca47188..1ad95ddc0 100644 --- a/src/Helper/HeadMeta.php +++ b/src/Helper/HeadMeta.php @@ -446,17 +446,17 @@ public function offsetSet($index, $value) /** * OffsetUnset * - * @param int $index + * @param int $offset * @return void * @throws Exception\InvalidArgumentException */ - public function offsetUnset($index) + public function offsetUnset($offset) { - if (! in_array($index, $this->getContainer()->getKeys())) { + if (! in_array($offset, $this->getContainer()->getKeys())) { throw new Exception\InvalidArgumentException('Invalid index passed to offsetUnset()'); } - $this->getContainer()->offsetUnset($index); + $this->getContainer()->offsetUnset($offset); } /** diff --git a/src/Helper/HeadScript.php b/src/Helper/HeadScript.php index 78f5c5e19..bae22fe27 100644 --- a/src/Helper/HeadScript.php +++ b/src/Helper/HeadScript.php @@ -556,12 +556,12 @@ public function set($value) /** * Override offsetSet * - * @param int $index Set script of file offset + * @param int $offset Set script of file offset * @param ObjectShape $value - * @throws Exception\InvalidArgumentException * @return void + * @throws Exception\InvalidArgumentException */ - public function offsetSet($index, $value) + public function offsetSet($offset, $value) { if (! $this->isValid($value)) { throw new Exception\InvalidArgumentException( @@ -570,7 +570,7 @@ public function offsetSet($index, $value) ); } - $this->getContainer()->offsetSet($index, $value); + $this->getContainer()->offsetSet($offset, $value); } /** diff --git a/src/Helper/HeadStyle.php b/src/Helper/HeadStyle.php index f8ebe24e5..8b908f797 100644 --- a/src/Helper/HeadStyle.php +++ b/src/Helper/HeadStyle.php @@ -420,12 +420,12 @@ public function append($value) /** * Override offsetSet to enforce style creation * - * @param int $index + * @param int $offset * @param ObjectShape $value - * @throws Exception\InvalidArgumentException * @return void + * @throws Exception\InvalidArgumentException */ - public function offsetSet($index, $value) + public function offsetSet($offset, $value) { if (! $this->isValid($value)) { throw new Exception\InvalidArgumentException( @@ -433,7 +433,7 @@ public function offsetSet($index, $value) ); } - $this->getContainer()->offsetSet($index, $value); + $this->getContainer()->offsetSet($offset, $value); } /** diff --git a/src/Helper/HtmlObject.php b/src/Helper/HtmlObject.php index 8e0d854ec..805b3434e 100644 --- a/src/Helper/HtmlObject.php +++ b/src/Helper/HtmlObject.php @@ -22,7 +22,7 @@ class HtmlObject extends AbstractHtmlElement * @param string $type Data file type * @param array $attribs Attribs for the object tag * @param array $params Params for in the object tag - * @param string $content Alternative content for object + * @param string|list|null $content Alternative content for object * @throws InvalidArgumentException * @return string */ diff --git a/src/Helper/Navigation/AbstractHelper.php b/src/Helper/Navigation/AbstractHelper.php index 68cf5ac0b..68451c8c3 100644 --- a/src/Helper/Navigation/AbstractHelper.php +++ b/src/Helper/Navigation/AbstractHelper.php @@ -618,7 +618,7 @@ public function getIndent() /** * Sets the maximum depth a page can have to be included when rendering * - * @param int $maxDepth Default is null, which sets no maximum depth. + * @param int|null|numeric-string $maxDepth Default is null, which sets no maximum depth. * @return AbstractHelper */ public function setMaxDepth($maxDepth = null) @@ -645,7 +645,7 @@ public function getMaxDepth() /** * Sets the minimum depth a page must have to be included when rendering * - * @param int $minDepth Default is null, which sets no minimum depth. + * @param int|null|numeric-string $minDepth Default is null, which sets no minimum depth. * @return AbstractHelper */ public function setMinDepth($minDepth = null) diff --git a/src/Helper/Placeholder/Container/AbstractContainer.php b/src/Helper/Placeholder/Container/AbstractContainer.php index 1341c84f4..faff0a239 100644 --- a/src/Helper/Placeholder/Container/AbstractContainer.php +++ b/src/Helper/Placeholder/Container/AbstractContainer.php @@ -24,7 +24,7 @@ /** * Abstract class representing container for placeholder values * - * @template TKey + * @template TKey of array-key * @template TValue * @extends ArrayObject */ diff --git a/src/Helper/Url.php b/src/Helper/Url.php index dc4766235..ed8014233 100644 --- a/src/Helper/Url.php +++ b/src/Helper/Url.php @@ -12,10 +12,9 @@ use function array_merge; use function func_num_args; -use function gettype; +use function get_debug_type; use function is_array; use function is_bool; -use function is_object; use function iterator_to_array; use function sprintf; @@ -121,7 +120,7 @@ public function setRouter($router) '%s expects a %s instance; received %s', __METHOD__, RouteStackInterface::class, - is_object($router) ? $router::class : gettype($router) + get_debug_type($router), )); } @@ -143,7 +142,7 @@ public function setRouteMatch($routeMatch) '%s expects a %s instance; received %s', __METHOD__, RouteMatch::class, - is_object($routeMatch) ? $routeMatch::class : gettype($routeMatch) + get_debug_type($routeMatch), )); } diff --git a/src/Model/ModelInterface.php b/src/Model/ModelInterface.php index c1bcbafbf..9b7c68787 100644 --- a/src/Model/ModelInterface.php +++ b/src/Model/ModelInterface.php @@ -33,7 +33,7 @@ public function setOption($name, $value); /** * Set renderer options/hints en masse * - * @param array|Traversable $options + * @param array|Traversable $options * @return ModelInterface */ public function setOptions($options); @@ -41,7 +41,7 @@ public function setOptions($options); /** * Get renderer options/hints * - * @return array|Traversable + * @return array|Traversable */ public function getOptions(); @@ -66,7 +66,7 @@ public function setVariable($name, $value); /** * Set view variables en masse * - * @param array|ArrayAccess $variables + * @param array|ArrayAccess $variables * @return ModelInterface */ public function setVariables($variables); @@ -74,7 +74,7 @@ public function setVariables($variables); /** * Get view variables * - * @return array|ArrayAccess + * @return array|ArrayAccess */ public function getVariables(); diff --git a/src/Model/ViewModel.php b/src/Model/ViewModel.php index 2067b2cc7..cb4e349e7 100644 --- a/src/Model/ViewModel.php +++ b/src/Model/ViewModel.php @@ -15,6 +15,7 @@ use function array_key_exists; use function array_merge; use function count; +use function get_debug_type; use function gettype; use function is_array; use function is_object; @@ -39,7 +40,7 @@ class ViewModel implements ModelInterface, ClearableModelInterface, RetrievableC /** * Renderer options * - * @var array + * @var array */ protected $options = []; @@ -75,8 +76,8 @@ class ViewModel implements ModelInterface, ClearableModelInterface, RetrievableC /** * Constructor * - * @param null|array|Traversable|ArrayAccess $variables - * @param array|Traversable $options + * @param null|array|Traversable|ArrayAccess $variables + * @param null|array|Traversable $options */ public function __construct($variables = null, $options = null) { @@ -191,7 +192,7 @@ public function getOption($name, $default = null) /** * Set renderer options/hints en masse * - * @param array|Traversable $options + * @param array|Traversable $options * @throws Exception\InvalidArgumentException * @return ViewModel */ @@ -207,7 +208,7 @@ public function setOptions($options) throw new Exception\InvalidArgumentException(sprintf( '%s: expects an array, or Traversable argument; received "%s"', __METHOD__, - is_object($options) ? $options::class : gettype($options) + get_debug_type($options), )); } @@ -218,7 +219,7 @@ public function setOptions($options) /** * Get renderer options/hints * - * @return array + * @return array */ public function getOptions() { @@ -228,7 +229,7 @@ public function getOptions() /** * Clear any existing renderer options/hints * - * @return ViewModel + * @return $this */ public function clearOptions() { diff --git a/src/Renderer/FeedRenderer.php b/src/Renderer/FeedRenderer.php index ea2863683..e722c5bb7 100644 --- a/src/Renderer/FeedRenderer.php +++ b/src/Renderer/FeedRenderer.php @@ -10,9 +10,8 @@ use Laminas\View\Model\ModelInterface as Model; use Laminas\View\Resolver\ResolverInterface as Resolver; -use function gettype; +use function get_debug_type; use function in_array; -use function is_object; use function is_string; use function sprintf; use function strtolower; @@ -59,7 +58,7 @@ public function setResolver(Resolver $resolver) * * @todo Determine what use case exists for accepting only $nameOrModel * @param string|Model $nameOrModel The script/resource process, or a view model - * @param null|array|ArrayAccess $values Values to use during rendering + * @param null|array|ArrayAccess $values Values to use during rendering * @throws Exception\InvalidArgumentException * @return string The script output. */ @@ -87,7 +86,7 @@ public function render($nameOrModel, $values = null) throw new Exception\InvalidArgumentException(sprintf( '%s expects a ViewModel or a string feed type as the first argument; received "%s"', __METHOD__, - is_object($nameOrModel) ? $nameOrModel::class : gettype($nameOrModel) + get_debug_type($nameOrModel), )); } diff --git a/src/Renderer/PhpRenderer.php b/src/Renderer/PhpRenderer.php index b328b9a75..5929ad736 100644 --- a/src/Renderer/PhpRenderer.php +++ b/src/Renderer/PhpRenderer.php @@ -21,9 +21,11 @@ use function array_key_exists; use function array_pop; +use function assert; use function call_user_func_array; use function class_exists; use function extract; +use function get_debug_type; use function gettype; use function is_array; use function is_callable; @@ -140,7 +142,7 @@ class PhpRenderer implements Renderer, TreeRendererInterface private $__filterChain; /** - * @var ArrayAccess|array|null ArrayAccess or associative array representing available variables + * @var Variables|null */ private $__vars; @@ -221,7 +223,7 @@ public function resolver($name = null) * * Expects either an array, or an object implementing ArrayAccess. * - * @param array|ArrayAccess $variables + * @param array|ArrayAccess $variables * @return PhpRenderer * @throws Exception\InvalidArgumentException */ @@ -230,7 +232,7 @@ public function setVars($variables) if (! is_array($variables) && ! $variables instanceof ArrayAccess) { throw new Exception\InvalidArgumentException(sprintf( 'Expected array or ArrayAccess object; received "%s"', - is_object($variables) ? $variables::class : gettype($variables) + get_debug_type($variables), )); } @@ -250,8 +252,8 @@ public function setVars($variables) /** * Get a single variable, or all variables * - * @param mixed $key - * @return mixed + * @param string|null $key + * @return ($key is null ? Variables : mixed) */ public function vars($key = null) { @@ -259,6 +261,8 @@ public function vars($key = null) $this->setVars(new Variables()); } + assert($this->__vars !== null); + if (null === $key) { return $this->__vars; } @@ -268,7 +272,7 @@ public function vars($key = null) /** * Get a single variable * - * @param mixed $key + * @param string $key * @return mixed */ public function get($key) diff --git a/src/Resolver/TemplatePathStack.php b/src/Resolver/TemplatePathStack.php index 6ddeb1f06..c251ebef7 100644 --- a/src/Resolver/TemplatePathStack.php +++ b/src/Resolver/TemplatePathStack.php @@ -15,11 +15,11 @@ use function array_change_key_case; use function count; use function file_exists; +use function get_debug_type; use function gettype; use function in_array; use function ini_get; use function is_array; -use function is_object; use function is_string; use function ltrim; use function pathinfo; @@ -131,7 +131,7 @@ public function setOptions($options) if (! is_array($options) && ! $options instanceof Traversable) { throw new Exception\InvalidArgumentException(sprintf( 'Expected array or Traversable object; received "%s"', - is_object($options) ? $options::class : gettype($options) + get_debug_type($options), )); } diff --git a/src/Variables.php b/src/Variables.php index a87725e64..57873019d 100644 --- a/src/Variables.php +++ b/src/Variables.php @@ -26,6 +26,7 @@ * @todo Allow specifying string names for manager, filter chain, variables * @todo Move escaping into variables object * @todo Move strict variables into variables object + * @extends ArrayObject */ class Variables extends ArrayObject { @@ -40,8 +41,8 @@ class Variables extends ArrayObject /** * Constructor * - * @param array $variables - * @param array $options + * @param array $variables + * @param array $options */ public function __construct(array $variables = [], array $options = []) { @@ -57,7 +58,7 @@ public function __construct(array $variables = [], array $options = []) /** * Configure object * - * @param array $options + * @param array $options * @return Variables */ public function setOptions(array $options) @@ -101,7 +102,7 @@ public function isStrict() /** * Assign many values at once * - * @param array|object $spec + * @param array|object $spec * @return Variables * @throws Exception\InvalidArgumentException */ @@ -135,23 +136,23 @@ public function assign($spec) * * Otherwise, returns _escaped_ version of the value. * - * @param mixed $key + * @param string $offset * @return mixed */ #[ReturnTypeWillChange] - public function offsetGet($key) + public function offsetGet($offset) { - if (! $this->offsetExists($key)) { + if (! $this->offsetExists($offset)) { if ($this->isStrict()) { trigger_error(sprintf( 'View variable "%s" does not exist', - $key + $offset ), E_USER_NOTICE); } return; } - $return = parent::offsetGet($key); + $return = parent::offsetGet($offset); // If we have a closure/functor, invoke it, and return its return value if (is_object($return) && is_callable($return)) { diff --git a/test/Helper/Navigation/SitemapTest.php b/test/Helper/Navigation/SitemapTest.php index 9e84b6aca..720c0d3ad 100644 --- a/test/Helper/Navigation/SitemapTest.php +++ b/test/Helper/Navigation/SitemapTest.php @@ -33,6 +33,8 @@ class SitemapTest extends AbstractTestCase protected $_helper; // phpcs:ignore /** * Stores the original set timezone + * + * @var non-empty-string */ private string $originaltimezone; diff --git a/test/Helper/Placeholder/RegistryTest.php b/test/Helper/Placeholder/RegistryTest.php index 2c39357f8..225372d15 100644 --- a/test/Helper/Placeholder/RegistryTest.php +++ b/test/Helper/Placeholder/RegistryTest.php @@ -53,7 +53,10 @@ public function testGetContainerCreatesContainerIfNonExistent(): void public function testSetContainerCreatesRegistryEntry(): void { - /** @psalm-suppress TooManyArguments */ + /** + * @psalm-suppress TooManyArguments + * @psalm-var Container $foo + */ $foo = new Container(['foo', 'bar']); $this->assertFalse($this->registry->containerExists('foo')); $this->registry->setContainer('foo', $foo); @@ -62,7 +65,10 @@ public function testSetContainerCreatesRegistryEntry(): void public function testSetContainerCreatesRegistersContainerInstance(): void { - /** @psalm-suppress TooManyArguments */ + /** + * @psalm-suppress TooManyArguments + * @psalm-var Container $foo + */ $foo = new Container(['foo', 'bar']); $this->assertFalse($this->registry->containerExists('foo')); $this->registry->setContainer('foo', $foo); diff --git a/test/Helper/Placeholder/StandaloneContainerTest.php b/test/Helper/Placeholder/StandaloneContainerTest.php index 0494c0339..32461c0b5 100644 --- a/test/Helper/Placeholder/StandaloneContainerTest.php +++ b/test/Helper/Placeholder/StandaloneContainerTest.php @@ -28,6 +28,7 @@ protected function setUp(): void public function testSetContainer(): void { + /** @var Container $container */ $container = new Container(); $this->assertNotSame($container, $this->helper->getContainer()); $this->helper->setContainer($container); diff --git a/test/PhpRendererTest.php b/test/PhpRendererTest.php index 7be4b4875..d53d71662 100644 --- a/test/PhpRendererTest.php +++ b/test/PhpRendererTest.php @@ -84,7 +84,7 @@ public function testUsesVariablesObjectForVarsByDefault(): void public function testCanSpecifyArrayAccessForVars(): void { - $a = new ArrayObject(); + $a = new ArrayObject(['baz' => 'bat']); $this->renderer->setVars($a); $this->assertSame($a->getArrayCopy(), $this->renderer->vars()->getArrayCopy()); } diff --git a/test/Resolver/TemplatePathStackTest.php b/test/Resolver/TemplatePathStackTest.php index f62100fdc..14b152009 100644 --- a/test/Resolver/TemplatePathStackTest.php +++ b/test/Resolver/TemplatePathStackTest.php @@ -216,7 +216,7 @@ public static function validOptions(): array } /** - * @param Options|ArrayObject $options + * @param Options $options */ #[DataProvider('validOptions')] public function testAllowsSettingOptions($options): void @@ -235,7 +235,7 @@ public function testAllowsSettingOptions($options): void } /** - * @param Options|ArrayObject $options + * @param Options $options */ #[DataProvider('validOptions')] public function testAllowsPassingOptionsToConstructor($options): void diff --git a/test/ViewTest.php b/test/ViewTest.php index c3d569909..7ac7e96cd 100644 --- a/test/ViewTest.php +++ b/test/ViewTest.php @@ -4,7 +4,6 @@ namespace LaminasTest\View; -use ArrayObject; use Laminas\Http\Request; use Laminas\Http\Response; use Laminas\View\Exception; @@ -46,9 +45,9 @@ protected function setUp(): void public function attachTestStrategies(): void { - $this->view->addRenderingStrategy(static fn($e) => new TestAsset\Renderer\VarExportRenderer()); + $this->view->addRenderingStrategy(static fn() => new TestAsset\Renderer\VarExportRenderer()); $this->result = $result = new stdClass(); - $this->view->addResponseStrategy(function ($e) use ($result) { + $this->view->addResponseStrategy(function (ViewEvent $e) use ($result) { $result->content = $e->getResult(); }); } @@ -119,14 +118,14 @@ public function testRendersTreeOfModels(): void public function testChildrenMayInvokeDifferentRenderingStrategiesThanParents(): void { - $this->view->addRenderingStrategy(function ($e) { + $this->view->addRenderingStrategy(function (ViewEvent $e) { $model = $e->getModel(); if (! $model instanceof ViewModel) { return; } return new TestAsset\Renderer\VarExportRenderer(); }); - $this->view->addRenderingStrategy(function ($e) { + $this->view->addRenderingStrategy(function (ViewEvent $e) { $model = $e->getModel(); if (! $model instanceof JsonModel) { return; @@ -134,7 +133,7 @@ public function testChildrenMayInvokeDifferentRenderingStrategiesThanParents(): return new Renderer\JsonRenderer(); }, 10); // higher priority, so it matches earlier $this->result = $result = new stdClass(); - $this->view->addResponseStrategy(function ($e) use ($result) { + $this->view->addResponseStrategy(function (ViewEvent $e) use ($result) { $result->content = $e->getResult(); }); @@ -212,10 +211,12 @@ public function testResponseStrategyIsTriggeredForParentModel(): void public function testResponseStrategyIsNotTriggeredForChildModel(): void { - $this->view->addRenderingStrategy(static fn($e) => new Renderer\JsonRenderer()); + $this->view->addRenderingStrategy(static fn() => new Renderer\JsonRenderer()); - $result = new ArrayObject(); - $this->view->addResponseStrategy(function ($e) use ($result) { + $result = []; + $this->view->addResponseStrategy(function (ViewEvent $e) use (&$result) { + self::assertIsArray($result); + /** @psalm-var mixed */ $result[] = $e->getResult(); }); @@ -231,7 +232,8 @@ public function testResponseStrategyIsNotTriggeredForChildModel(): void $this->view->render($this->model); - $this->assertEquals(1, count($result)); + self::assertIsArray($result); + self::assertEquals(1, count($result)); } public function testUsesTreeRendererInterfaceToDetermineWhetherOrNotToPassOnlyRootViewModelToPhpRenderer(): void @@ -244,10 +246,10 @@ public function testUsesTreeRendererInterfaceToDetermineWhetherOrNotToPassOnlyRo $phpRenderer->setCanRenderTrees(true); $phpRenderer->setResolver($resolver); - $this->view->addRenderingStrategy(static fn($e) => $phpRenderer); + $this->view->addRenderingStrategy(static fn() => $phpRenderer); $result = new stdClass(); - $this->view->addResponseStrategy(function ($e) use ($result) { + $this->view->addResponseStrategy(function (ViewEvent $e) use ($result) { $result->content = $e->getResult(); }); @@ -269,10 +271,10 @@ public function testUsesTreeRendererInterfaceToDetermineWhetherOrNotToPassOnlyRo { $jsonRenderer = new Renderer\JsonRenderer(); - $this->view->addRenderingStrategy(static fn($e) => $jsonRenderer); + $this->view->addRenderingStrategy(static fn() => $jsonRenderer); $result = new stdClass(); - $this->view->addResponseStrategy(function ($e) use ($result) { + $this->view->addResponseStrategy(function (ViewEvent $e) use ($result) { $result->content = $e->getResult(); });