<commit_before><?php

namespace Nova\Pagination;

use Nova\Support\Str;


class UrlGenerator
{
    /**
     * The query string variable used to store the page.
     *
     * @var string
     */
    protected $pageName = 'page';


    /**
     * Create a new URL Generator instance.
     *
     * @param  string  $path
     * @param  string  $pageName
     * @return void
     */
    public function __construct($pageName)
    {
        $this->pageName = $pageName;
    }

    /**
     * Resolve the URL for a given page number.
     *
     * @param  int  $page
     * @param  string  $path
     * @param  array  $query
     * @param  string|null  $fragment
     * @return string
     */
    public function pageUrl($page, $path, array $query, $fragment)
    {
        $pageName = $this->getPageName();

        //
        $query = array_merge($query, array($pageName => $page));

        return $this->buildUrl($path, $query, $fragment);
    }

    /**
     * Build the full query portion of a URL.
     *
     * @param  string  $path
     * @param  array  $query
     * @param  string|null  $fragment
     * @return string
     */
    protected function buildUrl($path, array $query, $fragment)
    {
        if (! empty($query)) {
            $separator = Str::contains($path, '?') ? '&' : '?';

            $path .= $separator .http_build_query($query, '', '&');
        }<commit_msg>Improve the Nova\Pagination\UrlGenerator<commit_after><?php

namespace Nova\Pagination;

use Nova\Support\Str;


class UrlGenerator
{
    /**
     * The query string variable used to store the page.
     *
     * @var string
     */
    protected $pageName = 'page';


    /**
     * Create a new URL Generator instance.
     *
     * @param  string  $path
     * @param  string  $pageName
     * @return void
     */
    public function __construct($pageName)
    {
        $this->pageName = $pageName;
    }

    /**
     * Resolve the URL for a given page number.
     *
     * @param  int  $page
     * @param  string  $path
     * @param  array  $query
     * @param  string|null  $fragment
     * @return string
     */
    public function pageUrl($page, $path, array $query, $fragment)
    {
        $pageName = $this->getPageName();

        return $this->buildUrl(
            $path, array_merge($query, array($pageName => $page)), $fragment
        );
    }

    /**
     * Build the full query portion of a URL.
     *
     * @param  string  $path
     * @param  array  $query
     * @param  string|null  $fragment
     * @return string
     */
    protected function buildUrl($path, array $query, $fragment)
    {
        if (! empty($query)) {
            $separator = Str::contains($path, '?') ? '&' : '?';

            $path .= $separator .http_build_query($query, '', '&');
        }
{'fraction_non_alphanumeric': 0.13711414213926776, 'fraction_numerical': 0.0, 'mean_word_length': 1.9460887949260042, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '7225824', 'n_tokens_mistral': 876, 'n_tokens_neox': 859, 'n_words': 223}