Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Config] finish adding parameter types #32286

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
Jul 5, 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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ protected function listBundles($output)
}
}

/**
* @return ExtensionInterface
*/
protected function findExtension($name)
{
$bundles = $this->initializeBundles();
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
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)));
}

$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);
}
6 changes: 3 additions & 3 deletions src/Symfony/Component/Config/Definition/ArrayNode.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)) {
Copy link
Member

Choose a reason for hiding this comment

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

only for 5? missing deprecation in 4.4?

Copy link
Contributor Author

@Tobion Tobion Jul 3, 2019

Choose a reason for hiding this comment

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

I just moved the check from PrototypedArrayNode.php::setDefaultValue here so the typhint in setDefaultValue can be added. The $this->defaultValue comes from a generic setter that we cannot use types for. The behavior is the same, just cleaner code using types when possible.

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

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

Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading