Skip to content

Commit

Permalink
minor #32286 [Config] finish adding parameter types (Tobion)
Browse files Browse the repository at this point in the history
This PR was merged into the 5.0-dev branch.

Discussion
----------

[Config] finish adding parameter types

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yno
| 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
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Completes some missing things in #32201

Commits
-------

2ca8354 [Config] finish adding parameter types
  • Loading branch information
fabpot committed Jul 5, 2019
2 parents c1fe1fa + 2ca8354 commit bfabad4
Show file tree
Hide file tree
Showing 46 changed files with 118 additions and 182 deletions.
Expand Up @@ -52,6 +52,9 @@ protected function listBundles($output)
}
}

/**
* @return ExtensionInterface
*/
protected function findExtension($name)
{
$bundles = $this->initializeBundles();
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function __construct(LoaderResolverInterface $resolver, array $defaultOpt
/**
* {@inheritdoc}
*/
public function load($resource, $type = null)
public function load($resource, string $type = null)
{
if ($this->loading) {
// This can happen if a fatal error occurs in parent::load().
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Expand Up @@ -19,7 +19,7 @@
"php": "^7.2.9",
"ext-xml": "*",
"symfony/cache": "^4.4|^5.0",
"symfony/config": "^4.4|^5.0",
"symfony/config": "^5.0",
"symfony/dependency-injection": "^4.4|^5.0",
"symfony/error-catcher": "^4.4|^5.0",
"symfony/http-foundation": "^4.4|^5.0",
Expand Down
6 changes: 1 addition & 5 deletions src/Symfony/Component/Config/ConfigCacheFactory.php
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)));
}

$cache = new ConfigCache($file, $this->debug);
if (!$cache->isFresh()) {
$callback($cache);
Expand Down
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);
}
6 changes: 3 additions & 3 deletions src/Symfony/Component/Config/Definition/ArrayNode.php
Expand Up @@ -129,16 +129,16 @@ public function setAllowNewKeys(bool $allow)
*/
public function setPerformDeepMerging(bool $boolean)
{
$this->performDeepMerging = (bool) $boolean;
$this->performDeepMerging = $boolean;
}

/**
* Whether extra keys should just be ignore without an exception.
* Whether extra keys should just be ignored without an exception.
*
* @param bool $boolean To allow extra keys
* @param bool $remove To remove extra keys
*/
public function setIgnoreExtraKeys(bool $boolean, $remove = true)
public function setIgnoreExtraKeys(bool $boolean, bool $remove = true)
{
$this->ignoreExtraKeys = $boolean;
$this->removeExtraKeys = $this->ignoreExtraKeys && $remove;
Expand Down
32 changes: 13 additions & 19 deletions src/Symfony/Component/Config/Definition/BaseNode.php
Expand Up @@ -97,17 +97,17 @@ public static function resetPlaceholders(): void
self::$placeholders = [];
}

public function setAttribute($key, $value)
public function setAttribute(string $key, $value)
{
$this->attributes[$key] = $value;
}

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

public function hasAttribute($key)
public function hasAttribute(string $key)
{
return isset($this->attributes[$key]);
}
Expand All @@ -122,17 +122,15 @@ public function setAttributes(array $attributes)
$this->attributes = $attributes;
}

public function removeAttribute($key)
public function removeAttribute(string $key)
{
unset($this->attributes[$key]);
}

/**
* Sets an info message.
*
* @param string $info
*/
public function setInfo($info)
public function setInfo(string $info)
{
$this->setAttribute('info', $info);
}
Expand Down Expand Up @@ -183,32 +181,28 @@ public function addEquivalentValue($originalValue, $equivalentValue)
*
* @param bool $boolean Required node
*/
public function setRequired($boolean)
public function setRequired(bool $boolean)
{
$this->required = (bool) $boolean;
$this->required = $boolean;
}

/**
* Sets this node as deprecated.
*
* You can use %node% and %path% placeholders in your message to display,
* respectively, the node name and its complete path.
*
* @param string|null $message Deprecated message
*/
public function setDeprecated($message)
public function setDeprecated(?string $message)
{
$this->deprecationMessage = $message;
}

/**
* Sets if this node can be overridden.
*
* @param bool $allow
*/
public function setAllowOverwrite($allow)
public function setAllowOverwrite(bool $allow)
{
$this->allowOverwrite = (bool) $allow;
$this->allowOverwrite = $allow;
}

