diff --git a/extension.neon b/extension.neon index 23008e5d..4870f24c 100644 --- a/extension.neon +++ b/extension.neon @@ -12,6 +12,7 @@ parameters: console_application_loader: null consoleApplicationLoader: null stubFiles: + - stubs/Psr/Cache/CacheItemInterface.stub - stubs/Symfony/Bundle/FrameworkBundle/KernelBrowser.stub - stubs/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.stub - stubs/Symfony/Bundle/FrameworkBundle/Test/TestContainer.stub @@ -51,6 +52,9 @@ parameters: - stubs/Symfony/Component/Validator/Constraint.stub - stubs/Symfony/Component/Validator/ConstraintViolationInterface.stub - stubs/Symfony/Component/Validator/ConstraintViolationListInterface.stub + - stubs/Symfony/Contracts/Cache/CacheInterface.stub + - stubs/Symfony/Contracts/Cache/CallbackInterface.stub + - stubs/Symfony/Contracts/Cache/ItemInterface.stub - stubs/Twig/Node/Node.stub parametersSchema: diff --git a/stubs/Psr/Cache/CacheItemInterface.stub b/stubs/Psr/Cache/CacheItemInterface.stub new file mode 100644 index 00000000..f595213d --- /dev/null +++ b/stubs/Psr/Cache/CacheItemInterface.stub @@ -0,0 +1,7 @@ +|callable(\Symfony\Contracts\Cache\ItemInterface): T $callback + * @param array $metadata + * @return T + */ + public function get(string $key, callable $callback, float $beta = null, array &$metadata = null); +} diff --git a/stubs/Symfony/Contracts/Cache/CallbackInterface.stub b/stubs/Symfony/Contracts/Cache/CallbackInterface.stub new file mode 100644 index 00000000..9b5a6e1a --- /dev/null +++ b/stubs/Symfony/Contracts/Cache/CallbackInterface.stub @@ -0,0 +1,16 @@ +gatherAssertTypes(__DIR__ . '/data/tree_builder.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleBaseCommand.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleOptionCommand.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleOptionLazyCommand.php'); @@ -51,6 +52,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/denormalizer.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/FormInterface_getErrors.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/cache.php'); } /** diff --git a/tests/Type/Symfony/data/cache.php b/tests/Type/Symfony/data/cache.php new file mode 100644 index 00000000..6b0728d4 --- /dev/null +++ b/tests/Type/Symfony/data/cache.php @@ -0,0 +1,22 @@ +get('foo', function (): string { + return ''; + }); + + assertType('string', $result); +}; + +/** + * @param \Symfony\Contracts\Cache\CallbackInterface<\stdClass> $cb + */ + function testCacheCallbackInterface(\Symfony\Contracts\Cache\CacheInterface $cache, \Symfony\Contracts\Cache\CallbackInterface $cb): void { + $result = $cache->get('foo',$cb); + + assertType('stdClass', $result); +};