-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a new builder to manage exclusions
- Loading branch information
Showing
4 changed files
with
70 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kiboko\Component\Satellite\Plugin\Filtering\Builder; | ||
|
||
use Kiboko\Component\Bucket\RejectionResultBucket; | ||
use Kiboko\Component\Bucket\RejectionWithReasonResultBucket; | ||
use PhpParser\Builder; | ||
use PhpParser\Node; | ||
|
||
final class ExclusionsBuilder extends Builder | ||
{ | ||
/** @var list<list<Node\Expr>> */ | ||
private array $exclusions = []; | ||
|
||
public function withCondition(Node\Expr $condition, ?Node\Expr $reason = null):self | ||
{ | ||
$this->exclusions[] = [ | ||
'condition' => $condition, | ||
'reason' => $reason, | ||
]; | ||
|
||
return $this; | ||
} | ||
|
||
public function getNode(): array | ||
{ | ||
$statements = []; | ||
foreach ($this->exclusions as $exclusion) { | ||
$statements[] = new Node\Stmt\If_( | ||
$exclusion['condition'], | ||
[ | ||
'stmts' => [ | ||
new Node\Stmt\Expression( | ||
new Node\Expr\Assign( | ||
new Node\Expr\Variable('input'), | ||
new Node\Expr\Yield_( | ||
new Node\Expr\New_( | ||
\array_key_exists('reason', $exclusion) ? new Node\Name\FullyQualified(RejectionWithReasonResultBucket::class) : new Node\Name\FullyQualified(RejectionResultBucket::class), | ||
[ | ||
new Node\Arg(new Node\Expr\Variable('input')), | ||
\array_key_exists('reason', $exclusion) ? new Node\Arg($exclusion['reason']) : new Node\Arg( | ||
new Node\Expr\ConstFetch( | ||
new Node\Name(null) | ||
), | ||
), | ||
] | ||
), | ||
), | ||
), | ||
), | ||
new Node\Stmt\Continue_(), | ||
], | ||
] | ||
); | ||
} | ||
|
||
return $statements; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters