Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some static code analyse errors with PHPStan level 1 #2522

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Slim/Middleware/MethodOverrideMiddleware.php
Expand Up @@ -39,7 +39,7 @@ public function __invoke(
} elseif (strtoupper($request->getMethod()) == 'POST') {
$body = $request->getParsedBody();

if (!empty($body['_METHOD'])) {
if ((is_array($body) || $body instanceof \ArrayAccess) && !empty($body['_METHOD'])) {
$request = $request->withMethod($body['_METHOD']);
}

Expand Down
5 changes: 4 additions & 1 deletion Slim/Router.php
Expand Up @@ -419,7 +419,10 @@ public function relativePathFor(string $name, array $data = [], array $queryPara
}

if (empty($segments)) {
throw new InvalidArgumentException('Missing data for URL segment: ' . $segmentName);
if (isset($segmentName)) {
throw new InvalidArgumentException('Missing data for URL segment: ' . $segmentName);
}
throw new InvalidArgumentException(sprintf('Missing RouteData for URL with name: "%s"', $name));
}
$url = implode('', $segments);

Expand Down
7 changes: 4 additions & 3 deletions tests/Middleware/ContentLengthMiddlewareTest.php
Expand Up @@ -22,7 +22,7 @@ class ContentLengthMiddlewareTest extends TestCase
{
public function testAddsContentLenght()
{
$mw = new ContentLengthMiddleware('append');
$mw = new ContentLengthMiddleware();

$uri = Uri::createFromString('https://example.com:443/foo/bar?abc=123');
$headers = new Headers();
Expand All @@ -33,8 +33,9 @@ public function testAddsContentLenght()
$response = new Response();

$next = function (ServerRequestInterface $req, ResponseInterface $res) {
$res->write('Body');
return $res;
$body = $res->getBody();
$body->write('Body');
return $res->withBody($body);
};

$newResponse = $mw($request, $response, $next);
Expand Down
12 changes: 6 additions & 6 deletions tests/Middleware/OutputBufferingMiddlewareTest.php
Expand Up @@ -55,10 +55,10 @@ public function testAppend()
$response = new Response();

$next = function (ServerRequestInterface $req, ResponseInterface $res) {
$res->write('Body');
$body = $res->getBody();
$body->write('Body');
echo 'Test';

return $res;
return $res->withBody($body);
};
$result = $mw($request, $response, $next);

Expand All @@ -78,10 +78,10 @@ public function testPrepend()
$response = new Response();

$next = function (ServerRequestInterface $req, ResponseInterface $res) {
$res->write('Body');
$body = $res->getBody();
$body->write('Body');
echo 'Test';

return $res;
return $res->withBody($body);
};
$result = $mw($request, $response, $next);

Expand Down