Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 96ee630

Browse files
authored
Added CacheInterface stub
1 parent 2e25964 commit 96ee630

File tree

7 files changed

+75
-0
lines changed

7 files changed

+75
-0
lines changed

‎extension.neon‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ parameters:
1212
console_application_loader: null
1313
consoleApplicationLoader: null
1414
stubFiles:
15+
- stubs/Psr/Cache/CacheItemInterface.stub
1516
- stubs/Symfony/Bundle/FrameworkBundle/KernelBrowser.stub
1617
- stubs/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.stub
1718
- stubs/Symfony/Bundle/FrameworkBundle/Test/TestContainer.stub
@@ -51,6 +52,9 @@ parameters:
5152
- stubs/Symfony/Component/Validator/Constraint.stub
5253
- stubs/Symfony/Component/Validator/ConstraintViolationInterface.stub
5354
- stubs/Symfony/Component/Validator/ConstraintViolationListInterface.stub
55+
- stubs/Symfony/Contracts/Cache/CacheInterface.stub
56+
- stubs/Symfony/Contracts/Cache/CallbackInterface.stub
57+
- stubs/Symfony/Contracts/Cache/ItemInterface.stub
5458
- stubs/Twig/Node/Node.stub
5559

5660
parametersSchema:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Psr\Cache;
4+
5+
interface CacheItemInterface
6+
{
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Symfony\Contracts\Cache;
4+
5+
interface CacheInterface
6+
{
7+
/**
8+
* @template T
9+
*
10+
* @param \Symfony\Contracts\Cache\CallbackInterface<T>|callable(\Symfony\Contracts\Cache\ItemInterface): T $callback
11+
* @param array<mixed> $metadata
12+
* @return T
13+
*/
14+
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null);
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Symfony\Contracts\Cache;
4+
5+
use Psr\Cache\CacheItemInterface;
6+
7+
/**
8+
* @template T
9+
*/
10+
interface CallbackInterface
11+
{
12+
/**
13+
* @return T
14+
*/
15+
public function __invoke(CacheItemInterface $item, bool &$save);
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Symfony\Contracts\Cache;
4+
5+
use Psr\Cache\CacheItemInterface;
6+
7+
interface ItemInterface extends CacheItemInterface
8+
{
9+
}

‎tests/Type/Symfony/ExtensionTest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function dataFileAsserts(): iterable
2020
}
2121

2222
yield from $this->gatherAssertTypes(__DIR__ . '/data/tree_builder.php');
23+
2324
yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleBaseCommand.php');
2425
yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleOptionCommand.php');
2526
yield from $this->gatherAssertTypes(__DIR__ . '/data/ExampleOptionLazyCommand.php');
@@ -51,6 +52,7 @@ public function dataFileAsserts(): iterable
5152
yield from $this->gatherAssertTypes(__DIR__ . '/data/denormalizer.php');
5253

5354
yield from $this->gatherAssertTypes(__DIR__ . '/data/FormInterface_getErrors.php');
55+
yield from $this->gatherAssertTypes(__DIR__ . '/data/cache.php');
5456
}
5557

5658
/**

‎tests/Type/Symfony/data/cache.php‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Symfony\cache;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function testCacheCallable(\Symfony\Contracts\Cache\CacheInterface $cache): void {
8+
$result = $cache->get('foo', function (): string {
9+
return '';
10+
});
11+
12+
assertType('string', $result);
13+
};
14+
15+
/**
16+
* @param \Symfony\Contracts\Cache\CallbackInterface<\stdClass> $cb
17+
*/
18+
function testCacheCallbackInterface(\Symfony\Contracts\Cache\CacheInterface $cache, \Symfony\Contracts\Cache\CallbackInterface $cb): void {
19+
$result = $cache->get('foo',$cb);
20+
21+
assertType('stdClass', $result);
22+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /