8000 [Config] Add type-hints to public interfaces and classes by jschaedl · Pull Request #32201 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Config] Add type-hints to public interfaces and classes #32201

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

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

Choose a reason for hiding this comment

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

missing callable type

}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/ConfigCacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ public function isFresh();
*
* @throws \RuntimeException When the cache file cannot be written
*/
public function write($content, array $metadata = null);
public function write(string $content, array $metadata = null);
}
28 changes: 10 additions & 18 deletions src/Symfony/Component/Config/Definition/ArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,40 +102,32 @@ public function getXmlRemappings()
/**
* Sets whether to add default values for this array if it has not been
* defined in any of the configuration files.
*
* @param bool $boolean
*/
public function setAddIfNotSet($boolean)
public function setAddIfNotSet(bool $boolean)
{
$this->addIfNotSet = (bool) $boolean;
$this->addIfNotSet = $boolean;
}

/**
* Sets whether false is allowed as value indicating that the array should be unset.
*
* @param bool $allow
*/
public function setAllowFalse($allow)
public function setAllowFalse(bool $allow)
{
$this->allowFalse = (bool) $allow;
$this->allowFalse = $allow;
}

/**
* Sets whether new keys can be defined in subsequent configurations.
*
* @param bool $allow
*/
public function setAllowNewKeys($allow)
public function setAllowNewKeys(bool $allow)
{
$this->allowNewKeys = (bool) $allow;
$this->allowNewKeys = $allow;
}

/**
* Sets if deep merging should occur.
*
* @param bool $boolean
*/
public function setPerformDeepMerging($boolean)
public function setPerformDeepMerging(bool $boolean)
{
$this->performDeepMerging = (bool) $boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

forgotten cast

}
Expand All @@ -146,16 +138,16 @@ public function setPerformDeepMerging($boolean)
* @param bool $boolean To allow extra keys
* @param bool $remove To remove extra keys
*/
public function setIgnoreExtraKeys($boolean, $remove = true)
public function setIgnoreExtraKeys(bool $boolean, $remove = true)
{
$this->ignoreExtraKeys = (bool) $boolean;
$this->ignoreExtraKeys = $boolean;
$this->removeExtraKeys = $this->ignoreExtraKeys && $remove;
}

/**
* {@inheritdoc}
*/
public function setName($name)
public function setName(string $name)
{
$this->name = $name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ interface PrototypeNodeInterface extends NodeInterface
*
* @param string $name The name of the node
Copy link
Contributor

Choose a reason for hiding this comment

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

useless doc

*/
public function setName($name);
public function setName(string $name);
}
6 changes: 3 additions & 3 deletions src/Symfony/Component/Config/Definition/VariableNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public function getDefaultValue()
*
* @param bool $boolean True if this entity will accept empty values
*/
public function setAllowEmptyValue($boolean)
public function setAllowEmptyValue(bool $boolean)
{
$this->allowEmptyValue = (bool) $boolean;
$this->allowEmptyValue = $boolean;
}

/**
* {@inheritdoc}
*/
public function setName($name)
public function setName(string $name)
{
$this->name = $name;
}
Expand Down
4 changes: 2 additions & 2 deletions 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($name, $currentPath = null, $first = true)
public function locate(string $name, string $currentPath = null, $first = true)
Copy link
Contributor

Choose a reason for hiding this comment

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

forgotten bool

{
if ('' == $name) {
throw new \InvalidArgumentException('An empty file name is not valid to be located.');
Expand Down Expand Up @@ -81,7 +81,7 @@ public function locate($name, $currentPath = null, $first = true)
*
* @return bool
*/
private function isAbsolutePath($file)
private function isAbsolutePath(string $file)
{
if ('/' === $file[0] || '\\' === $file[0]
|| (\strlen($file) > 3 && ctype_alpha($file[0])
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/FileLocatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ interface FileLocatorInterface
* @throws \InvalidArgumentException If $name is empty
* @throws FileLocatorFileNotFoundException If a file is not found
*/
public function locate($name, $currentPath = null, $first = true);
public function locate(string $name, string $currentPath = null, bool $first = true);
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Config/Loader/DelegatingLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(LoaderResolverInterface $resolver)
/**
* {@inheritdoc}
*/
public function load($resource, $type = null)
public function load($resource, string $type = null)
{
if (false === $loader = $this->resolver->resolve($resource, $type)) {
throw new LoaderLoadException($resource, null, null, null, $type);
Expand All @@ -43,7 +43,7 @@ public function load($resource, $type = null)
/**
* {@inheritdoc}
*/
public function supports($resource, $type = null)
public function supports($resource, string $type = null)
{
return false !== $this->resolver->resolve($resource, $type);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Config/Loader/GlobFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class GlobFileLoader extends FileLoader
/**
* {@inheritdoc}
*/
public function load($resource, $type = null)
public function load($resource, string $type = null)
{
return $this->import($resource);
}

/**
* {@inheritdoc}
*/
public function supports($resource, $type = null)
public function supports($resource, string $type = null)
{
return 'glob' === $type;
}
Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Component/Config/Loader/LoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@ interface LoaderInterface
/**
* Loads a resource.
*
* @param mixed $resource The resource
* @param string|null $type The resource type or null if unknown
* @param mixed $resource The resource
*
* @throws \Exception If something went wrong
*/
public function load($resource, $type = null);
public function load($resource, string $type = null);

/**
* Returns whether this class supports the given resource.
*
* @param mixed $resource A resource
* @param string|null $type The resource type or null if unknown
* @param mixed $resource A resource
*
* @return bool True if this class supports the given resource, false otherwise
*/
public function supports($resource, $type = null);
public function supports($resource, string $type = null);

/**
* Gets the loader resolver.
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Loader/LoaderResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(array $loaders = [])
/**
* {@inheritdoc}
*/
public function resolve($resource, $type = null)
public function resolve($resource, string $type = null)
{
foreach ($this->loaders as $loader) {
if ($loader->supports($resource, $type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ interface LoaderResolverInterface
*
* @return LoaderInterface|false The loader or false if none is able to load the resource
*/
public function resolve($resource, $type = null);
public function resolve($resource, string $type = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function supports(ResourceInterface $metadata)
return $metadata instanceof SelfCheckingResourceInterface;
}

public function isFresh(ResourceInterface $resource, $timestamp)
public function isFresh(ResourceInterface $resource, int $timestamp)
{
/* @var SelfCheckingResourceInterface $resource */
return $resource->isFresh($timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function isFresh()
*
* @throws \RuntimeException When cache file can't be written
*/
public function write($content, array $metadata = null)
public function write(string $content, array $metadata = null)
{
$mode = 0666;
$umask = umask();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(iterable $resourceCheckers = [])
/**
* {@inheritdoc}
*/
public function cache($file, $callback)
public function cache(string $file, $callback)
{
if (!\is_callable($callback)) {
throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', \gettype($callback)));
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/ResourceCheckerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ public function supports(ResourceInterface $metadata);
*
* @return bool True if the resource has not changed since the given timestamp, false otherwise
*/
public function isFresh(ResourceInterface $resource, $timestamp);
public function isFresh(ResourceInterface $resource, int $timestamp);
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Tests/FileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ public function testLocateEmpty()
{
$loader = new FileLocator([__DIR__.'/Fixtures']);

$loader->locate(null, __DIR__);
$loader->locate('', __DIR__);
Copy link
Contributor Author
@jschaedl jschaedl Jun 28, 2019

Choose a reason for hiding this comment

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

This test expected an InvalidArgumentException but gets a TypeError now.

}
}
0