8000 minor #32201 [Config] Add type-hints to public interfaces and classes… · symfony/symfony@7739849 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7739849

Browse files
committed
minor #32201 [Config] Add type-hints to public interfaces and classes (jschaedl)
This PR was squashed before being merged into the 5.0-dev branch (closes #32201). Discussion ---------- [Config] Add type-hints to public interfaces and classes | Q | A | ------------- | --- | Branch? | master <!-- see below --> | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #32179 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A <!-- required for new features --> This PR adds type hints to all public interfaces of the Config component. Commits ------- e069dc4 [Config] Add type-hints to public interfaces and classes
2 parents 7485b6f + e069dc4 commit 7739849

18 files changed

+35
-45
lines changed

src/Symfony/Component/Config/ConfigCacheFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(bool $debug)
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
public function cache($file, $callback)
38+
public function cache(string $file, $callback)
3939
{
4040
if (!\is_callable($callback)) {
4141
throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', \gettype($callback)));

src/Symfony/Component/Config/ConfigCacheFactoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ interface ConfigCacheFactoryInterface
2828
*
2929
* @return ConfigCacheInterface The cache instance
3030
*/
31-
public function cache($file, $callable);
31+
public function cache(string $file, $callable);
3232
}

src/Symfony/Component/Config/ConfigCacheInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ public function isFresh();
4545
*
4646
* @throws \RuntimeException When the cache file cannot be written
4747
*/
48-
public function write($content, array $metadata = null);
48+
public function write(string $content, array $metadata = null);
4949
}

src/Symfony/Component/Config/Definition/ArrayNode.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,40 +102,32 @@ public function getXmlRemappings()
102102
/**
103103
* Sets whether to add default values for this array if it has not been
104104
* defined in any of the configuration files.
105-
*
106-
* @param bool $boolean
107105
*/
108-
public function setAddIfNotSet($boolean)
106+
public function setAddIfNotSet(bool $boolean)
109107
{
110-
$this->addIfNotSet = (bool) $boolean;
108+
$this->addIfNotSet = $boolean;
111109
}
112110

113111
/**
114112
* Sets whether false is allowed as value indicating that the array should be unset.
115-
*
116-
* @param bool $allow
117113
*/
118-
public function setAllowFalse($allow)
114+
public function setAllowFalse(bool $allow)
119115
{
120-
$this->allowFalse = (bool) $allow;
116+
$this->allowFalse = $allow;
121117
}
122118

123119
/**
124120
* Sets whether new keys can be defined in subsequent configurations.
125-
*
126-
* @param bool $allow
127121
*/
128-
public function setAllowNewKeys($allow)
122+
public function setAllowNewKeys(bool $allow)
129123
{
130-
$this->allowNewKeys = (bool) $allow;
124+
$this->allowNewKeys = $allow;
131125
}
132126

133127
/**
134128
* Sets if deep merging should occur.
135-
*
136-
* @param bool $boolean
137129
*/
138-
public function setPerformDeepMerging($boolean)
130+
public function setPerformDeepMerging(bool $boolean)
139131
{
140132
$this->performDeepMerging = (bool) $boolean;
141133
}
@@ -146,16 +138,16 @@ public function setPerformDeepMerging($boolean)
146138
* @param bool $boolean To allow extra keys
147139
* @param bool $remove To remove extra keys
148140
*/
149-
public function setIgnoreExtraKeys($boolean, $remove = true)
141+
public function setIgnoreExtraKeys(bool $boolean, $remove = true)
150142
{
151-
$this->ignoreExtraKeys = (bool) $boolean;
143+
$this->ignoreExtraKeys = $boolean;
152144
$this->removeExtraKeys = $this->ignoreExtraKeys && $remove;
153145
}
154146

155147
/**
156148
* {@inheritdoc}
157149
*/
158-
public function setName($name)
150+
public function setName(string $name)
159151
{
160152
$this->name = $name;
161153
}

src/Symfony/Component/Config/Definition/PrototypeNodeInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ interface PrototypeNodeInterface extends NodeInterface
2323
*
2424
* @param string $name The name of the node
2525
*/
26-
public function setName($name);
26+
public function setName(string $name);
2727
}

src/Symfony/Component/Config/Definition/VariableNode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ public function getDefaultValue()
5656
*
5757
* @param bool $boolean True if this entity will accept empty values
5858
*/
59-
public function setAllowEmptyValue($boolean)
59+
public function setAllowEmptyValue(bool $boolean)
6060
{
61-
$this->allowEmptyValue = (bool) $boolean;
61+
$this->allowEmptyValue = $boolean;
6262
}
6363

6464
/**
6565
* {@inheritdoc}
6666
*/
67-
public function setName($name)
67+
public function setName(string $name)
6868
{
6969
$this->name = $name;
7070
}

