@@ -46,18 +46,15 @@ public function __construct(array $items)
4646 */
4747 public static function fromString (?string $ headerValue ): self
4848 {
49- $ parts = HeaderUtils::split ($ headerValue ?? '' , ',;= ' );
49+ $ items = [];
50+ foreach (HeaderUtils::split ($ headerValue ?? '' , ',;= ' ) as $ i => $ parts ) {
51+ $ part = array_shift ($ parts );
52+ $ item = new AcceptHeaderItem ($ part [0 ], HeaderUtils::combine ($ parts ));
5053
51- return new self (array_map (function ($ subParts ) {
52- static $ index = 0 ;
53- $ part = array_shift ($ subParts );
54- $ attributes = HeaderUtils::combine ($ subParts );
55-
56- $ item = new AcceptHeaderItem ($ part [0 ], $ attributes );
57- $ item ->setIndex ($ index ++);
54+ $ items [] = $ item ->setIndex ($ i );
55+ }
5856
59- return $ item ;
60- }, $ parts ));
57+ return new self ($ items );
6158 }
6259
6360 /**
@@ -95,10 +92,11 @@ public function get(string $value): ?AcceptHeaderItem
9592 return null ;
9693 }
9794
98- usort ($ candidates , fn ($ a , $ b ) =>
99- $ this ->getSpecificity ($ b , $ queryItem ) <=> $ this ->getSpecificity ($ a , $ queryItem ) // Descending specificity
100- ?: $ b ->getQuality () <=> $ a ->getQuality () // Descending quality
101- ?: $ a ->getIndex () <=> $ b ->getIndex () // Ascending index (stability)
95+ usort (
96+ $ candidates ,
97+ fn ($ a , $ b ) => $ this ->getSpecificity ($ b , $ queryItem ) <=> $ this ->getSpecificity ($ a , $ queryItem ) // Descending specificity
98+ ?: $ b ->getQuality () <=> $ a ->getQuality () // Descending quality
99+ ?: $ a ->getIndex () <=> $ b ->getIndex () // Ascending index (stability)
102100 );
103101
104102 return reset ($ candidates );
0 commit comments