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

Appearance settings

[Config] Add more type-hints as follow-up of #32201 #32287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
6 changes: 1 addition & 5 deletions 6 src/Symfony/Component/Config/ConfigCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ public function __construct(bool $debug)
/**
* {@inheritdoc}
*/
public function cache(string $file, $callback)
public function cache(string $file, callable $callback)
{
if (!\is_callable($callback)) {
throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', \gettype($callback)));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the callable type-hint we will get a TypeError now. So no need to check the argument anymore.


$cache = new ConfigCache($file, $this->debug);
if (!$cache->isFresh()) {
$callback($cache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ interface ConfigCacheFactoryInterface
*
* @return ConfigCacheInterface The cache instance
*/
public function cache(string $file, $callable);
public function cache(string $file, callable $callable);
}
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Config/Definition/ArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function setAllowNewKeys(bool $allow)
*/
public function setPerformDeepMerging(bool $boolean)
{
$this->performDeepMerging = (bool) $boolean;
$this->performDeepMerging = $boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ interface PrototypeNodeInterface extends NodeInterface
{
/**
* Sets the name of the node.
*
* @param string $name The name of the node
*/
public function setName(string $name);
}
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Config/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct($paths = [])
/**
* {@inheritdoc}
*/
public function locate(string $name, string $currentPath = null, $first = true)
public function locate(string $name, string $currentPath = null, bool $first = true)
{
if ('' == $name) {
throw new \InvalidArgumentException('An empty file name is not valid to be located.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ public function __construct(iterable $resourceCheckers = [])
/**
* {@inheritdoc}
*/
public function cache(string $file, $callback)
public function cache(string $file, callable $callback)
{
if (!\is_callable($callback)) {
throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', \gettype($callback)));
}

$cache = new ResourceCheckerConfigCache($file, $this->resourceCheckers);
if (!$cache->isFresh()) {
$callback($cache);
Expand Down
13 changes: 7 additions & 6 deletions 13 src/Symfony/Component/Config/Tests/ConfigCacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\ConfigCacheFactory;
use Symfony\Component\Config\ConfigCacheInterface;

class ConfigCacheFactoryTest extends TestCase
{
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid type for callback argument. Expected callable, but got "object".
*/
public function testCacheWithInvalidCallback()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test didn't make sense anymore, thanks to the callable type-hint of the callback argument.

public function testCanCreateCache()
{
$cacheFactory = new ConfigCacheFactory(true);

$cacheFactory->cache('file', new \stdClass());
$cache = $cacheFactory->cache('file', function (ConfigCacheInterface $cache) {
return;
});

$this->assertInstanceOf(ConfigCacheInterface::class, $cache);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.