Repository: symfony/symfony
File: src/Symfony/Component/HttpFoundation/AcceptHeader.php (PHP)

Code before:
        return new self(array_map(function ($subParts) {
            static $index = 0;
            $part = array_shift($subParts);
            $attributes = HeaderUtils::combine($subParts);

            $item = new AcceptHeaderItem($part[0], $attributes);
            $item->setIndex($index++);

            return $item;
        }, $parts));
    }

    /**
     * Returns header value's string representation.
     */
    public function __toString(): string
    {
        return implode(',', $this->items);
    }

    /**
     * Tests if header has given value.
     */
    public function has(string $value): bool
    {
        return null !== $this->get($value);
    }

    /**
     * Returns given value's item, if exists.
     */
    public function get(string $value): ?AcceptHeaderItem
    {
        $queryItem = AcceptHeaderItem::fromString($value.';q=1');
        $baseValue = $queryItem->getValue();
        $queryAttributes = $queryItem->getAttributes();
        $parametersString = $this->buildCanonicalParams($queryAttributes);
        $canonicalKey = $baseValue.($parametersString ? ';'.$parametersString : '');

        if (isset($this->items[$canonicalKey])) {
            return $this->items[$canonicalKey];
        }

        // Find all matching candidates
        $candidates = [];
        foreach ($this->items as $item) {
            if ($this->matches($item, $queryItem)) {
                $candidates[] = $item;
            }
        }


Review comment (suggestion):
```suggestion
        return isset($this->items[$value]) || null !== $this->get($value);
```

Code after:
        return new self(array_map(function ($subParts) {
            static $index = 0;
            $part = array_shift($subParts);
            $attributes = HeaderUtils::combine($subParts);

            $item = new AcceptHeaderItem($part[0], $attributes);
            $item->setIndex($index++);

            return $item;
        }, $parts));
    }

    /**
     * Returns header value's string representation.
     */
    public function __toString(): string
    {
        return implode(',', $this->items);
    }

    /**
     * Tests if header has given value.
     */
    public function has(string $value): bool
    {
        $canonicalKey = $this->getCanonicalKey(AcceptHeaderItem::fromString($value));

        return isset($this->items[$canonicalKey]);
    }

    /**
     * Returns given value's item, if exists.
     */
    public function get(string $value): ?AcceptHeaderItem
    {
        $queryItem = AcceptHeaderItem::fromString($value.';q=1');
        $canonicalKey = $this->getCanonicalKey($queryItem);

        if (isset($this->items[$canonicalKey])) {
            return $this->items[$canonicalKey];
        }

        // Collect and filter matching candidates
        if (!$candidates = array_filter($this->items, fn (AcceptHeaderItem $item) => $this->matches($item, $queryItem))) {
            return null;
        }

        usort($candidates, fn ($a, $b) =>
            $this->getSpecificity($b, $queryItem) <=> $this->getSpecificity($a, $queryItem) // Descending specificity
            ?: $b->getQuality() <=> $a->getQuality() // Descending quality
            ?: $a->getIndex() <=> $b->getIndex() // Ascending index (stability)