/**
Expand Down Expand Up @@ -257,7 +251,7 @@ public function isDeprecated()
*
* @return string
*/
public function getDeprecationMessage($node, $path)
public function getDeprecationMessage(string $node, string $path)
{
return strtr($this->deprecationMessage, ['%node%' => $node, '%path%' => $path]);
}
Expand Down Expand Up @@ -366,9 +360,9 @@ final public function normalize($value)
/**
* Normalizes the value before any other normalization is applied.
*
* @param $value
* @param mixed $value
*
* @return The normalized array value
* @return mixed The normalized array value
*/
protected function preNormalize($value)
{
Expand Down
Expand Up @@ -66,11 +66,9 @@ public function children()
/**
* Sets a prototype for child nodes.
*
* @param string $type The type of node
*
* @return NodeDefinition
*/
public function prototype($type)
public function prototype(string $type)
{
return $this->prototype = $this->getNodeBuilder()->node(null, $type)->setParent($this);
}
Expand Down Expand Up @@ -194,12 +192,12 @@ public function disallowNewKeysInSubsequentConfigs()
/**
* Sets a normalization rule for XML configurations.
*
* @param string $singular The key to remap
* @param string $plural The plural of the key for irregular plurals
* @param string $singular The key to remap
* @param string|null $plural The plural of the key for irregular plurals
*
* @return $this
*/
public function fixXmlConfig($singular, $plural = null)
public function fixXmlConfig(string $singular, string $plural = null)
{
$this->normalization()->remap($singular, $plural);

Expand Down Expand Up @@ -234,7 +232,7 @@ public function fixXmlConfig($singular, $plural = null)
*
* @return $this
*/
public function useAttributeAsKey($name, $removeKeyItem = true)
public function useAttributeAsKey(string $name, bool $removeKeyItem = true)
{
$this->key = $name;
$this->removeKeyItem = $removeKeyItem;
Expand All @@ -245,11 +243,9 @@ public function useAttributeAsKey($name, $removeKeyItem = true)
/**
* Sets whether the node can be unset.
*
* @param bool $allow
*
* @return $this
*/
public function canBeUnset($allow = true)
public function canBeUnset(bool $allow = true)
{
$this->merge()->allowUnset($allow);

Expand Down Expand Up @@ -341,7 +337,7 @@ public function performNoDeepMerging()
*
* @return $this
*/
public function ignoreExtraKeys($remove = true)
public function ignoreExtraKeys(bool $remove = true)
{
$this->ignoreExtraKeys = true;
$this->removeExtraKeys = $remove;
Expand All @@ -350,15 +346,13 @@ public function ignoreExtraKeys($remove = true)
}

/**
* Sets key normalization.
*
* @param bool $bool Whether to enable key normalization
* Sets whether to enable key normalization.
*
* @return $this
*/
public function normalizeKeys($bool)
public function normalizeKeys(bool $bool)
{
$this->normalizeKeys = (bool) $bool;
$this->normalizeKeys = $bool;

return $this;
}
Expand Down Expand Up @@ -417,6 +411,10 @@ protected function createNode()
}

if ($this->default) {
if (!\is_array($this->defaultValue)) {
throw new \InvalidArgumentException($node->getPath().': the default value of an array node has to be an array.');
}

$node->setDefaultValue($this->defaultValue);
}

Expand Down
Expand Up @@ -178,13 +178,11 @@ public function thenEmptyArray()
*
* if you want to add the value of the node in your message just use a %s placeholder.
*
* @param string $message
*
* @return $this
*
* @throws \InvalidArgumentException
*/
public function thenInvalid($message)
public function thenInvalid(string $message)
{
$this->thenPart = function ($v) use ($message) { throw new \InvalidArgumentException(sprintf($message, json_encode($v))); };

Expand Down
Expand Up @@ -30,11 +30,9 @@ public function __construct(NodeDefinition $node)
/**
* Sets whether the node can be unset.
*
* @param bool $allow
*
* @return $this
*/
public function allowUnset($allow = true)
public function allowUnset(bool $allow = true)
{
$this->allowFalse = $allow;

Expand All @@ -44,11 +42,9 @@ public function allowUnset($allow = true)
/**
* Sets whether the node can be overwritten.
*
* @param bool $deny Whether the overwriting is forbidden or not
*
* @return $this
*/
public function denyOverwrite($deny = true)
public function denyOverwrite(bool $deny = true)
{
$this->allowOverwrite = !$deny;

Expand Down

0 comments on commit bfabad4

Please sign in to comment.