CoreFiles by mySites.guru
AcceptMatch.php62 lines, 1,198 bytes, from Joomla_4.3.2-Stable-Full_Package.zip
Raw History Compare with 4.3.1
md5
5113caebb5182bcba83eca34af9759e0
sha1
620d9098048b7bd59070df4847601a4adcae8145
sha256
8feeb85c1cda5642519b58a780a7fb2f5a9863a7726b3febf270afc04a374929
<?php

namespace Negotiation;

final class AcceptMatch
{
    /**
     * @var float
     */
    public $quality;

    /**
     * @var int
     */
    public $score;

    /**
     * @var int
     */
    public $index;

    public function __construct($quality, $score, $index)
    {
        $this->quality = $quality;
        $this->score   = $score;
        $this->index   = $index;
    }

    /**
     * @param AcceptMatch $a
     * @param AcceptMatch $b
     *
     * @return int
     */
    public static function compare(AcceptMatch $a, AcceptMatch $b)
    {
        if ($a->quality !== $b->quality) {
            return $a->quality > $b->quality ? -1 : 1;
        }

        if ($a->index !== $b->index) {
            return $a->index > $b->index ? 1 : -1;
        }

        return 0;
    }

    /**
     * @param array   $carry reduced array
     * @param AcceptMatch $match match to be reduced
     *
     * @return AcceptMatch[]
     */
    public static function reduce(array $carry, AcceptMatch $match)
    {
        if (!isset($carry[$match->index]) || $carry[$match->index]->score < $match->score) {
            $carry[$match->index] = $match;
        }

        return $carry;
    }
}

The same content is in 282 releases, Joomla 4.0.0-rc1 to 6.3.0-alpha1. See them all, or every version of this file.