*/ private array $rules = []; /** * Next id. * * @var int */ private int $next_id = 1; /** * {@inheritDoc} * * @return list */ public function all_enabled(): array { return array_values( array_filter( $this->rules, static fn( ReminderRule $rule ): bool => $rule->is_enabled() ) ); } /** * {@inheritDoc} * * @return list */ public function all(): array { return $this->rules; } /** * {@inheritDoc} * * @param ReminderRule $rule Rule. */ public function save( ReminderRule $rule ): void { if ( null === $rule->id() ) { $rule->assign_id( $this->next_id++ ); } foreach ( $this->rules as $i => $existing ) { if ( $existing->id() === $rule->id() ) { $this->rules[ $i ] = $rule; return; } } $this->rules[] = $rule; } /** * {@inheritDoc} * * @param int $id Id. */ public function find_by_id( int $id ): ?ReminderRule { foreach ( $this->rules as $rule ) { if ( $rule->id() === $id ) { return $rule; } } return null; } /** * {@inheritDoc} * * @param int $id Id. */ public function delete( int $id ): void { $this->rules = array_values( array_filter( $this->rules, static fn( ReminderRule $rule ): bool => $rule->id() !== $id ) ); } }