Lines
100.00%
6 / 6
Methods
100.00%
5 / 5
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| rules | n/a | 0 / 0 | n/a | 0 / 0 | 0 | ||
| run | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| me | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| send | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| now | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 22 | abstract class BotScript implements Script | |
| 23 | { | |
| 24 | private Character $me; | |
| 25 | ||
| 26 | /** @var Closure(): Timestamp */ | |
| 27 | private readonly Closure $clock; | |
| 28 | ||
| 29 | /** @param null|Closure(): Timestamp $clock */ | |
| 30 | public function __construct(?Closure $clock = null) | |
| 31 | { | |
| 32 | $this->clock = $clock ?? Timestamp::monotonic(...); | |
| 33 | } | |
| 34 | ||
| 35 | /** @return Generator<int, Instruction, null|Event|TimedOut, object> */ | |
| 36 | abstract protected function rules(): Generator; | |
| 37 | ||
| 38 | /** @return Generator<int, Instruction, null|Event|TimedOut, object> */ | |
| 39 | #[Override] | |
| 40 | final public function run(Character $me): Generator | |
| 41 | { | |
| 42 | $this->me = $me; | |
| 43 | ||
| 44 | return $this->rules(); | |
| 45 | } | |
| 46 | ||
| 47 | public function me(): Character | |
| 48 | { | |
| 49 | return $this->me; | |
| 50 | } | |
| 51 | ||
| 52 | public function send(Command $command): Send | |
| 53 | { | |
| 54 | return new Send($command); | |
| 55 | } | |
| 56 | ||
| 57 | public function now(): Timestamp | |
| 58 | { | |
| 59 | return ($this->clock)(); | |
| 60 | } | |
| 61 | } |