Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
};