posts = $posts; $this->total = $total; $this->page = $page; $this->per_page = $per_page; } /** * Returns the total number of pages. * * @return int The total number of pages. */ public function get_total_pages(): int { if ( $this->per_page < 1 ) { return 0; } return (int) \ceil( $this->total / $this->per_page ); } /** * Parses the page to the expected key value representation. * * @return array>> The page presented as the expected key value representation. */ public function to_array(): array { return [ 'posts' => $this->posts->to_array(), 'total' => $this->total, 'total_pages' => $this->get_total_pages(), 'page' => $this->page, 'per_page' => $this->per_page, ]; } }