Add goals repository and configurable rules engine

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-15 08:44:52 -08:00
1 parent 939193f258
commit 7155396312
19 files changed
+882

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
<?php
declare( strict_types=1 );
namespace StreamGoals\Rules;
/** Emits a named event when a single donation meets min_minor. */
final class BonusRule {
public function __construct(
public readonly int $minMinor,
public readonly string $event,
public readonly string $basis = 'base'
) {
if ( $minMinor <= 0 || '' === $event ) {
throw new \InvalidArgumentException( 'Invalid bonus config.' );
}
}
public static function fromConfig( array $c ): self {
return new self(
(int) ( $c['min_minor'] ?? 0 ),
(string) ( $c['event'] ?? 'bonus' ),
'total' === ( $c['basis'] ?? 'base' ) ? 'total' : 'base'
);
}
/** @return int 1 if the bonus triggers, else 0. */
public function apply( Donation $d ): int {
return $d->amountFor( $this->basis ) >= $this->minMinor ? 1 : 0;
}
}