Skip to content

Commit

Permalink
Fixed filtering rejections code
Browse files Browse the repository at this point in the history
  • Loading branch information
gplanchat committed Dec 11, 2024
1 parent 8382034 commit 9694ef8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
21 changes: 15 additions & 6 deletions src/Plugin/Filtering/Builder/Drop.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ final class Drop implements StepBuilderInterface
private ?Node\Expr $logger = null;
private ?Node\Expr $rejection = null;
private ?Node\Expr $state = null;

private ?string $reason = null;

/** @var list<?Node\Expr> */
private array $exclusions = [];

Expand Down Expand Up @@ -48,6 +51,13 @@ public function withExclusions(Node\Expr ...$exclusions): self
return $this;
}

public function withReason(string $reason): self
{
$this->reason = $reason;

return $this;
}

private function buildExclusions(Node\Expr ...$exclusions): Node\Expr
{
if (\count($exclusions) > 3) {
Expand Down Expand Up @@ -122,16 +132,15 @@ class: new Node\Stmt\Class_(null, [
new Node\Expr\Variable('input'),
new Node\Expr\Yield_(
new Node\Expr\New_(
class: new Node\Name\FullyQualified('Kiboko\\Component\\Bucket\\RejectionResultBucket'),
class: new Node\Name\FullyQualified(
\Kiboko\Component\Bucket\RejectionResultBucket::class
),
args: [
new Node\Arg(
new Node\Expr\MethodCall(
new Node\Expr\Variable('exception'),
'getMessage'
),
new Node\Scalar\String_($this->reason),
),
new Node\Arg(
new Node\Expr\Variable('exception'),
new Node\Expr\ConstFetch(new Node\Name('null')),
),
new Node\Arg(
new Node\Expr\Variable('input'),
Expand Down
17 changes: 12 additions & 5 deletions src/Plugin/Filtering/Builder/Reject.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ final class Reject implements StepBuilderInterface
private ?Node\Expr $logger = null;
private ?Node\Expr $rejection = null;
private ?Node\Expr $state = null;

private ?string $reason = null;

/** @var list<?Node\Expr> */
private array $exclusions = [];

Expand Down Expand Up @@ -48,6 +51,13 @@ public function withExclusions(Node\Expr ...$exclusions): self
return $this;
}

public function withReason(string $reason): self
{
$this->reason = $reason;

return $this;
}

private function buildExclusions(Node\Expr ...$exclusions): Node\Expr
{
if (\count($exclusions) > 3) {
Expand Down Expand Up @@ -127,13 +137,10 @@ class: new Node\Name\FullyQualified(
),
args: [
new Node\Arg(
new Node\Expr\MethodCall(
new Node\Expr\Variable('exception'),
'getMessage'
),
new Node\Scalar\String_($this->reason),
),
new Node\Arg(
new Node\Expr\Variable('exception'),
new Node\Expr\ConstFetch(new Node\Name('null')),
),
new Node\Arg(
new Node\Expr\Variable('input'),
Expand Down

0 comments on commit 9694ef8

Please sign in to comment.