HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wpmuhibbah/wp-content/plugins/give/src/Framework/PaymentGateways/DonationSummary.php
<?php

namespace Give\Framework\PaymentGateways;

use Give\Donations\Models\Donation;

/**
 * @since 2.19.0
 */
class DonationSummary
{
    /** @var int */
    protected $length = 255;

    /** @var Donation */
    protected $donation;

    /**
     * @since 2.19.0
     */
    public function __construct(Donation $donation)
    {
        $this->donation = $donation;
    }

    /**
     * @since 2.19.0
     *
     * @param int $length
     */
    public function setLength(int $length)
    {
        $this->length = $length;
    }

    /**
     * @since 2.19.0
     *
     * @return string
     */
    public function getSummaryWithDonor(): string
    {
        return $this->trim(
            implode(' - ', [
                $this->getSummary(),
                $this->getDonorLabel(),
            ])
        );
    }

    /**
     * @since 2.19.0
     *
     * @return string
     */
    public function getSummary(): string
    {
        return $this->trimAndFilter(
            implode(
                ': ',
                array_filter([
                    $this->getLabel(),
                    $this->getPriceLabel(),
                ])
            )
        );
    }

    /**
     * @since 2.19.0
     *
     * @return string
     */
    protected function getLabel(): string
    {
        $formId = give_get_payment_form_id($this->donation->id);
        $formTitle = get_the_title($formId);
        return $formTitle ?: sprintf(__('Donation Form ID: %d', 'give'), $formId);
    }

    /**
     * @since 2.19.0
     * @return string
     */
    protected function getPriceLabel(): string
    {
        $priceId = $this->donation->levelId;

        return is_numeric($priceId)
            ? give_get_price_option_name($this->donation->formId, $this->donation->levelId)
            : '';
    }

    /**
     * @since 2.19.0
     */
    protected function getDonorLabel(): string
    {
        return sprintf(
            '%s %s (%s)',
            $this->donation->firstName,
            $this->donation->lastName,
            $this->donation->email
        );
    }

    /**
     * @since 2.19.0
     *
     * @param string $text
     *
     * @return string
     */
    protected function trimAndFilter(string $text): string
    {
        /**
         * @since 2.25.0 Re-use trim method for text.
         * @since 1.8.12
         */
        return apply_filters('give_payment_gateway_donation_summary', $this->trim($text));
    }

    /**
     * @since 2.25.0
     *
     * @param string $text
     *
     * @return string
     */
    protected function trim(string $text): string
    {
        return substr($text, 0, $this->length);
    }
}