Skip to content

Commit

Permalink
Fix phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Jun 20, 2023
1 parent d741b37 commit b5b3166
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$value of function strval expects bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 2
path: src/Prophecy/Argument/Token/ExactValueToken.php

-
message: "#^Method Prophecy\\\\Call\\\\CallCenter\\:\\:indentArguments\\(\\) should return array\\<string\\> but returns array\\<string\\>\\|null\\.$#"
count: 1
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ parameters:
treatPhpDocTypesAsCertain: false
paths:
- ./src/
excludePaths:
- src/Prophecy/Comparator/Factory.php
includes:
- phpstan-baseline.neon
18 changes: 17 additions & 1 deletion src/Prophecy/Comparator/ClosureComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,38 @@
*/
final class ClosureComparator extends Comparator
{
/**
* @param mixed $expected
* @param mixed $actual
*/
public function accepts($expected, $actual): bool
{
return is_object($expected) && $expected instanceof \Closure
&& is_object($actual) && $actual instanceof \Closure;
}

/**
* @param mixed $expected
* @param mixed $actual
* @param float $delta
* @param bool $canonicalize
* @param bool $ignoreCase
*/
public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void
{
if ($expected !== $actual) {
// Support for sebastian/comparator < 5
if ((new \ReflectionMethod(ComparisonFailure::class, '__construct'))->getNumberOfParameters() >= 6) {
// @phpstan-ignore-next-line
throw new ComparisonFailure($expected, $actual, '', '', false, 'all closures are different if not identical');
}

throw new ComparisonFailure(
$expected,
$actual,
// we don't need a diff
'',
'',
false,
'all closures are different if not identical'
);
}
Expand Down
11 changes: 11 additions & 0 deletions src/Prophecy/Comparator/ProphecyComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,23 @@
*/
class ProphecyComparator extends ObjectComparator
{
/**
* @param mixed $expected
* @param mixed $actual
*/
public function accepts($expected, $actual): bool
{
return is_object($expected) && is_object($actual) && $actual instanceof ProphecyInterface;
}

/**
* @param mixed $expected
* @param mixed $actual
* @param float $delta
* @param bool $canonicalize
* @param bool $ignoreCase
* @param array $processed
*
* @phpstan-param list<array{object, object}> $processed
*/
public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false, array &$processed = array()): void
Expand Down
3 changes: 3 additions & 0 deletions src/Prophecy/Util/ExportUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu
return 'Array &' . $key;
}

\assert(\is_array($value));
$array = $value;
$key = $processed->add($value);
$values = '';
Expand All @@ -171,10 +172,12 @@ protected static function recursiveExport(&$value, $indentation, $processed = nu
$class = get_class($value);

if ($processed->contains($value)) {
\assert(\is_object($value));
return sprintf('%s#%d Object', $class, spl_object_id($value));
}

$processed->add($value);
\assert(\is_object($value));
$values = '';
$array = self::toArray($value);

Expand Down

0 comments on commit b5b3166

Please sign in to comment.