[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/willdurand/negotiation/src/Negotiation/ -> AcceptMatch.php (source)

   1  <?php
   2  
   3  namespace Negotiation;
   4  
   5  final class AcceptMatch
   6  {
   7      /**
   8       * @var float
   9       */
  10      public $quality;
  11  
  12      /**
  13       * @var int
  14       */
  15      public $score;
  16  
  17      /**
  18       * @var int
  19       */
  20      public $index;
  21  
  22      public function __construct($quality, $score, $index)
  23      {
  24          $this->quality = $quality;
  25          $this->score   = $score;
  26          $this->index   = $index;
  27      }
  28  
  29      /**
  30       * @param AcceptMatch $a
  31       * @param AcceptMatch $b
  32       *
  33       * @return int
  34       */
  35      public static function compare(AcceptMatch $a, AcceptMatch $b)
  36      {
  37          if ($a->quality !== $b->quality) {
  38              return $a->quality > $b->quality ? -1 : 1;
  39          }
  40  
  41          if ($a->index !== $b->index) {
  42              return $a->index > $b->index ? 1 : -1;
  43          }
  44  
  45          return 0;
  46      }
  47  
  48      /**
  49       * @param array   $carry reduced array
  50       * @param AcceptMatch $match match to be reduced
  51       *
  52       * @return AcceptMatch[]
  53       */
  54      public static function reduce(array $carry, AcceptMatch $match)
  55      {
  56          if (!isset($carry[$match->index]) || $carry[$match->index]->score < $match->score) {
  57              $carry[$match->index] = $match;
  58          }
  59  
  60          return $carry;
  61      }
  62  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer