mirror of
https://github.com/danog/psalm-plugin-symfony.git
synced 2024-11-30 04:29:10 +01:00
conditional returns & request stub (#23)
This commit is contained in:
parent
446a6fb2d0
commit
b81d92542e
@ -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": {
|
||||
|
@ -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) {
|
||||
|
@ -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
21
src/Stubs/Request.stubphp
Normal 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) {}
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user