Skip to content

Commit

Permalink
TrapHandle: add if(condition) method to dump only if the condition …
Browse files Browse the repository at this point in the history
…is true.
  • Loading branch information
roxblnfk committed Nov 25, 2023
1 parent 5097ee1 commit bba2d9c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Client/TrapHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ public static function fromArray(array $array): self
return $new;
}

/**
* Dump only if the condition is true.
*/
public function if(bool|callable $condition): self
{
if (\is_callable($condition)) {
$condition = $condition();

Check failure on line 32 in src/Client/TrapHandle.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)

MixedAssignment

src/Client/TrapHandle.php:32:13: MixedAssignment: Unable to determine the type that $condition is being assigned to (see https://psalm.dev/032)
}

$this->haveToSend = $condition;

Check failure on line 35 in src/Client/TrapHandle.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)

MixedAssignment

src/Client/TrapHandle.php:35:9: MixedAssignment: Unable to determine the type that $this->haveToSend is being assigned to (see https://psalm.dev/032)
return $this;
}

public function __destruct()
{
$this->haveToSend and $this->sendUsingDump();
Expand Down

0 comments on commit bba2d9c

Please sign in to comment.