stored_job( $job ); $initial = JobState::initial( $job ); return new JobState( $this->stored_flag( $stored, $initial->enabled ), $job->accepted_frequency( $stored['frequency'] ?? null ) ?? $initial->frequency, $this->stored_number( $stored, 'last_run_at' ), $this->stored_number( $stored, 'last_count' ) ); } public function save( JobId $job, JobState $state ): void { $stored_jobs = $this->stored_jobs(); $stored_jobs[ $job->value ] = $state->to_array(); update_option( self::OPTION, $stored_jobs, false ); } /** @return array */ private function stored_jobs(): array { $stored_jobs = get_option( self::OPTION, array() ); return is_array( $stored_jobs ) ? $stored_jobs : array(); } /** @return array */ private function stored_job( JobId $job ): array { $stored_job = $this->stored_jobs()[ $job->value ] ?? array(); return is_array( $stored_job ) ? $stored_job : array(); } /** @param array $stored */ private function stored_flag( array $stored, bool $fallback ): bool { $enabled = $stored['enabled'] ?? null; return is_bool( $enabled ) ? $enabled : $fallback; } /** @param array $stored */ private function stored_number( array $stored, string $field_name ): int|null { $number = $stored[ $field_name ] ?? null; return is_int( $number ) ? $number : null; } }