Fix issues detected by Psalm

This commit is contained in:
PJ Dietz 2020-08-08 12:05:33 -04:00
parent 2cf65def5c
commit 08ddb0aa2f
6 changed files with 26 additions and 23 deletions

View File

@ -26,7 +26,7 @@ class DispatchStack implements DispatchStackInterface
* Push a new middleware onto the stack. * Push a new middleware onto the stack.
* *
* @param mixed $middleware Middleware to dispatch in sequence * @param mixed $middleware Middleware to dispatch in sequence
* @return self * @return static
*/ */
public function add($middleware) public function add($middleware)
{ {

View File

@ -101,7 +101,7 @@ abstract class Message implements MessageInterface
* While header names are not case-sensitive, getHeaders() will preserve the * While header names are not case-sensitive, getHeaders() will preserve the
* exact case in which headers were originally specified. * exact case in which headers were originally specified.
* *
* @return array Returns an associative array of the message's headers. * @return string[][] Returns an associative array of the message's headers.
*/ */
public function getHeaders() public function getHeaders()
{ {

View File

@ -51,9 +51,10 @@ class NullStream implements StreamInterface
} }
/** /**
* Returns 0 * Returns the current position of the file read/write pointer
* *
* @return int|bool Position of the file pointer or false on error. * @return int Position of the file pointer
* @throws \RuntimeException on error.
*/ */
public function tell() public function tell()
{ {

View File

@ -212,7 +212,7 @@ class Request extends Message implements RequestInterface
/** /**
* @param string $method * @param string $method
* @return static * @return string
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
private function getValidatedMethod($method) private function getValidatedMethod($method)

View File

@ -67,7 +67,9 @@ class Stream implements StreamInterface
*/ */
public function close() public function close()
{ {
fclose($this->resource); $resource = $this->resource;
fclose($resource);
$this->resource = null;
} }
/** /**
@ -79,9 +81,9 @@ class Stream implements StreamInterface
*/ */
public function detach() public function detach()
{ {
$stream = $this->resource; $resource = $this->resource;
$this->resource = null; $this->resource = null;
return $stream; return $resource;
} }
/** /**

View File

@ -203,7 +203,7 @@ class Router
} }
/** /**
* @param DispatcherInterface * @param DispatcherInterface $dispatcher
* @return RouteFactoryInterface * @return RouteFactoryInterface
*/ */
protected function getRouteFactory($dispatcher) protected function getRouteFactory($dispatcher)
@ -266,21 +266,21 @@ class Router
} }
); );
if ($matches) { if (!$matches) {
if (count($matches) > 0) { return null;
// If there are multiple matches, sort them to find the one with
// the longest string length.
$compareByLength = function ($a, $b) {
return strlen($b) - strlen($a);
};
usort($matches, $compareByLength);
}
/** @var string $bestMatch */
$bestMatch = $matches[0];
$route = $this->prefixRoutes[$bestMatch];
return $route;
} }
return null;
// If there are multiple matches, sort them to find the one with the
// longest string length.
if (count($matches) > 1) {
$compareByLength = function ($a, $b) {
return strlen($b) - strlen($a);
};
usort($matches, $compareByLength);
}
$bestMatch = $matches[0];
return $this->prefixRoutes[$bestMatch];
} }
private function startsWith($haystack, $needle) private function startsWith($haystack, $needle)