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) { 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; } 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 = []; 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); } 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); } 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; 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; diff --git a/src/Negotiation/Negotiator.php b/src/Negotiation/Negotiator.php index d083fa1..f6ae1fe 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, ''];