Skip to content

Commit 9fb7649

Browse files
authored
Added CacheInterface.stubphp from symfony contracts (#74)
1 parent 898d580 commit 9fb7649

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"require-dev": {
1919
"doctrine/orm": "^2.7",
2020
"phpunit/phpunit": "~7.5",
21+
"symfony/cache-contracts": "^1.0 || ^2.0",
2122
"symfony/console": "*",
2223
"symfony/messenger": "^4.2 || ^5.0",
2324
"symfony/security-guard": "^4.0 || ^5.0",
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+
interface CacheInterface
8+
{
9+
/**
10+
* @template T
11+
*
12+
* @psalm-param CallbackInterface|callable(CacheItemInterface, bool): T $callback
13+
* @psalm-return T
14+
*/
15+
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null);
16+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@symfony-common
2+
Feature: CacheInterface
3+
4+
Background:
5+
Given I have the following config
6+
"""
7+
<?xml version="1.0"?>
8+
<psalm errorLevel="1">
9+
<projectFiles>
10+
<directory name="."/>
11+
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
12+
</projectFiles>
13+
14+
<plugins>
15+
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
16+
</plugins>
17+
</psalm>
18+
"""
19+
20+
Scenario: CacheInterface::get has the same return type as the passed callback
21+
Given I have the following code
22+
"""
23+
<?php
24+
25+
use Psr\Cache\CacheItemInterface;
26+
use Symfony\Contracts\Cache\CacheInterface;
27+
28+
function test(CacheInterface $cache): stdClass
29+
{
30+
return $cache->get('key', function (CacheItemInterface $item, bool &$save): stdClass {
31+
return new stdClass();
32+
});
33+
}
34+
35+
"""
36+
When I run Psalm
37+
Then I see no errors

0 commit comments

Comments
 (0)