src/Symfony/Component/Config/FileLocator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct($paths = [])
3333
/**
3434
* {@inheritdoc}
3535
*/
36-
public function locate($name, $currentPath = null, $first = true)
36+
public function locate(string $name, string $currentPath = null, $first = true)
3737
{
3838
if ('' == $name) {
3939
throw new \InvalidArgumentException('An empty file name is not valid to be located.');
@@ -81,7 +81,7 @@ public function locate($name, $currentPath = null, $first = true)
8181
*
8282
* @return bool
8383
*/
84-
private function isAbsolutePath($file)
84+
private function isAbsolutePath(string $file)
8585
{
8686
if ('/' === $file[0] || '\\' === $file[0]
8787
|| (\strlen($file) > 3 && ctype_alpha($file[0])

src/Symfony/Component/Config/FileLocatorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ interface FileLocatorInterface
3030
* @throws \InvalidArgumentException If $name is empty
3131
* @throws FileLocatorFileNotFoundException If a file is not found
3232
*/
33-
public function locate($name, $currentPath = null, $first = true);
33+
public function locate(string $name, string $currentPath = null, bool $first = true);
3434
}

src/Symfony/Component/Config/Loader/DelegatingLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(LoaderResolverInterface $resolver)
3131
/**
3232
* {@inheritdoc}
3333
*/
34-
public function load($resource, $type = null)
34+
public function load($resource, string $type = null)
3535
{
3636
if (false === $loader = $this->resolver->resolve($resource, $type)) {
3737
throw new LoaderLoadException($resource, null, null, null, $type);
@@ -43,7 +43,7 @@ public function load($resource, $type = null)
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function supports($resource, $type = null)
46+
public function supports($resource, string $type = null)
4747
{
4848
return false !== $this->resolver->resolve($resource, $type);
4949
}

src/Symfony/Component/Config/Loader/GlobFileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class GlobFileLoader extends FileLoader
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function load($resource, $type = null)
24+
public function load($resource, string $type = null)
2525
{
2626
return $this->import($resource);
2727
}
2828

2929
/**
3030
* {@inheritdoc}
3131
*/
32-
public function supports($resource, $type = null)
32+
public function supports($resource, string $type = null)
3333
{
3434
return 'glob' === $type;
3535
}

src/Symfony/Component/Config/Loader/LoaderInterface.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,20 @@ interface LoaderInterface
2121
/**
2222
* Loads a resource.
2323
*
24-
* @param mixed $resource The resource
25-
* @param string|null $type The resource type or null if unknown
24+
* @param mixed $resource The resource
2625
*
2726
* @throws \Exception If something went wrong
2827
*/
29-
public function load($resource, $type = null);
28+
public function load($resource, string $type = null);
3029

3130
/**
3231
* Returns whether this class supports the given resource.
3332
*
34-
* @param mixed $resource A resource
35-
* @param string|null $type The resource type or null if unknown
33+
* @param mixed $resource A resource
3634
*
3735
* @return bool True if this class supports the given resource, false otherwise
3836
*/
39-
public function supports($resource, $type = null);
37+
public function supports($resource, string $type = null);
4038

4139
/**
4240
* Gets the loader resolver.

src/Symfony/Component/Config/Loader/LoaderResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(array $loaders = [])
3939
/**
4040
* {@inheritdoc}
4141
*/
42-
public function resolve($resource, $type = null)
42+
public function resolve($resource, string $type = null)
4343
{
4444
foreach ($this->loaders as $loader) {
4545
if ($loader->supports($resource, $type)) {

src/Symfony/Component/Config/Loader/LoaderResolverInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ interface LoaderResolverInterface
2626
*
2727
* @return LoaderInterface|false The loader or false if none is able to load the resource
2828
*/
29-
public function resolve($resource, $type = null);
29+
public function resolve($resource, string $type = null);
3030
}

src/Symfony/Component/Config/Resource/SelfCheckingResourceChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function supports(ResourceInterface $metadata)
2828
return $metadata instanceof SelfCheckingResourceInterface;
2929
}
3030

31-
public function isFresh(ResourceInterface $resource, $timestamp)
31+
public function isFresh(ResourceInterface $resource, int $timestamp)
3232
{
3333
/* @var SelfCheckingResourceInterface $resource */
3434
return $resource->isFresh($timestamp);

src/Symfony/Component/Config/ResourceCheckerConfigCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function isFresh()
116116
*
117117
* @throws \RuntimeException When cache file can't be written
118118
*/
119-
public function write($content, array $metadata = null)
119+
public function write(string $content, array $metadata = null)
120120
{
121121
$mode = 0666;
122122
$umask = umask();

src/Symfony/Component/Config/ResourceCheckerConfigCacheFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(iterable $resourceCheckers = [])
3232
/**
3333
* {@inheritdoc}
3434
*/
35-
public function cache($file, $callback)
35+
public function cache(string $file, $callback)
3636
{
3737
if (!\is_callable($callback)) {
3838
throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', \gettype($callback)));

src/Symfony/Component/Config/ResourceCheckerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ public function supports(ResourceInterface $metadata);
4444
*
4545
* @return bool True if the resource has not changed since the given timestamp, false otherwise
4646
*/
47-
public function isFresh(ResourceInterface $resource, $timestamp);
47+
public function isFresh(ResourceInterface $resource, int $timestamp);
4848
}

src/Symfony/Component/Config/Tests/FileLocatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,6 @@ public function testLocateEmpty()
115115
{
116116
$loader = new FileLocator([__DIR__.'/Fixtures']);
117117

118-
$loader->locate(null, __DIR__);
118+
$loader->locate('', __DIR__);
119119
}
120120
}

0 commit comments

Comments
 (0)
0