conditional returns & request stub (#23)

This commit is contained in:
Farhad Safarov 2020-04-14 11:58:44 +03:00 committed by GitHub
parent 446a6fb2d0
commit b81d92542e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 11 deletions

View File

@ -12,7 +12,7 @@
"require": {
"php": "^7.1",
"ext-simplexml": "*",
"vimeo/psalm": "^3.7",
"vimeo/psalm": "^3.11",
"symfony/framework-bundle": "^3.0 || ^4.0 || ^5.0"
},
"require-dev": {

View File

@ -56,16 +56,6 @@ class ClassHandler implements AfterClassLikeAnalysisInterface, AfterMethodCallAn
Union &$return_type_candidate = null
) {
switch ($declaring_method_id) {
case 'Symfony\Component\HttpFoundation\Request::getcontent':
if ($return_type_candidate) {
$removeType = 'resource';
if (isset($expr->args[0]->value->name->parts[0])) {
/** @psalm-suppress MixedArrayAccess */
$removeType = 'true' === $expr->args[0]->value->name->parts[0] ? 'string' : 'resource';
}
$return_type_candidate->removeType($removeType);
}
break;
case 'Doctrine\ORM\EntityManagerInterface::getrepository':
case 'Doctrine\Persistence\ObjectManager::getrepository':
if (!$expr->args[0]->value instanceof ClassConstFetch) {

View File

@ -39,5 +39,9 @@ class Plugin implements PluginEntryPointInterface
} else {
$api->registerHooksFromClass(ContainerHandler::class);
}
foreach (glob(__DIR__ . '/Stubs/*.stubphp') as $stubFilePath) {
$api->addStubFile($stubFilePath);
}
}
}

21
src/Stubs/Request.stubphp Normal file
View File

@ -0,0 +1,21 @@
<?php
namespace Symfony\Component\HttpFoundation;
class Request
{
/**
* Returns the request body content.
*
* @param bool $asResource If true, a resource will be returned
*
* @throws \LogicException
*
* @psalm-return (
* $asResource is true
* ? resource
* : string
* )
*/
public function getContent($asResource = false) {}
}

View File

@ -72,3 +72,4 @@ Feature: Request getContent
Then I see these errors
| Type | Message |
| InvalidArgument | Argument 1 of json_decode expects string, resource provided |
And I see no other errors