8000 [Config] finish adding parameter types · symfony/symfony@2ca8354 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ca8354

Browse files
committed
[Config] finish adding parameter types
1 parent 38b9b95 commit 2ca8354

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+118
-182
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ protected function listBundles($output)
5252
}
5353
}
5454

55+
/**
56+
* @return ExtensionInterface
57+
*/
5558
protected function findExtension($name)
5659
{
5760
$bundles = $this->initializeBundles();

src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(LoaderResolverInterface $resolver, array $defaultOpt
4040
/**
4141
* {@inheritdoc}
4242
*/
43-
public function load($resource, $type = null)
43+
public function load($resource, string $type = null)
4444
{
4545
if ($this->loading) {
4646
// This can happen if a fatal error occurs in parent::load().

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": "^7.2.9",
2020
"ext-xml": "*",
2121
"symfony/cache": "^4.4|^5.0",
22-
"symfony/config": "^4.4|^5.0",
22+
"symfony/config": "^5.0",
2323
"symfony/dependency-injection": "^4.4|^5.0",
2424
"symfony/error-catcher": "^4.4|^5.0",
2525
"symfony/http-foundation": "^4.4|^5.0",

src/Symfony/Component/Config/ConfigCacheFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ public function __construct(bool $debug)
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
public function cache(string $file, $callback)
38+
public function cache(string $file, callable $callback)
3939
{
40-
if (!\is_callable($callback)) {
41-
throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', \gettype($callback)));
42-
}
43-
4440
$cache = new ConfigCache($file, $this->debug);
4541
if (!$cache->isFresh()) {
4642
$callback($cache);

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(string $file, $callable);
31+
public function cache(string $file, callable $callable);
3232
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,16 @@ public function setAllowNewKeys(bool $allow)
129129
*/
130130
public function setPerformDeepMerging(bool $boolean)
131131
{
132-
$this->performDeepMerging = (bool) $boolean;
132+
$this->performDeepMerging = $boolean;
133133
}
134134

135135
/**
136-
* Whether extra keys should just be ignore without an exception.
136+
* Whether extra keys should just be ignored without an exception.
137137
*
138138
* @param bool $boolean To allow extra keys
139139
* @param bool $remove To remove extra keys
140140
*/
141-
public function setIgnoreExtraKeys(bool $boolean, $remove = true)
141+
public function setIgnoreExtraKeys(bool $boolean, bool $remove = true)
142142
{
143143
$this->ignoreExtraKeys = $boolean;
144144
$this->removeExtraKeys = $this->ignoreExtraKeys && $remove;

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ public static function resetPlaceholders(): void
9797
self::$placeholders = [];
9898
}
9999

100-
public function setAttribute($key, $value)
100+
public function setAttribute(string $key, $value)
101101
{
102102
$this->attributes[$key] = $value;
103103
}
104104

105-
public function getAttribute($key, $default = null)
105+
public function getAttribute(string $key, $default = null)
106106
{
107107
return isset($this->attributes[$key]) ? $this->attributes[$key] : $default;
108108
}
109109

110-
public function hasAttribute($key)
110+
public function hasAttribute(string $key)
111111
{
112112
return isset($this->attributes[$key]);
113113
}
@@ -122,17 +122,15 @@ public function setAttributes(array $attributes)
122122
$this->attributes = $attributes;
123123
}
124124

125-
public function removeAttribute($key)
125+
public function removeAttribute(string $key)
126126
{
127127
unset($this->attributes[$key]);
128128
}
129129

130130
/**
131131
* Sets an info message.
132-
*
133-
* @param string $info
134132
*/
135-
public function setInfo($info)
133+
public function setInfo(string $info)
136134
{
137135
$this->setAttribute('info', $info);
138136
}
@@ -183,32 +181,28 @@ public function addEquivalentValue($originalValue, $equivalentValue)
183181
*
184182
* @param bool $boolean Required node
185183
*/
186-
public function setRequired($boolean)
184+
public function setRequired(bool $boolean)
187185
{
188-
$this->required = (bool) $boolean;
186+
$this->required = $boolean;
189187
}
190188

191189
/**
192190
* Sets this node as deprecated.
193191
*
194192
* You can use %node% and %path% placeholders in your message to display,
195193
* respectively, the node name and its complete path.
196-
*
197-
* @param string|null $message Deprecated message
198194
*/
199-
public function setDeprecated($message)
195+
public function setDeprecated(?string $message)
200196
{
201197
$this->deprecationMessage = $message;
202198
}
203199

204200
/**
205201
* Sets if this node can be overridden.
206-
*
207-
* @param bool $allow
208202
*/
209-
public function setAllowOverwrite($allow)
203+
public function setAllowOverwrite(bool $allow)
210204
{
211-
$this->allowOverwrite = (bool) $allow;
205+
$this->allowOverwrite = $allow;
212206
}
213207

214208
/**
@@ -257,7 +251,7 @@ public function isDeprecated()
257251
*
258252
* @return string
259253
*/
260-
public function getDeprecationMessage($node, $path)
254+
public function getDeprecationMessage(string $node, string $path)
261255
{
262256
return strtr($this->deprecationMessage, ['%node%' => $node, '%path%' => $path]);
263257
}
@@ -366,9 +360,9 @@ final public function normalize($value)
366360
/**
367361
* Normalizes the value before any other normalization is applied.
368362
*
369-
* @param $value
363+
10000 * @param mixed $value
370364
*
371-
* @return The normalized array value
365+
* @return mixed The normalized array value
372366
*/
373367
protected function preNormalize($value)
374368
{

src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ public function children()
6666
/**
6767
* Sets a prototype for child nodes.
6868
*
69-
* @param string $type The type of node
70-
*
7169
* @return NodeDefinition
7270
*/
73-
public function prototype($type)
71+
public function prototype(string $type)
7472
{
7573
return $this->prototype = $this->getNodeBuilder()->node(null, $type)->setParent($this);
7674
}
@@ -194,12 +192,12 @@ public function disallowNewKeysInSubsequentConfigs()
194192
/**
195193
* Sets a normalization rule for XML configurations.
196194
*
197-
* @param string $singular The key to remap
198-
* @param string $plural The plural of the key for irregular plurals
195+
* @param string $singular The key to remap
196+
* @param string|null $plural The plural of the key for irregular plurals
199197
*
200198
* @return $this
201199
*/
202-
public function fixXmlConfig($singular, $plural = null)
200+
public function fixXmlConfig(string $singular, string $plural = null)
203201
{
204202
$this->normalization()->remap($singular, $plural);
205203

@@ -234,7 +232,7 @@ public function fixXmlConfig($singular, $plural = null)
234232
*
235233
* @return $this
236234
*/
237-
public function useAttributeAsKey($name, $removeKeyItem = true)
235+
public function useAttributeAsKey(string $name, bool $removeKeyItem = true)
238236
{
239237
$this->key = $name;
240238
$this->removeKeyItem = $removeKeyItem;
@@ -245,11 +243,9 @@ public function useAttributeAsKey($name, $removeKeyItem = true)
245243
/**
246244
* Sets whether the node can be unset.
247245
*
248-
* @param bool $allow
249-
*
250246
* @return $this
251247
*/
252-
public function canBeUnset($allow = true)
248+
public function canBeUnset(bool $allow = true)
253249
{
254250
$this->merge()->allowUnset($allow);
255251

@@ -341,7 +337,7 @@ public function performNoDeepMerging()
341337
*
342338
* @return $this
343339
*/
344-
public function ignoreExtraKeys($remove = true)
340+
public function ignoreExtraKeys(bool $remove = true)
345341
{
346342
$this->ignoreExtraKeys = true;
347343
$this->removeExtraKeys = $remove;
@@ -350,15 +346,13 @@ public function ignoreExtraKeys($remove = true)
350346
}
351347

352348
/**
353-
* Sets key normalization.
354-
*
355-
* @param bool $bool Whether to enable key normalization
349+
* Sets whether to enable key normalization.
356350
*
357351
* @return $this
358352
*/
359-
public function normalizeKeys($bool)
353+
public function normalizeKeys(bool $bool)
360354
{
361-
$this->normalizeKeys = (bool) $bool;
355+
$this->normalizeKeys = $bool;
362356

363357
return $this;
364358
}
@@ -417,6 +411,10 @@ protected function createNode()
417411
}
418412

419413
if ($this->default) {
414+
if (!\is_array($this->defaultValue)) {
415+
throw new \InvalidArgumentException($node->getPath().': the default value of an array node has to be an array.');
416+
}
417+
420418
$node->setDefaultValue($this->defaultValue);
421419
}
422420

src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,11 @@ public function thenEmptyArray()
178178
*
179179
* if you want to add the value of the node in your message just use a %s placeholder.
180180
*
181-
* @param string $message
182-
*
183181
* @return $this
184182
*
185183
* @throws \InvalidArgumentException
186184
*/
187-
public function thenInvalid($message)
185+
public function thenInvalid(string $message)
188186
{
189187
$this->thenPart = function ($v) use ($message) { throw new \InvalidArgumentException(sprintf($message, json_encode($v))); };
190188

src/Symfony/Component/Config/Definition/Builder/MergeBuilder.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ public function __construct(NodeDefinition $node)
3030
/**
3131
* Sets whether the node can be unset.
3232
*
33-
* @param bool $allow
34-
*
3533
* @return $this
3634
*/
37-
public function allowUnset($allow = true)
35+
public function allowUnset(bool $allow = true)
3836
{
3937
$this->allowFalse = $allow;
4038

@@ -44,11 +42,9 @@ public function allowUnset($allow = true)
4442
/**
4543
* Sets whether the node can be overwritten.
4644
*
47-
* @param bool $deny Whether the overwriting is forbidden or not
48-
*
4945
* @return $this
5046
*/
51-
public function denyOverwrite($deny = true)
47+
public function denyOverwrite(bool $deny = true)
5248
{
5349
$this->allowOverwrite = !$deny;
5450

0 commit comments

Comments
 (0)
0