Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Codegen/TargetUnifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ private static function returnTypeBranches(
?\ReflectionType $type,
\ReflectionClass $declaringClass,
): array {
if ($type === null) {
if (!$type instanceof \ReflectionType) {
return [['mixed']];
}

Expand Down
6 changes: 3 additions & 3 deletions src/Codegen/TypeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private function __construct() {}
*/
public static function parameterType(?\ReflectionType $type, ?\ReflectionClass $declaringClass = null): string
{
if ($type === null) {
if (!$type instanceof \ReflectionType) {
return '';
}

Expand Down Expand Up @@ -83,7 +83,7 @@ public static function acceptsMatcher(?\ReflectionType $type): bool
*/
public static function returnType(?\ReflectionType $type, ?\ReflectionClass $declaringClass = null): string
{
return $type === null ? 'mixed' : self::resolveParent(self::render($type), $declaringClass);
return $type instanceof \ReflectionType ? self::resolveParent(self::render($type), $declaringClass) : 'mixed';
}

/**
Expand Down Expand Up @@ -150,7 +150,7 @@ private static function resolveParent(string $rendered, ?\ReflectionClass $decla
*/
private static function resolveSelf(string $rendered, ?\ReflectionClass $declaringClass): string
{
if ($declaringClass === null) {
if (!$declaringClass instanceof \ReflectionClass) {
return $rendered;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Defaults/DefaultFactories.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function valueFor(string $requested, ?RuntimeContext $owner = null): ?arr
$owner ??= Runtime::current();
$factory = $this->factoryFor($requested);

if ($factory === null) {
if (!$factory instanceof \Closure) {
return null;
}

Expand All @@ -79,7 +79,7 @@ public function valueFor(string $requested, ?RuntimeContext $owner = null): ?arr

$valueOwner = is_object($value) ? Runtime::ownerOf($value) : null;

if ($valueOwner !== null && $valueOwner !== $owner) {
if ($valueOwner instanceof \Rasuvaeff\Understudy\Runtime\RuntimeContext && $valueOwner !== $owner) {
throw ContextOwnershipViolation::forDouble();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Defaults/TypeDefaultResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function forSignature(
bool $nested = false,
?object $double = null,
): mixed {
if ($signature === null) {
if (!$signature instanceof \Rasuvaeff\Understudy\Codegen\MethodSignature) {
return null;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Expectation/ArgumentFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function __construct() {}
*/
public static function scope(callable $render): mixed
{
if (self::$aliases !== null) {
if (self::$aliases instanceof \SplObjectStorage) {
return $render();
}

Expand All @@ -82,7 +82,7 @@ public static function format(mixed $value, int $depth = 0): string
return '…';
}

if (self::$aliases === null) {
if (!self::$aliases instanceof \SplObjectStorage) {
return self::scope(static fn(): string => self::format($value, $depth));
}

Expand Down Expand Up @@ -224,7 +224,7 @@ private static function formatObject(object $value, int $depth): string
private static function alias(object $value): int
{
$table = self::$aliases;
\assert($table !== null);
\assert($table instanceof \SplObjectStorage);

// `contains()` is deprecated as of 8.5; `offsetExists()` is the same
// lookup under the name the language kept.
Expand Down
10 changes: 5 additions & 5 deletions src/Expectation/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function hasCaptors(): bool
*/
public function setGuard(callable $guard, string $description): void
{
if ($this->guard !== null) {
if ($this->guard instanceof \Closure) {
throw InvalidCallSpecification::guardAlreadyNarrowed($this->method, $this->guardDescription);
}

Expand All @@ -189,7 +189,7 @@ public function setGuard(callable $guard, string $description): void
*/
private function acceptsGuard(array $args): bool
{
if ($this->guard === null) {
if (!$this->guard instanceof \Closure) {
return true;
}

Expand Down Expand Up @@ -349,7 +349,7 @@ public function matches(string $method, array $args): bool
*/
public function matchesArguments(array $args): bool
{
if ($this->tailMatcher !== null) {
if ($this->tailMatcher instanceof \Rasuvaeff\Understudy\Matcher\TailMatcher) {
$fixed = $this->argumentCount - 1;
/** @var int<0, max> $fixed */

Expand Down Expand Up @@ -517,7 +517,7 @@ public function describeAgainst(array $args): string
*/
private function describeGuardAgainst(array $args): string
{
if ($this->guard === null) {
if (!$this->guard instanceof \Closure) {
return '';
}

Expand All @@ -539,7 +539,7 @@ private function describeGuardAgainst(array $args): string
*/
private function acceptsGuardDefensively(array $args): bool
{
\assert($this->guard !== null);
\assert($this->guard instanceof \Closure);

try {
return ($this->guard)(...$args);
Expand Down
6 changes: 3 additions & 3 deletions src/Invocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function recordOutcome(Outcome $outcome): void
*/
public function recordReturned(mixed $value): void
{
if ($this->returnedState !== null || $this->outcome !== null) {
if ($this->returnedState !== null || $this->outcome instanceof \Rasuvaeff\Understudy\Outcome) {
return;
}

Expand All @@ -201,7 +201,7 @@ public function recordReturned(mixed $value): void
*/
public function recordDiscardedReturn(): void
{
if ($this->returnedState !== null || $this->outcome !== null) {
if ($this->returnedState !== null || $this->outcome instanceof \Rasuvaeff\Understudy\Outcome) {
return;
}

Expand All @@ -226,7 +226,7 @@ public function isReturnDiscarded(): bool
*/
public function recordThrown(\Throwable $thrown): void
{
if ($this->returnedState !== null || $this->outcome !== null) {
if ($this->returnedState !== null || $this->outcome instanceof \Rasuvaeff\Understudy\Outcome) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Outcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function didThrow(): bool
public function returned(string $method): mixed
{
if (!$this->returned) {
\assert($this->thrown !== null);
\assert($this->thrown instanceof \Throwable);

throw OutcomeUnavailable::threwInstead($method, $this->thrown);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Runtime/DoubleState.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public function declaredExpectations(): array
*/
public function settle(): void
{
$remaining = static fn(Expectation $expectation): bool => $expectation->cardinality() === null;
$remaining = static fn(Expectation $expectation): bool => !$expectation->cardinality() instanceof \Rasuvaeff\Understudy\Cardinality;

$this->expectations = array_values(array_filter($this->expectations, $remaining));
$this->matchingExpectations = array_values(array_filter($this->matchingExpectations, $remaining));
Expand Down
Loading
Loading