diff --git a/src/Negotiation/AbstractNegotiator.php b/src/Negotiation/AbstractNegotiator.php index cf01c1c..669941e 100644 --- a/src/Negotiation/AbstractNegotiator.php +++ b/src/Negotiation/AbstractNegotiator.php @@ -53,7 +53,7 @@ public function getBest($header, array $priorities, $strict = false) } /** - * @param string $header A string containing an `Accept|Accept-*` header. + * @param string $header A string containing an `Accept|Accept-*` header. * * @return [AcceptHeader] An ordered list of accept header elements */ @@ -74,18 +74,18 @@ public function getOrderedElements($header) // silently skip in case of invalid headers coming in from a client } } - + // sort based on quality and then original order. This is necessary as // to ensure that the first in the list for two items with the same // quality stays in that order in both PHP5 and PHP7. uasort($orderKeys, function ($a, $b) { $qA = $a[0]; $qB = $b[0]; - + if ($qA == $qB) { return $a[1] > $b[1]; } - + return ($qA > $qB) ? -1 : 1; }); @@ -97,7 +97,6 @@ public function getOrderedElements($header) return $orderedElements; } - /** * @param string $header accept header part or server priority * diff --git a/tests/Negotiation/Tests/NegotiatorTest.php b/tests/Negotiation/Tests/NegotiatorTest.php index 98ae7dc..a43fcf0 100644 --- a/tests/Negotiation/Tests/NegotiatorTest.php +++ b/tests/Negotiation/Tests/NegotiatorTest.php @@ -109,11 +109,13 @@ public function testGetOrderedElements($header, $expected) $elements = $this->negotiator->getOrderedElements($header); } catch (\Exception $e) { $this->assertEquals($expected, $e); + return; } if (empty($elements)) { $this->assertNull($expected); + return; } @@ -133,7 +135,7 @@ public static function dataProviderForTestGetOrderedElements() // first one wins as no quality modifiers array('text/html, text/xml', array('text/html', 'text/xml')), - + // ordered by quality modifier array( 'text/html;q=0.3, text/html;q=0.7',