Skip to content

Commit

Permalink
Updates locked deps and solves psalm errors introduced by better type…
Browse files Browse the repository at this point in the history
…s upstream

Signed-off-by: George Steel <george@net-glue.co.uk>
  • Loading branch information
gsteel committed Jan 10, 2022
1 parent d7f7ee4 commit c70b388
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 56 deletions.
42 changes: 22 additions & 20 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 4 additions & 19 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.18.0.0">
<files psalm-version="4.18.1@dda05fa913f4dc6eb3386f2f7ce5a45d37a71bcb">
<file src="bin/templatemap_generator.php">
<MissingParamType occurrences="1">
<code>$templatePath</code>
Expand Down Expand Up @@ -2208,35 +2208,24 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Resolver/TemplatePathStack.php">
<DocblockTypeContradiction occurrences="2">
<code>gettype($options)</code>
<DocblockTypeContradiction occurrences="1">
<code>is_string($path)</code>
</DocblockTypeContradiction>
<FalsableReturnStatement occurrences="2">
<code>false</code>
<code>false</code>
</FalsableReturnStatement>
<MixedArgument occurrences="7">
<code>$key</code>
<code>$path</code>
<code>$path</code>
<MixedArgument occurrences="4">
<code>$value</code>
<code>$value</code>
<code>$value</code>
<code>$value</code>
</MixedArgument>
<MixedAssignment occurrences="6">
<code>$key</code>
<code>$path</code>
<code>$path</code>
<MixedAssignment occurrences="3">
<code>$this-&gt;lastLookupFailure</code>
<code>$this-&gt;lastLookupFailure</code>
<code>$value</code>
</MixedAssignment>
<MixedOperand occurrences="2">
<code>$path</code>
<code>$path</code>
</MixedOperand>
<NullArgument occurrences="1">
<code>$this-&gt;paths</code>
</NullArgument>
Expand All @@ -2245,10 +2234,6 @@
<code>(bool) $flag</code>
<code>(string) $defaultSuffix</code>
</RedundantCastGivenDocblockType>
<RedundantConditionGivenDocblockType occurrences="2">
<code>is_array($paths)</code>
<code>is_object($options)</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Strategy/FeedStrategy.php">
<MixedAssignment occurrences="1">
Expand Down
40 changes: 26 additions & 14 deletions src/Resolver/TemplatePathStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

/**
* Resolves view scripts based on a stack of paths
*
* @psalm-type PathStack = SplStack<string>
*/
class TemplatePathStack implements ResolverInterface
{
Expand All @@ -50,7 +52,7 @@ class TemplatePathStack implements ResolverInterface
*/
protected $defaultSuffix = 'phtml';

/** @var SplStack */
/** @var PathStack */
protected $paths;

/**
Expand Down Expand Up @@ -81,7 +83,7 @@ class TemplatePathStack implements ResolverInterface
/**
* Constructor
*
* @param null|array|Traversable $options
* @param null|array<string, mixed>|Traversable<string, mixed> $options
*/
public function __construct($options = null)
{
Expand All @@ -93,7 +95,9 @@ public function __construct($options = null)
}
}

$this->paths = new SplStack();
/** @psalm-var PathStack $paths */
$paths = new SplStack();
$this->paths = $paths;
if (null !== $options) {
$this->setOptions($options);
}
Expand All @@ -102,12 +106,13 @@ public function __construct($options = null)
/**
* Configure object
*
* @param array|Traversable $options
* @param array<string, mixed>|Traversable<string, mixed> $options
* @return void
* @throws Exception\InvalidArgumentException
*/
public function setOptions($options)
{
/** @psalm-suppress DocblockTypeContradiction */
if (! is_array($options) && ! $options instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
'Expected array or Traversable object; received "%s"',
Expand Down Expand Up @@ -162,7 +167,7 @@ public function getDefaultSuffix()
/**
* Add many paths to the stack at once
*
* @param array $paths
* @param list<string> $paths
* @return TemplatePathStack
*/
public function addPaths(array $paths)
Expand All @@ -176,24 +181,29 @@ public function addPaths(array $paths)
/**
* Rest the path stack to the paths provided
*
* @param SplStack|array $paths
* @param PathStack|list<string> $paths
* @return TemplatePathStack
* @throws Exception\InvalidArgumentException
*/
public function setPaths($paths)
{
if ($paths instanceof SplStack) {
$this->paths = $paths;
} elseif (is_array($paths)) {

return $this;
}

/** @psalm-suppress RedundantConditionGivenDocblockType */
if (is_array($paths)) {
$this->clearPaths();
$this->addPaths($paths);
} else {
throw new Exception\InvalidArgumentException(
"Invalid argument provided for \$paths, expecting either an array or SplStack object"
);

return $this;
}

return $this;
throw new Exception\InvalidArgumentException(
"Invalid argument provided for \$paths, expecting either an array or SplStack object"
);
}

/**
Expand Down Expand Up @@ -236,13 +246,15 @@ public function addPath($path)
*/
public function clearPaths()
{
$this->paths = new SplStack();
/** @psalm-var PathStack $paths */
$paths = new SplStack();
$this->paths = $paths;
}

/**
* Returns stack of paths
*
* @return SplStack
* @return PathStack
*/
public function getPaths()
{
Expand Down
6 changes: 3 additions & 3 deletions test/Resolver/TemplatePathStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function testSettingOptionsWithInvalidArgumentRaisesException($options):
}

/**
* @return array<array-key, array{0: mixed[]|ArrayObject}>
* @return array<array-key, array{0: array<string, mixed>|ArrayObject<string, mixed>}>
*/
public function validOptions(): array
{
Expand All @@ -220,7 +220,7 @@ public function validOptions(): array
}

/**
* @param array|ArrayObject $options
* @param array<string, mixed>|ArrayObject<string, mixed> $options
* @dataProvider validOptions
*/
public function testAllowsSettingOptions($options): void
Expand All @@ -239,7 +239,7 @@ public function testAllowsSettingOptions($options): void
}

/**
* @param array|ArrayObject $options
* @param array<string, mixed>|ArrayObject<string, mixed> $options
* @dataProvider validOptions
*/
public function testAllowsPassingOptionsToConstructor($options): void
Expand Down

0 comments on commit c70b388

Please sign in to comment.