Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix psalm errors #38

Merged
merged 2 commits into from
Feb 21, 2025
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
},
"require-dev": {
"innmind/static-analysis": "~1.1",
"innmind/static-analysis": "^1.2.1",
"innmind/black-box": "^5.5.1",
"innmind/coding-standard": "~2.0"
},
Expand Down
5 changes: 5 additions & 0 deletions src/Accumulate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct(\Generator $generator)
/**
* @return S
*/
#[\Override]
public function current(): mixed
{
/** @psalm-suppress InaccessibleProperty */
Expand All @@ -45,6 +46,7 @@ public function current(): mixed
/**
* @return int<0, max>|null
*/
#[\Override]
public function key(): ?int
{
/** @psalm-suppress InaccessibleProperty */
Expand All @@ -55,6 +57,7 @@ public function key(): ?int
return \key($this->values);
}

#[\Override]
public function next(): void
{
/** @psalm-suppress InaccessibleProperty */
Expand All @@ -68,6 +71,7 @@ public function next(): void
}
}

#[\Override]
public function rewind(): void
{
/** @psalm-suppress InaccessibleProperty */
Expand All @@ -76,6 +80,7 @@ public function rewind(): void
\reset($this->values);
}

#[\Override]
public function valid(): bool
{
/** @psalm-suppress InaccessibleProperty */
Expand Down
7 changes: 7 additions & 0 deletions src/Attempt/Defer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,45 @@ public function __construct(callable $deferred)
$this->deferred = $deferred;
}

#[\Override]
public function map(callable $map): self
{
$captured = $this->capture();

return new self(static fn() => self::detonate($captured)->map($map));
}

#[\Override]
public function flatMap(callable $map): Attempt
{
$captured = $this->capture();

return Attempt::defer(static fn() => self::detonate($captured)->flatMap($map));
}

#[\Override]
public function match(callable $result, callable $error)
{
return $this->unwrap()->match($result, $error);
}

#[\Override]
public function recover(callable $recover): Attempt
{
$captured = $this->capture();

return Attempt::defer(static fn() => self::detonate($captured)->recover($recover));
}

#[\Override]
public function maybe(): Maybe
{
$captured = $this->capture();

return Maybe::defer(static fn() => self::detonate($captured)->maybe());
}

#[\Override]
public function either(): Either
{
$captured = $this->capture();
Expand All @@ -73,6 +79,7 @@ public function either(): Either
/**
* @return Attempt<R1>
*/
#[\Override]
public function memoize(): Attempt
{
return $this->unwrap();
Expand Down
7 changes: 7 additions & 0 deletions src/Attempt/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,40 @@ public function __construct(
*
* @return self<T>
*/
#[\Override]
public function map(callable $map): self
{
/** @var self<T> */
return $this;
}

#[\Override]
public function flatMap(callable $map): Attempt
{
return Attempt::error($this->value);
}

#[\Override]
public function match(callable $result, callable $error)
{
/** @psalm-suppress ImpureFunctionCall */
return $error($this->value);
}

#[\Override]
public function recover(callable $recover): Attempt
{
/** @psalm-suppress ImpureFunctionCall */
return $recover($this->value);
}

#[\Override]
public function maybe(): Maybe
{
return Maybe::nothing();
}

#[\Override]
public function either(): Either
{
return Either::left($this->value);
Expand All @@ -65,6 +71,7 @@ public function either(): Either
/**
* @return Attempt<R1>
*/
#[\Override]
public function memoize(): Attempt
{
return Attempt::error($this->value);
Expand Down
7 changes: 7 additions & 0 deletions src/Attempt/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,40 @@ public function __construct(
) {
}

#[\Override]
public function map(callable $map): self
{
/** @psalm-suppress ImpureFunctionCall */
return new self($map($this->value));
}

#[\Override]
public function flatMap(callable $map): Attempt
{
/** @psalm-suppress ImpureFunctionCall */
return $map($this->value);
}

#[\Override]
public function match(callable $result, callable $error)
{
/** @psalm-suppress ImpureFunctionCall */
return $result($this->value);
}

#[\Override]
public function recover(callable $recover): Attempt
{
return Attempt::result($this->value);
}

#[\Override]
public function maybe(): Maybe
{
return Maybe::just($this->value);
}

#[\Override]
public function either(): Either
{
return Either::right($this->value);
Expand All @@ -61,6 +67,7 @@ public function either(): Either
/**
* @return Attempt<R1>
*/
#[\Override]
public function memoize(): Attempt
{
return Attempt::result($this->value);
Expand Down
10 changes: 10 additions & 0 deletions src/Either/Defer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,53 @@ public function __construct($deferred)
$this->deferred = $deferred;
}

#[\Override]
public function map(callable $map): self
{
$captured = $this->capture();

return new self(static fn() => self::detonate($captured)->map($map));
}

#[\Override]
public function flatMap(callable $map): Either
{
$captured = $this->capture();

return Either::defer(static fn() => self::detonate($captured)->flatMap($map));
}

#[\Override]
public function leftMap(callable $map): self
{
$captured = $this->capture();

return new self(static fn() => self::detonate($captured)->leftMap($map));
}

#[\Override]
public function match(callable $right, callable $left)
{
return $this->unwrap()->match($right, $left);
}

#[\Override]
public function otherwise(callable $otherwise): Either
{
$captured = $this->capture();

return Either::defer(static fn() => self::detonate($captured)->otherwise($otherwise));
}

#[\Override]
public function filter(callable $predicate, callable $otherwise): Implementation
{
$captured = $this->capture();

return new self(static fn() => self::detonate($captured)->filter($predicate, $otherwise));
}

#[\Override]
public function maybe(): Maybe
{
$captured = $this->capture();
Expand All @@ -80,18 +87,21 @@ public function maybe(): Maybe
/**
* @return Either<L1, R1>
*/
#[\Override]
public function memoize(): Either
{
return $this->unwrap();
}

#[\Override]
public function flip(): self
{
$captured = $this->capture();

return new self(static fn() => self::detonate($captured)->flip());
}

#[\Override]
public function eitherWay(callable $right, callable $left): Either
{
$captured = $this->capture();
Expand Down
10 changes: 10 additions & 0 deletions src/Either/Left.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,47 @@ public function __construct($value)
*
* @return self<L1, T>
*/
#[\Override]
public function map(callable $map): self
{
/** @var self<L1, T> */
return $this;
}

#[\Override]
public function flatMap(callable $map): Either
{
return Either::left($this->value);
}

#[\Override]
public function leftMap(callable $map): self
{
/** @psalm-suppress ImpureFunctionCall */
return new self($map($this->value));
}

#[\Override]
public function match(callable $right, callable $left)
{
/** @psalm-suppress ImpureFunctionCall */
return $left($this->value);
}

#[\Override]
public function otherwise(callable $otherwise): Either
{
/** @psalm-suppress ImpureFunctionCall */
return $otherwise($this->value);
}

#[\Override]
public function filter(callable $predicate, callable $otherwise): self
{
return $this;
}

#[\Override]
public function maybe(): Maybe
{
return Maybe::nothing();
Expand All @@ -77,16 +84,19 @@ public function maybe(): Maybe
/**
* @return Either<L1, R1>
*/
#[\Override]
public function memoize(): Either
{
return Either::left($this->value);
}

#[\Override]
public function flip(): Implementation
{
return new Right($this->value);
}

#[\Override]
public function eitherWay(callable $right, callable $left): Either
{
/** @psalm-suppress ImpureFunctionCall */
Expand Down
Loading
Loading