<commit_before><?php
class Paginator {
	private $current_page, $total_pages;

	function __construct($_current, $_total) {
		$this->current_page = $_current;
		$this->total_pages = $_total;
	}

	private function get_classes_string($classes) {
		if (count($classes)) {
			return ' class = "' . join(" ", $classes) . '"';
		} else {
			return "";
		}
	}

	private function get_left_arrow() {
		$classes = [];

		if ($this->current_page == 1) {
			$classes[] = "disabled";
			$open_tag = "<span>";
			$close_tag = "</span>";
		} else {
			$target_page = $this->current_page - 1;
			$open_tag = "<a href=\"?page=$target_page\">";
			$close_tag = "</a>";
		}

		$classes_string = $this->get_classes_string($classes);

		$output = <<<"HEREDOC"
<li$classes_string>
	$open_tag
		&laquo;
	$close_tag
</li>
HEREDOC;

		return $output;
	}

	private function get_right_arrow() {
		$classes = [];

		if ($this->current_page == $this->total_pages) {
			$classes[] = "disabled";
			$open_tag = "<span>";
			$close_tag = "</span>";
		} else {
			$target_page = $this->current_page + 1;
			$open_tag = "<a href=\"?page=$target_page\">";
			$close_tag = "</a>";
		}

		$classes_string = $this->get_classes_string($classes);

		$output = <<<"HEREDOC"
<li$classes_string>
	$open_tag
		&raquo;
	$close_tag
</li>
HEREDOC;

		return $output;
	}

	private function get_item($index) {
		$classes = [];

		if ($this->current_page == $index) {
			$classes[] = "active";
			$open_tag = "<span>";
			$close_tag = "</span>";
		} elseif (is_string($index)) {
			$classes[] = "disabled";
			$open_tag = "<span>";
			$close_tag = "</span>";
		} else {
			$open_tag = "<a href=\"?page=$index\">";
			$close_tag = "</a>";
		}

		$classes_string = $this->get_classes_string($classes);

		$output = <<<"HEREDOC"
<li$classes_string>
	$open_tag
		$index
	$close_tag
</li>
HEREDOC;

		return $output;
	}

	function get_required_index() {
		$index = [];
		for ($i = 1; $i <= 3; $i++) {
			$index[] = $i;
		}

		for ($i = max(4, $this->current_page - 2); $i <= $this->current_page + 2; $i++) {
			$index[] = $i;
		}

		for ($i = max($this->current_page + 3, $this->total_pages - 2); $i <= $this->total_pages; $i++) {
			$index[] = $i;
		}

		return $index;
	}

	function get_output() {
		if ($this->total_pages <= 1) {
			return "";
		}

		$index = $this->get_required_index();

		$output = '<ul class="pagination">';

		$output .= $this->get_left_arrow();

		for ($i = 0; $i < count($index); $i++) {
			if ($i && $index[$i] != $index[$i-1] + 1) {
				$output .= $this->get_item("&#x22EF;");
			}<commit_msg>Ensure that the page numbers generated are valid especially when the total pages is little.<commit_after><?php
class Paginator {
	private $current_page, $total_pages;

	function __construct($_current, $_total) {
		$this->current_page = $_current;
		$this->total_pages = $_total;
	}

	private function get_classes_string($classes) {
		if (count($classes)) {
			return ' class = "' . join(" ", $classes) . '"';
		} else {
			return "";
		}
	}

	private function get_left_arrow() {
		$classes = [];

		if ($this->current_page == 1) {
			$classes[] = "disabled";
			$open_tag = "<span>";
			$close_tag = "</span>";
		} else {
			$target_page = $this->current_page - 1;
			$open_tag = "<a href=\"?page=$target_page\">";
			$close_tag = "</a>";
		}

		$classes_string = $this->get_classes_string($classes);

		$output = <<<"HEREDOC"
<li$classes_string>
	$open_tag
		&laquo;
	$close_tag
</li>
HEREDOC;

		return $output;
	}

	private function get_right_arrow() {
		$classes = [];

		if ($this->current_page == $this->total_pages) {
			$classes[] = "disabled";
			$open_tag = "<span>";
			$close_tag = "</span>";
		} else {
			$target_page = $this->current_page + 1;
			$open_tag = "<a href=\"?page=$target_page\">";
			$close_tag = "</a>";
		}

		$classes_string = $this->get_classes_string($classes);

		$output = <<<"HEREDOC"
<li$classes_string>
	$open_tag
		&raquo;
	$close_tag
</li>
HEREDOC;

		return $output;
	}

	private function get_item($index) {
		$classes = [];

		if ($this->current_page == $index) {
			$classes[] = "active";
			$open_tag = "<span>";
			$close_tag = "</span>";
		} elseif (is_string($index)) {
			$classes[] = "disabled";
			$open_tag = "<span>";
			$close_tag = "</span>";
		} else {
			$open_tag = "<a href=\"?page=$index\">";
			$close_tag = "</a>";
		}

		$classes_string = $this->get_classes_string($classes);

		$output = <<<"HEREDOC"
<li$classes_string>
	$open_tag
		$index
	$close_tag
</li>
HEREDOC;

		return $output;
	}

	function get_required_index() {
		$index = [];
		for ($i = 1; $i <= 3 && $i <= $this->total_pages; $i++) {
			$index[] = $i;
		}

		for ($i = max(4, $this->current_page - 2); $i <= $this->current_page + 2 && $i <= $this->total_pages; $i++) {
			$index[] = $i;
		}

		for ($i = max($this->current_page + 3, $this->total_pages - 2); $i <= $this->total_pages; $i++) {
			$index[] = $i;
		}

		return $index;
	}

	function get_output() {
		if ($this->total_pages <= 1) {
			return "";
		}

		$index = $this->get_required_index();

		$output = '<ul class="pagination">';

		$output .= $this->get_left_arrow();

		for ($i = 0; $i < count($index); $i++) {
			if ($i && $index[$i] != $index[$i-1] + 1) {
				$output .= $this->get_item("&#x22EF;");
			}
{'fraction_non_alphanumeric': 0.22245440729483282, 'fraction_numerical': 0.0060790273556231, 'mean_word_length': 3.492320819112628, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2083308', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2023, 'n_words': 402}