From 1313e6d5cb43aa36177fd5c2b166bc2188308f1f Mon Sep 17 00:00:00 2001 From: AzJezz Date: Sun, 8 Apr 2018 11:35:34 +0100 Subject: [PATCH 01/10] Update AbstractNegotiator.php --- src/Negotiation/AbstractNegotiator.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Negotiation/AbstractNegotiator.php b/src/Negotiation/AbstractNegotiator.php index 669941e..6059ecd 100644 --- a/src/Negotiation/AbstractNegotiator.php +++ b/src/Negotiation/AbstractNegotiator.php @@ -13,13 +13,13 @@ abstract class AbstractNegotiator * * @return AcceptHeader|null best matching type */ - public function getBest($header, array $priorities, $strict = false) + public function getBest(string $header, array $priorities,bool $strict = false): ?AcceptHeader { - if (empty($priorities)) { + if ($priorities === []) { throw new InvalidArgument('A set of server priorities should be given.'); } - if (!$header) { + if ($header === '') { throw new InvalidArgument('The header string should not be empty.'); } @@ -55,9 +55,9 @@ public function getBest($header, array $priorities, $strict = false) /** * @param string $header A string containing an `Accept|Accept-*` header. * - * @return [AcceptHeader] An ordered list of accept header elements + * @return AcceptHeader[] An ordered list of accept header elements */ - public function getOrderedElements($header) + public function getOrderedElements(string $header): array { if (!$header) { throw new InvalidArgument('The header string should not be empty.'); @@ -111,7 +111,7 @@ abstract protected function acceptFactory($header); * * @return Match|null Headers matched */ - protected function match(AcceptHeader $header, AcceptHeader $priority, $index) + protected function match(AcceptHeader $header, AcceptHeader $priority, $index): ?Match { $ac = $header->getType(); $pc = $priority->getType(); @@ -132,7 +132,7 @@ protected function match(AcceptHeader $header, AcceptHeader $priority, $index) * * @return AcceptHeader[] */ - private function parseHeader($header) + private function parseHeader($header): array { $res = preg_match_all('/(?:[^,"]*+(?:"[^"]*+")?)+[^,"]*+/', $header, $matches); @@ -149,7 +149,7 @@ private function parseHeader($header) * * @return Match[] Headers matched */ - private function findMatches(array $headerParts, array $priorities) + private function findMatches(array $headerParts, array $priorities): array { $matches = []; foreach ($priorities as $index => $p) { From 315261b5a7b2d3518068d33bf4e24b10ec60072c Mon Sep 17 00:00:00 2001 From: AzJezz Date: Sun, 8 Apr 2018 11:36:34 +0100 Subject: [PATCH 02/10] Update Accept.php --- src/Negotiation/Accept.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Negotiation/Accept.php b/src/Negotiation/Accept.php index 281ae27..9624fa4 100644 --- a/src/Negotiation/Accept.php +++ b/src/Negotiation/Accept.php @@ -31,7 +31,7 @@ public function __construct($value) /** * @return string */ - public function getSubPart() + public function getSubPart(): string { return $this->subPart; } @@ -39,7 +39,7 @@ public function getSubPart() /** * @return string */ - public function getBasePart() + public function getBasePart(): string { return $this->basePart; } From 56ee3f148e763491e0510a63a050d07ac1028acf Mon Sep 17 00:00:00 2001 From: AzJezz Date: Sun, 8 Apr 2018 11:38:09 +0100 Subject: [PATCH 03/10] Update BaseAccept.php --- src/Negotiation/BaseAccept.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Negotiation/BaseAccept.php b/src/Negotiation/BaseAccept.php index 3c58447..08c45b2 100644 --- a/src/Negotiation/BaseAccept.php +++ b/src/Negotiation/BaseAccept.php @@ -32,7 +32,7 @@ abstract class BaseAccept /** * @param string $value */ - public function __construct($value) + public function __construct(string $value) { list($type, $parameters) = $this->parseParameters($value); @@ -52,7 +52,7 @@ public function __construct($value) /** * @return string */ - public function getNormalizedValue() + public function getNormalizedValue(): string { return $this->normalized; } @@ -60,7 +60,7 @@ public function getNormalizedValue() /** * @return string */ - public function getValue() + public function getValue(): string { return $this->value; } @@ -68,7 +68,7 @@ public function getValue() /** * @return string */ - public function getType() + public function getType(): string { return $this->type; } @@ -76,7 +76,7 @@ public function getType() /** * @return float */ - public function getQuality() + public function getQuality(): float { return $this->quality; } @@ -84,7 +84,7 @@ public function getQuality() /** * @return array */ - public function getParameters() + public function getParameters(): array { return $this->parameters; } @@ -95,7 +95,7 @@ public function getParameters() * * @return string|null */ - public function getParameter($key, $default = null) + public function getParameter(string $key, $default = null): ?string { return isset($this->parameters[$key]) ? $this->parameters[$key] : $default; } @@ -105,7 +105,7 @@ public function getParameter($key, $default = null) * * @return boolean */ - public function hasParameter($key) + public function hasParameter(string $key): bool { return isset($this->parameters[$key]); } @@ -115,7 +115,7 @@ public function hasParameter($key) * @param string $acceptPart * @return array */ - private function parseParameters($acceptPart) + private function parseParameters(string $acceptPart): array { $parts = explode(';', $acceptPart); $type = array_shift($parts); @@ -140,7 +140,7 @@ private function parseParameters($acceptPart) * * @return string */ - private function buildParametersString($parameters) + private function buildParametersString($parameters): string { $parts = []; From baafa3ba203eef612134769b1f50b60dd1034e75 Mon Sep 17 00:00:00 2001 From: AzJezz Date: Sun, 8 Apr 2018 11:38:28 +0100 Subject: [PATCH 04/10] Update CharsetNegotiator.php --- src/Negotiation/CharsetNegotiator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Negotiation/CharsetNegotiator.php b/src/Negotiation/CharsetNegotiator.php index c1f9a4b..7c110ef 100644 --- a/src/Negotiation/CharsetNegotiator.php +++ b/src/Negotiation/CharsetNegotiator.php @@ -7,7 +7,7 @@ class CharsetNegotiator extends AbstractNegotiator /** * {@inheritdoc} */ - protected function acceptFactory($accept) + protected function acceptFactory($accept): AcceptCharset { return new AcceptCharset($accept); } From c45b6cec871c6709d1aaf817d4919b02adf2aa1e Mon Sep 17 00:00:00 2001 From: AzJezz Date: Sun, 8 Apr 2018 11:38:55 +0100 Subject: [PATCH 05/10] Update EncodingNegotiator.php --- src/Negotiation/EncodingNegotiator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Negotiation/EncodingNegotiator.php b/src/Negotiation/EncodingNegotiator.php index 6b97fb7..3344dda 100644 --- a/src/Negotiation/EncodingNegotiator.php +++ b/src/Negotiation/EncodingNegotiator.php @@ -7,7 +7,7 @@ class EncodingNegotiator extends AbstractNegotiator /** * {@inheritdoc} */ - protected function acceptFactory($accept) + protected function acceptFactory($accept): AcceptEncoding { return new AcceptEncoding($accept); } From 99b0907a9a69a2d39799d9a4c9cba01c89f499ea Mon Sep 17 00:00:00 2001 From: AzJezz Date: Sun, 8 Apr 2018 11:39:27 +0100 Subject: [PATCH 06/10] Update LanguageNegotiator.php --- src/Negotiation/LanguageNegotiator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Negotiation/LanguageNegotiator.php b/src/Negotiation/LanguageNegotiator.php index ac93814..7ab0ffd 100644 --- a/src/Negotiation/LanguageNegotiator.php +++ b/src/Negotiation/LanguageNegotiator.php @@ -7,7 +7,7 @@ class LanguageNegotiator extends AbstractNegotiator /** * {@inheritdoc} */ - protected function acceptFactory($accept) + protected function acceptFactory($accept): AccepLanguage { return new AcceptLanguage($accept); } @@ -15,7 +15,7 @@ protected function acceptFactory($accept) /** * {@inheritdoc} */ - protected function match(AcceptHeader $acceptLanguage, AcceptHeader $priority, $index) + protected function match(AcceptHeader $acceptLanguage, AcceptHeader $priority, $index): ?Match { if (!$acceptLanguage instanceof AcceptLanguage || !$priority instanceof AcceptLanguage) { return null; From bb51444112992fbf7e92073c7feffd45f7da7df1 Mon Sep 17 00:00:00 2001 From: AzJezz Date: Sun, 8 Apr 2018 11:39:57 +0100 Subject: [PATCH 07/10] Update Match.php --- src/Negotiation/Match.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Negotiation/Match.php b/src/Negotiation/Match.php index 5b0e014..0300ec3 100644 --- a/src/Negotiation/Match.php +++ b/src/Negotiation/Match.php @@ -51,7 +51,7 @@ public static function compare(Match $a, Match $b) * * @return Match[] */ - public static function reduce(array $carry, Match $match) + public static function reduce(array $carry, Match $match): array { if (!isset($carry[$match->index]) || $carry[$match->index]->score < $match->score) { $carry[$match->index] = $match; From 755c1f89eb4cc0608fc20ed4754d9bc49361c4ee Mon Sep 17 00:00:00 2001 From: AzJezz Date: Sun, 8 Apr 2018 11:40:36 +0100 Subject: [PATCH 08/10] Update Negotiator.php --- src/Negotiation/Negotiator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Negotiation/Negotiator.php b/src/Negotiation/Negotiator.php index d083fa1..cf3a86f 100644 --- a/src/Negotiation/Negotiator.php +++ b/src/Negotiation/Negotiator.php @@ -7,7 +7,7 @@ class Negotiator extends AbstractNegotiator /** * {@inheritdoc} */ - protected function acceptFactory($accept) + protected function acceptFactory($accept): Accept { return new Accept($accept); } @@ -15,7 +15,7 @@ protected function acceptFactory($accept) /** * {@inheritdoc} */ - protected function match(AcceptHeader $accept, AcceptHeader $priority, $index) + protected function match(AcceptHeader $accept, AcceptHeader $priority, $index): Match { if (!$accept instanceof Accept || !$priority instanceof Accept) { return null; @@ -78,7 +78,7 @@ protected function match(AcceptHeader $accept, AcceptHeader $priority, $index) * should allow wildcards for either the portion before the "+" or * after. This method splits the subpart to allow such matching. */ - protected function splitSubPart($subPart) + protected function splitSubPart($subPart): array { if (!strstr($subPart, '+')) { return [$subPart, '']; From c4a61b643398114000c807aa6626c86c3d3698a6 Mon Sep 17 00:00:00 2001 From: AzJezz Date: Sun, 8 Apr 2018 11:40:52 +0100 Subject: [PATCH 09/10] Update Negotiator.php --- src/Negotiation/Negotiator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Negotiation/Negotiator.php b/src/Negotiation/Negotiator.php index cf3a86f..f6ae1fe 100644 --- a/src/Negotiation/Negotiator.php +++ b/src/Negotiation/Negotiator.php @@ -15,7 +15,7 @@ protected function acceptFactory($accept): Accept /** * {@inheritdoc} */ - protected function match(AcceptHeader $accept, AcceptHeader $priority, $index): Match + protected function match(AcceptHeader $accept, AcceptHeader $priority, $index): ?Match { if (!$accept instanceof Accept || !$priority instanceof Accept) { return null; From 40ca57863365d69598d1ee56168113adf81b58f7 Mon Sep 17 00:00:00 2001 From: AzJezz Date: Sun, 8 Apr 2018 11:41:41 +0100 Subject: [PATCH 10/10] Update AbstractNegotiator.php --- src/Negotiation/AbstractNegotiator.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Negotiation/AbstractNegotiator.php b/src/Negotiation/AbstractNegotiator.php index 669941e..2511a30 100644 --- a/src/Negotiation/AbstractNegotiator.php +++ b/src/Negotiation/AbstractNegotiator.php @@ -13,7 +13,7 @@ abstract class AbstractNegotiator * * @return AcceptHeader|null best matching type */ - public function getBest($header, array $priorities, $strict = false) + public function getBest($header, array $priorities, $strict = false): ?AcceptHeader { if (empty($priorities)) { throw new InvalidArgument('A set of server priorities should be given.'); @@ -57,7 +57,7 @@ public function getBest($header, array $priorities, $strict = false) * * @return [AcceptHeader] An ordered list of accept header elements */ - public function getOrderedElements($header) + public function getOrderedElements($header): array { if (!$header) { throw new InvalidArgument('The header string should not be empty.'); @@ -111,7 +111,7 @@ abstract protected function acceptFactory($header); * * @return Match|null Headers matched */ - protected function match(AcceptHeader $header, AcceptHeader $priority, $index) + protected function match(AcceptHeader $header, AcceptHeader $priority, $index): ?Match { $ac = $header->getType(); $pc = $priority->getType(); @@ -132,7 +132,7 @@ protected function match(AcceptHeader $header, AcceptHeader $priority, $index) * * @return AcceptHeader[] */ - private function parseHeader($header) + private function parseHeader($header): array { $res = preg_match_all('/(?:[^,"]*+(?:"[^"]*+")?)+[^,"]*+/', $header, $matches); @@ -149,7 +149,7 @@ private function parseHeader($header) * * @return Match[] Headers matched */ - private function findMatches(array $headerParts, array $priorities) + private function findMatches(array $headerParts, array $priorities): array { $matches = []; foreach ($priorities as $index => $p) {