finished_at, posts_count: $state->posts_count, first_run: $state->first_run ); } public function with_run_state( ScanState $state, ScanRunState $run_state ): ScanState { return $this->changed( $state, $run_state, $state->phase, $state->last_read_post_id, $state->posts_read ); } public function cancelled( ScanState $state ): ScanState { return new ScanState( finished_at: $state->finished_at, posts_count: $state->posts_count, first_run: $state->first_run ); } public function advanced( ScanState $state, int $last_read_post_id, int $posts_read_now ): ScanState { return $this->changed( $state, $state->run_state, $state->phase, $last_read_post_id, $state->posts_read + $posts_read_now ); } public function checking( ScanState $state ): ScanState { return $this->changed( $state, $state->run_state, ScanPhase::Checking, $state->last_read_post_id, $state->posts_read ); } public function finished( ScanState $state, int $now ): ScanState { return new ScanState( finished_at: $now, posts_count: $state->posts_read, first_run: false ); } private function changed( ScanState $state, ScanRunState $run_state, ScanPhase|null $phase, int $last_read_post_id, int $posts_read ): ScanState { return new ScanState( run_state: $run_state, phase: $phase, started_at: $state->started_at, last_read_post_id: $last_read_post_id, posts_read: $posts_read, finished_at: $state->finished_at, posts_count: $state->posts_count, first_run: $state->first_run ); } }