From dbbc60e6b99b53be38d43ec11c68fd2a81abd7b0 Mon Sep 17 00:00:00 2001 From: Mark Olree <55830693+YspMark@users.noreply.github.com> Date: Mon, 17 Jan 2022 16:40:03 +0100 Subject: [PATCH 1/7] Added CacheInterface stub --- extension.neon | 1 + stubs/Contracts/Cache/CacheInterface.stub | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 stubs/Contracts/Cache/CacheInterface.stub diff --git a/extension.neon b/extension.neon index 23008e5d..6c990e1e 100644 --- a/extension.neon +++ b/extension.neon @@ -51,6 +51,7 @@ 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/Twig/Node/Node.stub parametersSchema: diff --git a/stubs/Contracts/Cache/CacheInterface.stub b/stubs/Contracts/Cache/CacheInterface.stub new file mode 100644 index 00000000..e5919ed4 --- /dev/null +++ b/stubs/Contracts/Cache/CacheInterface.stub @@ -0,0 +1,14 @@ + Date: Mon, 17 Jan 2022 16:46:42 +0100 Subject: [PATCH 2/7] Added CacheInterface stub --- stubs/{ => Symfony}/Contracts/Cache/CacheInterface.stub | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename stubs/{ => Symfony}/Contracts/Cache/CacheInterface.stub (100%) diff --git a/stubs/Contracts/Cache/CacheInterface.stub b/stubs/Symfony/Contracts/Cache/CacheInterface.stub similarity index 100% rename from stubs/Contracts/Cache/CacheInterface.stub rename to stubs/Symfony/Contracts/Cache/CacheInterface.stub From 64f6c625c5d4c11dc3a5cc15f86771e18b640013 Mon Sep 17 00:00:00 2001 From: Mark Olree <55830693+YspMark@users.noreply.github.com> Date: Tue, 18 Jan 2022 10:10:14 +0100 Subject: [PATCH 3/7] Extended with the CallbackInterface $callback param type --- extension.neon | 1 + .../Symfony/Contracts/Cache/CacheInterface.stub | 5 +++-- .../Contracts/Cache/CallbackInterface.stub | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 stubs/Symfony/Contracts/Cache/CallbackInterface.stub diff --git a/extension.neon b/extension.neon index 6c990e1e..fb09086d 100644 --- a/extension.neon +++ b/extension.neon @@ -52,6 +52,7 @@ parameters: - 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/Twig/Node/Node.stub parametersSchema: diff --git a/stubs/Symfony/Contracts/Cache/CacheInterface.stub b/stubs/Symfony/Contracts/Cache/CacheInterface.stub index e5919ed4..ddc24c2d 100644 --- a/stubs/Symfony/Contracts/Cache/CacheInterface.stub +++ b/stubs/Symfony/Contracts/Cache/CacheInterface.stub @@ -2,12 +2,13 @@ namespace Symfony\Contracts\Cache; -class CacheInterface +interface CacheInterface { /** * @template T * - * @param callable:T $callback + * @param \Symfony\Contracts\Cache\CallbackInterface|callable(\Psr\Cache\CacheItemInterface): 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 @@ + Date: Tue, 18 Jan 2022 12:48:21 +0100 Subject: [PATCH 4/7] Added CacheItemInterface, fixed optional = notation --- extension.neon | 1 + stubs/Psr/Cache/CacheItemInterface.stub | 7 +++++++ stubs/Symfony/Contracts/Cache/CacheInterface.stub | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 stubs/Psr/Cache/CacheItemInterface.stub diff --git a/extension.neon b/extension.neon index fb09086d..11636d77 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 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(\Psr\Cache\CacheItemInterface): T $callback + * @param \Symfony\Contracts\Cache\CallbackInterface|callable(\Psr\Cache\CacheItemInterface=): T $callback * @param array $metadata * @return T */ From 19ccb0f54f6f828a00cd3e5af34beaf51c763698 Mon Sep 17 00:00:00 2001 From: Mark Olree <55830693+YspMark@users.noreply.github.com> Date: Tue, 18 Jan 2022 15:53:44 +0100 Subject: [PATCH 5/7] Added CacheInterface test --- tests/Type/Symfony/ExtensionTest.php | 5 +++++ .../Type/Symfony/data/ExampleCacheInterface.php | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/Type/Symfony/data/ExampleCacheInterface.php diff --git a/tests/Type/Symfony/ExtensionTest.php b/tests/Type/Symfony/ExtensionTest.php index 61d354da..01a9bbb2 100644 --- a/tests/Type/Symfony/ExtensionTest.php +++ b/tests/Type/Symfony/ExtensionTest.php @@ -20,6 +20,11 @@ public function dataFileAsserts(): iterable } yield from $this->gatherAssertTypes(__DIR__ . '/data/tree_builder.php'); + + if (interface_exists('\Symfony\Contracts\Cache\CacheInterface')) { + yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleCacheInterface.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'); diff --git a/tests/Type/Symfony/data/ExampleCacheInterface.php b/tests/Type/Symfony/data/ExampleCacheInterface.php new file mode 100644 index 00000000..2dbfb18d --- /dev/null +++ b/tests/Type/Symfony/data/ExampleCacheInterface.php @@ -0,0 +1,17 @@ +get('cacheTest', $callbackCallable)); From 653d3341f0675d77b5a1c9d43d01ad6092961bfe Mon Sep 17 00:00:00 2001 From: Mark Olree <55830693+YspMark@users.noreply.github.com> Date: Tue, 18 Jan 2022 16:41:42 +0100 Subject: [PATCH 6/7] Changed to Symfony ItemInterface on CacheInterface --- extension.neon | 1 + stubs/Symfony/Contracts/Cache/CacheInterface.stub | 2 +- stubs/Symfony/Contracts/Cache/ItemInterface.stub | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 stubs/Symfony/Contracts/Cache/ItemInterface.stub diff --git a/extension.neon b/extension.neon index 11636d77..4870f24c 100644 --- a/extension.neon +++ b/extension.neon @@ -54,6 +54,7 @@ parameters: - 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/Symfony/Contracts/Cache/CacheInterface.stub b/stubs/Symfony/Contracts/Cache/CacheInterface.stub index 39e168fb..4b98f533 100644 --- a/stubs/Symfony/Contracts/Cache/CacheInterface.stub +++ b/stubs/Symfony/Contracts/Cache/CacheInterface.stub @@ -7,7 +7,7 @@ interface CacheInterface /** * @template T * - * @param \Symfony\Contracts\Cache\CallbackInterface|callable(\Psr\Cache\CacheItemInterface=): T $callback + * @param \Symfony\Contracts\Cache\CallbackInterface|callable(\Symfony\Contracts\Cache\ItemInterface): T $callback * @param array $metadata * @return T */ diff --git a/stubs/Symfony/Contracts/Cache/ItemInterface.stub b/stubs/Symfony/Contracts/Cache/ItemInterface.stub new file mode 100644 index 00000000..cb3982bb --- /dev/null +++ b/stubs/Symfony/Contracts/Cache/ItemInterface.stub @@ -0,0 +1,9 @@ + Date: Tue, 18 Jan 2022 16:42:24 +0100 Subject: [PATCH 7/7] Replaced test with more extensive one on both callbacks --- tests/Type/Symfony/ExtensionTest.php | 5 +---- .../Symfony/data/ExampleCacheInterface.php | 17 -------------- tests/Type/Symfony/data/cache.php | 22 +++++++++++++++++++ 3 files changed, 23 insertions(+), 21 deletions(-) delete mode 100644 tests/Type/Symfony/data/ExampleCacheInterface.php create mode 100644 tests/Type/Symfony/data/cache.php diff --git a/tests/Type/Symfony/ExtensionTest.php b/tests/Type/Symfony/ExtensionTest.php index 01a9bbb2..5da566b1 100644 --- a/tests/Type/Symfony/ExtensionTest.php +++ b/tests/Type/Symfony/ExtensionTest.php @@ -21,10 +21,6 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/tree_builder.php'); - if (interface_exists('\Symfony\Contracts\Cache\CacheInterface')) { - yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleCacheInterface.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'); @@ -56,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/ExampleCacheInterface.php b/tests/Type/Symfony/data/ExampleCacheInterface.php deleted file mode 100644 index 2dbfb18d..00000000 --- a/tests/Type/Symfony/data/ExampleCacheInterface.php +++ /dev/null @@ -1,17 +0,0 @@ -get('cacheTest', $callbackCallable)); 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); +};