<commit_before><?php

/**
 * Class for negotiating on mime types.
 *
 * PHP Version 5.3
 *
 * @copyright   (c) 2006-2014 <NAME>
 * @author      <NAME> <<EMAIL>>
 * @license     http://opensource.org/licenses/MIT MIT
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ptlis\ConNeg\Negotiator;

use ptlis\ConNeg\Collection\MimeTypePairCollection;
use ptlis\ConNeg\Collection\TypeCollection;
use ptlis\ConNeg\Collection\TypePairSort;
use ptlis\ConNeg\QualityFactor\QualityFactor;
use ptlis\ConNeg\TypePair\MimeTypePair;
use ptlis\ConNeg\Type\Mime\AbsentMimeType;
use ptlis\ConNeg\Type\Mime\MimeTypeFactory;
use ptlis\ConNeg\Type\Mime\MimeTypeInterface;
use ptlis\ConNeg\Type\Mime\MimeWildcardSubType;
use ptlis\ConNeg\Type\Mime\MimeWildcardType;

/**
 * Class for negotiating on mime types.
 */
class MimeNegotiator implements NegotiatorInterface
{
    /**
     * @var MimeTypeFactory
     */
    private $typeFactory;


    /**
     * Constructor
     *
     * @param MimeTypeFactory $typeFactory
     */
    public function __construct(MimeTypeFactory $typeFactory)
    {
        $this->typeFactory = $typeFactory;
    }


    /**
     * Return a collection of types sorted by preference.
     *
     * @param TypeCollection $userTypeList
     * @param TypeCollection $appTypeList
     *
     * @return MimeTypePairCollection
     */
    public function negotiateAll(TypeCollection $userTypeList, TypeCollection $appTypeList)
    {
        $matchingList = array();
        foreach ($appTypeList as $appType) {
            $matchingList[$appType->getType()] = new MimeTypePair(
                $appType,
                new AbsentMimeType(new QualityFactor(0))
            );
        }

        $matchingList = $this->matchUserToAppTypes($userTypeList, $matchingList);

        $pairCollection = new MimeTypePairCollection();

        foreach ($matchingList as $matching) {
            $pairCollection->addPair($matching);
        }

        return $pairCollection->getDescending();
    }


    /**
     * Return the preferred type & product of application & user-agent quality factors.
     *
     * @param TypeCollection $userTypeList
     * @param TypeCollection $appTypeList
     *
     * @return MimeTypePair
     */
    public function negotiateBest(TypeCollection $userTypeList, TypeCollection $appTypeList)<commit_msg>Removed another direct use of QualityFactor class.<commit_after><?php

/**
 * Class for negotiating on mime types.
 *
 * PHP Version 5.3
 *
 * @copyright   (c) 2006-2014 <NAME>
 * @author      <NAME> <<EMAIL>>
 * @license     http://opensource.org/licenses/MIT MIT
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ptlis\ConNeg\Negotiator;

use ptlis\ConNeg\Collection\MimeTypePairCollection;
use ptlis\ConNeg\Collection\TypeCollection;
use ptlis\ConNeg\Collection\TypePairSort;
use ptlis\ConNeg\TypePair\MimeTypePair;
use ptlis\ConNeg\Type\Mime\MimeTypeFactory;
use ptlis\ConNeg\Type\Mime\MimeTypeInterface;
use ptlis\ConNeg\Type\Mime\MimeWildcardSubType;
use ptlis\ConNeg\Type\Mime\MimeWildcardType;

/**
 * Class for negotiating on mime types.
 */
class MimeNegotiator implements NegotiatorInterface
{
    /**
     * @var MimeTypeFactory
     */
    private $typeFactory;


    /**
     * Constructor
     *
     * @param MimeTypeFactory $typeFactory
     */
    public function __construct(MimeTypeFactory $typeFactory)
    {
        $this->typeFactory = $typeFactory;
    }


    /**
     * Return a collection of types sorted by preference.
     *
     * @param TypeCollection $userTypeList
     * @param TypeCollection $appTypeList
     *
     * @return MimeTypePairCollection
     */
    public function negotiateAll(TypeCollection $userTypeList, TypeCollection $appTypeList)
    {
        $matchingList = array();
        foreach ($appTypeList as $appType) {
            $matchingList[$appType->getType()] = new MimeTypePair(
                $appType,
                $this->typeFactory->get('', 0)
            );
        }

        $matchingList = $this->matchUserToAppTypes($userTypeList, $matchingList);

        $pairCollection = new MimeTypePairCollection();

        foreach ($matchingList as $matching) {
            $pairCollection->addPair($matching);
        }

        return $pairCollection->getDescending();
    }


    /**
     * Return the preferred type & product of application & user-agent quality factors.
     *
     * @param TypeCollection $userTypeList
     * @param TypeCollection $appTypeList
     *
     * @return MimeTypePair
     */
    public function negotiateBest(TypeCollection $userTypeList, TypeCollection $appTypeList)
{'fraction_non_alphanumeric': 0.10138248847926268, 'fraction_numerical': 0.004608294930875576, 'mean_word_length': 2.952814569536424, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '1536712', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1393, 'n_words': 314}