Skip to content

Commit

Permalink
Fixed phpstan error
Browse files Browse the repository at this point in the history
  • Loading branch information
sebprt committed Nov 21, 2023
1 parent 12691a4 commit 90ca485
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Constraint/Builder/BuilderProducesCodeThat.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class BuilderProducesCodeThat extends UnaryOperator
{
public function __construct(
private readonly string $builderCompilePath,
$constraint,
mixed $constraint,
) {
parent::__construct($constraint);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Constraint/Pipeline/IteratesLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function asIterator(iterable $iterable): \Iterator
return new \IteratorIterator($iterable);
}

public function matches($other): bool
public function matches(mixed $other): bool

Check warning on line 40 in src/Constraint/Pipeline/IteratesLike.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "PublicVisibility": --- Original +++ New @@ @@ } return new \IteratorIterator($iterable); } - public function matches(mixed $other) : bool + protected function matches(mixed $other) : bool { $both = new \MultipleIterator(\MultipleIterator::MIT_NEED_ANY); $both->attachIterator($this->asIterator($this->expected));
{
$both = new \MultipleIterator(\MultipleIterator::MIT_NEED_ANY);

Expand All @@ -54,7 +54,7 @@ public function matches($other): bool
return !$iterator->valid();
}

protected function failureDescription($other): string
protected function failureDescription(mixed $other): string
{
return sprintf(
'%s iterates like %s',
Expand Down
4 changes: 2 additions & 2 deletions src/Constraint/Pipeline/PipelineExtractsLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private function passThroughCoroutine(): \Generator
}
}

public function matches($other): bool
public function matches(mixed $other): bool
{
$both = new \MultipleIterator(\MultipleIterator::MIT_NEED_ANY);

Expand Down Expand Up @@ -82,7 +82,7 @@ public function matches($other): bool
return !$iterator->valid();
}

protected function failureDescription($other): string
protected function failureDescription(mixed $other): string
{
return sprintf(
'%s pipeline extracts like %s',
Expand Down
4 changes: 2 additions & 2 deletions src/Constraint/Pipeline/PipelineLoadsLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function asIterator(iterable $iterable): \Iterator
return new \IteratorIterator($iterable);
}

public function matches($other): bool
public function matches(mixed $other): bool
{
$both = new \MultipleIterator(\MultipleIterator::MIT_NEED_ANY);

Expand Down Expand Up @@ -102,7 +102,7 @@ public function matches($other): bool
return !$iterator->valid();
}

protected function failureDescription($other): string
protected function failureDescription(mixed $other): string
{
return sprintf(
'%s pipeline loads like %s',
Expand Down
4 changes: 2 additions & 2 deletions src/Constraint/Pipeline/PipelineTransformsLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function asIterator(iterable $iterable): \Iterator
return new \IteratorIterator($iterable);
}

public function matches($other): bool
public function matches(mixed $other): bool
{
$both = new \MultipleIterator(\MultipleIterator::MIT_NEED_ANY);

Expand Down Expand Up @@ -102,7 +102,7 @@ public function matches($other): bool
return !$iterator->valid();
}

protected function failureDescription($other): string
protected function failureDescription(mixed $other): string
{
return sprintf(
'%s pipeline transforms like %s',
Expand Down
6 changes: 2 additions & 4 deletions src/Constraint/Pipeline/PipelineWritesFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private function asIterator(iterable $iterable): \Iterator
return new \IteratorIterator($iterable);
}

public function matches($other): bool
public function matches(mixed $other): bool
{
if (!$other instanceof LoaderInterface) {
$this->fail($other, strtr('Expected an instance of %expected%, but got %actual%.', [
Expand Down Expand Up @@ -81,15 +81,13 @@ public function matches($other): bool
);
}

iterator_count($iterator);

$constraint = new FileExists();
$constraint->evaluate($this->expected);

return !$iterator->valid();
}

protected function failureDescription($other): string
protected function failureDescription(mixed $other): string
{
return sprintf(
'%s pipeline writes file %s',
Expand Down
1 change: 1 addition & 0 deletions src/Mock/ApiClientMockBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class ApiClientMockBuilder implements Builder
{
private Node\Expr $node;

/** @param array<Node\Arg|Node\VariadicPlaceholder> $mockedArgs */
public function __construct(
private readonly string $mockedClientBuilder,
private readonly ?array $mockedArgs = []
Expand Down
14 changes: 6 additions & 8 deletions src/Mock/ExceptionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ public function __construct(
$this->arguments = $arguments;
}

public function getNode(): Node
public function getNode(): Node\Expr
{
return new Node\Expr\New_(
class: new Node\Name\FullyQualified($this->class),
args: [
array_map(
fn (Node\Expr $value, int|string $key) => !\is_string($key) ? new Node\Arg(value: $value) : new Node\Arg(value: $value, name: new Node\Identifier($key)),
$this->arguments,
array_keys($this->arguments),
),
]
args: array_map(
fn (Node\Expr $value, int|string $key) => !\is_string($key) ? new Node\Arg(value: $value) : new Node\Arg(value: $value, name: new Node\Identifier($key)),
$this->arguments,
array_keys($this->arguments),
),
);
}
}
16 changes: 10 additions & 6 deletions src/Mock/RequestMatcher/RequestMatcherBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
use Http\Message\RequestMatcher;
use PhpParser\Node;

final class RequestMatcherBuilder implements RequestMatcherBuilderInterface
final readonly class RequestMatcherBuilder implements RequestMatcherBuilderInterface
{
/**
* @param list<string> $methods
* @param list<string> $schemes
*/
public function __construct(
private readonly ?string $path = null,
private readonly ?string $host = null,
private $methods = [],
private $schemes = []
private ?string $path = null,
private ?string $host = null,
private array $methods = [],
private array $schemes = []
) {}

public function getNode(): Node
public function getNode(): Node\Expr
{
return new Node\Expr\New_(
class: new Node\Name\FullyQualified(RequestMatcher::class),
Expand Down
5 changes: 4 additions & 1 deletion src/Mock/RequestMatcher/RequestMatcherBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
namespace Kiboko\Component\PHPUnitExtension\Mock\RequestMatcher;

use PhpParser\Builder;
use PhpParser\Node;

interface RequestMatcherBuilderInterface extends Builder {}
interface RequestMatcherBuilderInterface extends Builder {
public function getNode(): Node\Expr;
}
2 changes: 1 addition & 1 deletion src/Mock/ResponseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(
private string $path,
) {}

public function getNode(): Node
public function getNode(): Node\Expr
{
return new Node\Expr\Include_(new Node\Scalar\String_($this->path), Node\Expr\Include_::TYPE_INCLUDE);
}
Expand Down

0 comments on commit 90ca485

Please sign in to comment.