Skip to content

Commit

Permalink
Added CacheInterface stub
Browse files Browse the repository at this point in the history
  • Loading branch information
YspMark authored Jan 18, 2022
1 parent 2e25964 commit 96ee630
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions stubs/Psr/Cache/CacheItemInterface.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Psr\Cache;

interface CacheItemInterface
{
}
15 changes: 15 additions & 0 deletions stubs/Symfony/Contracts/Cache/CacheInterface.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Symfony\Contracts\Cache;

interface CacheInterface
{
/**
* @template T
*
* @param \Symfony\Contracts\Cache\CallbackInterface<T>|callable(\Symfony\Contracts\Cache\ItemInterface): T $callback
* @param array<mixed> $metadata
* @return T
*/
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null);
}
16 changes: 16 additions & 0 deletions stubs/Symfony/Contracts/Cache/CallbackInterface.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Symfony\Contracts\Cache;

use Psr\Cache\CacheItemInterface;

/**
* @template T
*/
interface CallbackInterface
{
/**
* @return T
*/
public function __invoke(CacheItemInterface $item, bool &$save);
}
9 changes: 9 additions & 0 deletions stubs/Symfony/Contracts/Cache/ItemInterface.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Symfony\Contracts\Cache;

use Psr\Cache\CacheItemInterface;

interface ItemInterface extends CacheItemInterface
{
}
2 changes: 2 additions & 0 deletions tests/Type/Symfony/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function dataFileAsserts(): iterable
}

yield from $this->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');
Expand Down Expand Up @@ -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');
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/Type/Symfony/data/cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace PHPStan\Type\Symfony\cache;

use function PHPStan\Testing\assertType;

function testCacheCallable(\Symfony\Contracts\Cache\CacheInterface $cache): void {
$result = $cache->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);
};

0 comments on commit 96ee630

Please sign in to comment.