[DependencyInjection] Add type-hints to interfaces and implementations.

This commit is contained in:
Alexander M. Turek 2019-06-28 18:25:25 +02:00
parent f03bf95941
commit 68f9f278e2
51 changed files with 195 additions and 441 deletions

View File

@ -44,13 +44,11 @@ class Alias
/**
* Sets if this Alias is public.
*
* @param bool $boolean If this Alias should be public
*
* @return $this
*/
public function setPublic($boolean)
public function setPublic(bool $boolean)
{
$this->public = (bool) $boolean;
$this->public = $boolean;
$this->private = false;
return $this;
@ -64,13 +62,11 @@ class Alias
* but triggers a deprecation notice when accessed from the container,
* so that the alias can be made really private in 4.0.
*
* @param bool $boolean
*
* @return $this
*/
public function setPrivate($boolean)
public function setPrivate(bool $boolean)
{
$this->private = (bool) $boolean;
$this->private = $boolean;
return $this;
}
@ -96,7 +92,7 @@ class Alias
*
* @throws InvalidArgumentException when the message template is invalid
*/
public function setDeprecated($status = true, $template = null)
public function setDeprecated(bool $status = true, string $template = null)
{
if (null !== $template) {
if (preg_match('#[\r\n]|\*/#', $template)) {
@ -110,7 +106,7 @@ class Alias
$this->deprecationTemplate = $template;
}
$this->deprecated = (bool) $status;
$this->deprecated = $status;
return $this;
}

View File

@ -109,7 +109,7 @@ class ChildDefinition extends Definition
/**
* @internal
*/
public function setAutoconfigured($autoconfigured)
public function setAutoconfigured(bool $autoconfigured)
{
throw new BadMethodCallException('A ChildDefinition cannot be autoconfigured.');
}

View File

@ -167,7 +167,7 @@ class MergeExtensionConfigurationContainerBuilder extends ContainerBuilder
/**
* {@inheritdoc}
*/
public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
public function addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
{
throw new LogicException(sprintf('You cannot add compiler pass "%s" from extension "%s". Compiler passes must be registered before the container is compiled.', \get_class($pass), $this->extensionClass));
}

View File

@ -107,7 +107,7 @@ class Container implements ContainerInterface, ResetInterface
*
* @throws InvalidArgumentException if the parameter is not defined
*/
public function getParameter($name)
public function getParameter(string $name)
{
return $this->parameterBag->get($name);
}
@ -119,7 +119,7 @@ class Container implements ContainerInterface, ResetInterface
*
* @return bool The presence of parameter in container
*/
public function hasParameter($name)
public function hasParameter(string $name)
{
return $this->parameterBag->has($name);
}
@ -130,7 +130,7 @@ class Container implements ContainerInterface, ResetInterface
* @param string $name The parameter name
* @param mixed $value The parameter value
*/
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
$this->parameterBag->set($name, $value);
}
@ -141,10 +141,9 @@ class Container implements ContainerInterface, ResetInterface
* Setting a synthetic service to null resets it: has() returns false and get()
* behaves in the same way as if the service was never created.
*
* @param string $id The service identifier
* @param object $service The service instance
*/
public function set($id, $service)
public function set(string $id, $service)
{
// Runs the internal initializer; used by the dumped container to include always-needed files
if (isset($this->privates['service_container']) && $this->privates['service_container'] instanceof \Closure) {
@ -218,7 +217,7 @@ class Container implements ContainerInterface, ResetInterface
*
* @see Reference
*/
public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1)
public function get($id, int $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1)
{
return $this->services[$id]
?? $this->services[$id = $this->aliases[$id] ?? $id]
@ -285,7 +284,7 @@ class Container implements ContainerInterface, ResetInterface
*
* @return bool true if service has already been initialized, false otherwise
*/
public function initialized($id)
public function initialized(string $id)
{
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];

View File

@ -160,12 +160,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* If you are not using the loaders and therefore don't want
* to depend on the Config component, set this flag to false.
*
* @param bool $track True if you want to track resources, false otherwise
*/
public function setResourceTracking($track)
public function setResourceTracking(bool $track)
{
$this->trackResources = (bool) $track;
$this->trackResources = $track;
}
/**
@ -198,13 +196,11 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Returns an extension by alias or namespace.
*
* @param string $name An alias or a namespace
*
* @return ExtensionInterface An extension instance
*
* @throws LogicException if the extension is not registered
*/
public function getExtension($name)
public function getExtension(string $name)
{
if (isset($this->extensions[$name])) {
return $this->extensions[$name];
@ -230,11 +226,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Checks if we have an extension.
*
* @param string $name The name of the extension
*
* @return bool If the extension exists
*/
public function hasExtension($name)
public function hasExtension(string $name)
{
return isset($this->extensions[$name]) || isset($this->extensionsByNs[$name]);
}
@ -424,7 +418,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
* @throws BadMethodCallException When this ContainerBuilder is compiled
* @throws \LogicException if the extension is not registered
*/
public function loadFromExtension($extension, array $values = null)
public function loadFromExtension(string $extension, array $values = null)
{
if ($this->isCompiled()) {
throw new BadMethodCallException('Cannot load from an extension on a compiled container.');
@ -450,7 +444,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* @return $this
*/
public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
public function addCompilerPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
{
$this->getCompiler()->addPass($pass, $type, $priority);
@ -486,15 +480,12 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Sets a service.
*
* @param string $id The service identifier
* @param object $service The service instance
*
* @throws BadMethodCallException When this ContainerBuilder is compiled
*/
public function set($id, $service)
public function set(string $id, $service)
{
$id = (string) $id;
if ($this->isCompiled() && (isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic())) {
// setting a synthetic service on a compiled container is alright
throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id));
@ -507,12 +498,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Removes a service definition.
*
* @param string $id The service identifier
*/
public function removeDefinition($id)
public function removeDefinition(string $id)
{
if (isset($this->definitions[$id = (string) $id])) {
if (isset($this->definitions[$id])) {
unset($this->definitions[$id]);
$this->removedIds[$id] = true;
}
@ -547,7 +536,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* @see Reference
*/
public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
public function get($id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
{
if ($this->isCompiled() && isset($this->removedIds[$id = (string) $id]) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $invalidBehavior) {
return parent::get($id);
@ -556,7 +545,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
return $this->doGet($id, $invalidBehavior);
}
private function doGet($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, array &$inlineServices = null, $isConstructorArgument = false)
private function doGet(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, array &$inlineServices = null, bool $isConstructorArgument = false)
{
if (isset($inlineServices[$id])) {
return $inlineServices[$id];
@ -689,11 +678,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Returns the configuration array for the given extension.
*
* @param string $name The name of the extension
*
* @return array An array of configuration
*/
public function getExtensionConfig($name)
public function getExtensionConfig(string $name)
{
if (!isset($this->extensionConfigs[$name])) {
$this->extensionConfigs[$name] = [];
@ -704,11 +691,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Prepends a config array to the configs of the given extension.
*
* @param string $name The name of the extension
* @param array $config The config to set
*/
public function prependExtensionConfig($name, array $config)
public function prependExtensionConfig(string $name, array $config)
{
if (!isset($this->extensionConfigs[$name])) {
$this->extensionConfigs[$name] = [];
@ -828,10 +812,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
* @throws InvalidArgumentException if the id is not a string or an Alias
* @throws InvalidArgumentException if the alias is for itself
*/
public function setAlias($alias, $id)
public function setAlias(string $alias, $id)
{
$alias = (string) $alias;
if ('' === $alias || '\\' === $alias[-1] || \strlen($alias) !== strcspn($alias, "\0\r\n'")) {
throw new InvalidArgumentException(sprintf('Invalid alias id: "%s"', $alias));
}
@ -856,9 +838,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* @param string $alias The alias to remove
*/
public function removeAlias($alias)
public function removeAlias(string $alias)
{
if (isset($this->aliasDefinitions[$alias = (string) $alias])) {
if (isset($this->aliasDefinitions[$alias])) {
unset($this->aliasDefinitions[$alias]);
$this->removedIds[$alias] = true;
}
@ -867,13 +849,11 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Returns true if an alias exists under the given identifier.
*
* @param string $id The service identifier
*
* @return bool true if the alias exists, false otherwise
*/
public function hasAlias($id)
public function hasAlias(string $id)
{
return isset($this->aliasDefinitions[$id = (string) $id]);
return isset($this->aliasDefinitions[$id]);
}
/**
@ -889,16 +869,12 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Gets an alias.
*
* @param string $id The service identifier
*
* @return Alias An Alias instance
*
* @throws InvalidArgumentException if the alias does not exist
*/
public function getAlias($id)
public function getAlias(string $id)
{
$id = (string) $id;
if (!isset($this->aliasDefinitions[$id])) {
throw new InvalidArgumentException(sprintf('The service alias "%s" does not exist.', $id));
}
@ -912,12 +888,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
* This methods allows for simple registration of service definition
* with a fluid interface.
*
* @param string $id The service identifier
* @param string $class|null The service class
*
* @return Definition A Definition instance
*/
public function register($id, $class = null)
public function register(string $id, string $class = null)
{
return $this->setDefinition($id, new Definition($class));
}
@ -928,12 +901,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
* This method implements a shortcut for using setDefinition() with
* an autowired definition.
*
* @param string $id The service identifier
* @param string|null $class The service class
*
* @return Definition The created definition
*/
public function autowire($id, $class = null)
public function autowire(string $id, string $class = null)
{
return $this->setDefinition($id, (new Definition($class))->setAutowired(true));
}
@ -974,21 +944,16 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Sets a service definition.
*
* @param string $id The service identifier
* @param Definition $definition A Definition instance
*
* @return Definition the service definition
*
* @throws BadMethodCallException When this ContainerBuilder is compiled
*/
public function setDefinition($id, Definition $definition)
public function setDefinition(string $id, Definition $definition)
{
if ($this->isCompiled()) {
throw new BadMethodCallException('Adding definition to a compiled container is not allowed');
}
$id = (string) $id;
if ('' === $id || '\\' === $id[-1] || \strlen($id) !== strcspn($id, "\0\r\n'")) {
throw new InvalidArgumentException(sprintf('Invalid service id: "%s"', $id));
}
@ -1001,28 +966,22 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Returns true if a service definition exists under the given identifier.
*
* @param string $id The service identifier
*
* @return bool true if the service definition exists, false otherwise
*/
public function hasDefinition($id)
public function hasDefinition(string $id)
{
return isset($this->definitions[(string) $id]);
return isset($this->definitions[$id]);
}
/**
* Gets a service definition.
*
* @param string $id The service identifier
*
* @return Definition A Definition instance
*
* @throws ServiceNotFoundException if the service definition does not exist
*/
public function getDefinition($id)
public function getDefinition(string $id)
{
$id = (string) $id;
if (!isset($this->definitions[$id])) {
throw new ServiceNotFoundException($id);
}
@ -1035,16 +994,12 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* The method "unaliases" recursively to return a Definition instance.
*
* @param string $id The service identifier or alias
*
* @return Definition A Definition instance
*
* @throws ServiceNotFoundException if the service definition does not exist
*/
public function findDefinition($id)
public function findDefinition(string $id)
{
$id = (string) $id;
$seen = [];
while (isset($this->aliasDefinitions[$id])) {
$id = (string) $this->aliasDefinitions[$id];
@ -1066,9 +1021,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Creates a service for a service definition.
*
* @param Definition $definition A service definition instance
* @param string $id The service identifier
* @param bool $tryProxy Whether to try proxying the service with a lazy proxy
* @param bool $tryProxy Whether to try proxying the service with a lazy proxy
*
* @return object The service described by the service definition
*
@ -1076,7 +1029,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
* @throws RuntimeException When the service is a synthetic service
* @throws InvalidArgumentException When configure callable is not callable
*/
private function createService(Definition $definition, array &$inlineServices, $isConstructorArgument = false, $id = null, $tryProxy = true)
private function createService(Definition $definition, array &$inlineServices, $isConstructorArgument = false, string $id = null, bool $tryProxy = true)
{
if (null === $id && isset($inlineServices[$h = spl_object_hash($definition)])) {
return $inlineServices[$h];
@ -1207,7 +1160,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
return $this->doResolveServices($value);
}
private function doResolveServices($value, array &$inlineServices = [], $isConstructorArgument = false)
private function doResolveServices($value, array &$inlineServices = [], bool $isConstructorArgument = false)
{
if (\is_array($value)) {
foreach ($value as $k => $v) {
@ -1289,12 +1242,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
* }
* }
*
* @param string $name
* @param bool $throwOnAbstract
*
* @return array An array of tags with the tagged service as key, holding a list of attribute arrays
*/
public function findTaggedServiceIds($name, $throwOnAbstract = false)
public function findTaggedServiceIds(string $name, bool $throwOnAbstract = false)
{
$this->usedTags[] = $name;
$tags = [];
@ -1351,11 +1301,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Returns a ChildDefinition that will be used for autoconfiguring the interface/class.
*
* @param string $interface The class or interface to match
*
* @return ChildDefinition
*/
public function registerForAutoconfiguration($interface)
public function registerForAutoconfiguration(string $interface)
{
if (!isset($this->autoconfiguredInstanceof[$interface])) {
$this->autoconfiguredInstanceof[$interface] = new ChildDefinition('');
@ -1506,11 +1454,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Removes bindings for a service.
*
* @param string $id The service identifier
*
* @internal
*/
public function removeBindings($id)
public function removeBindings(string $id)
{
if ($this->hasDefinition($id)) {
foreach ($this->getDefinition($id)->getBindings() as $key => $binding) {
@ -1635,11 +1581,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
/**
* Shares a given service in the container.
*
* @param Definition $definition
* @param object $service
* @param string|null $id
* @param object $service
*/
private function shareService(Definition $definition, $service, $id, array &$inlineServices)
private function shareService(Definition $definition, $service, ?string $id, array &$inlineServices)
{
$inlineServices[null !== $id ? $id : spl_object_hash($definition)] = $service;
@ -1661,7 +1605,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
return $this->expressionLanguage;
}
private function inVendors($path)
private function inVendors(string $path)
{
if (null === $this->vendors) {
$resource = new ComposerResource();

View File

@ -33,10 +33,9 @@ interface ContainerInterface extends PsrContainerInterface
/**
* Sets a service.
*
* @param string $id The service identifier
* @param object $service The service instance
*/
public function set($id, $service);
public function set(string $id, $service);
/**
* Gets a service.
@ -51,7 +50,7 @@ interface ContainerInterface extends PsrContainerInterface
*
* @see Reference
*/
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
public function get($id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
/**
* Returns true if the given service is defined.
@ -65,11 +64,9 @@ interface ContainerInterface extends PsrContainerInterface
/**
* Check for whether or not a service has been initialized.
*
* @param string $id
*
* @return bool true if the service has been initialized, false otherwise
*/
public function initialized($id);
public function initialized(string $id);
/**
* Gets a parameter.
@ -80,7 +77,7 @@ interface ContainerInterface extends PsrContainerInterface
*
* @throws InvalidArgumentException if the parameter is not defined
*/
public function getParameter($name);
public function getParameter(string $name);
/**
* Checks if a parameter exists.
@ -89,7 +86,7 @@ interface ContainerInterface extends PsrContainerInterface
*
* @return bool The presence of parameter in container
*/
public function hasParameter($name);
public function hasParameter(string $name);
/**
* Sets a parameter.
@ -97,5 +94,5 @@ interface ContainerInterface extends PsrContainerInterface
* @param string $name The parameter name
* @param mixed $value The parameter value
*/
public function setParameter($name, $value);
public function setParameter(string $name, $value);
}

View File

@ -56,11 +56,7 @@ class Definition
*/
public $innerServiceId;
/**
* @param string|null $class The service class
* @param array $arguments An array of arguments to pass to the service constructor
*/
public function __construct($class = null, array $arguments = [])
public function __construct(string $class = null, array $arguments = [])
{
if (null !== $class) {
$this->setClass($class);
@ -135,7 +131,7 @@ class Definition
*
* @throws InvalidArgumentException in case the decorated service id and the new decorated service id are equals
*/
public function setDecoratedService($id, $renamedId = null, $priority = 0)
public function setDecoratedService(?string $id, ?string $renamedId = null, int $priority = 0)
{
if ($renamedId && $id === $renamedId) {
throw new InvalidArgumentException(sprintf('The decorated service inner name for "%s" must be different than the service name itself.', $id));
@ -165,19 +161,10 @@ class Definition
/**
* Sets the service class.
*
* @param string $class The service class
*
* @return $this
*/
public function setClass($class)
public function setClass(?string $class)
{
if ($class instanceof Parameter) {
@trigger_error(sprintf('Passing an instance of %s as class name to %s in deprecated in Symfony 4.4 and will result in a TypeError in 5.0. Please pass the string "%%%s%%" instead.', Parameter::class, __CLASS__, (string) $class), E_USER_DEPRECATED);
}
if (null !== $class && !\is_string($class)) {
@trigger_error(sprintf('The class name passed to %s is expected to be a string. Passing a %s is deprecated in Symfony 4.4 and will result in a TypeError in 5.0.', __CLASS__, \is_object($class) ? \get_class($class) : \gettype($class)), E_USER_DEPRECATED);
}
$this->changes['class'] = true;
$this->class = $class;
@ -232,12 +219,11 @@ class Definition
/**
* Sets a specific property.
*
* @param string $name
* @param mixed $value
* @param mixed $value
*
* @return $this
*/
public function setProperty($name, $value)
public function setProperty(string $name, $value)
{
$this->properties[$name] = $value;
@ -356,7 +342,7 @@ class Definition
*
* @throws InvalidArgumentException on empty $method param
*/
public function addMethodCall($method, array $arguments = [], bool $returnsClone = false)
public function addMethodCall(string $method, array $arguments = [], bool $returnsClone = false)
{
if (empty($method)) {
throw new InvalidArgumentException('Method name cannot be empty.');
@ -369,11 +355,9 @@ class Definition
/**
* Removes a method to call after service initialization.
*
* @param string $method The method name to remove
*
* @return $this
*/
public function removeMethodCall($method)
public function removeMethodCall(string $method)
{
foreach ($this->calls as $i => $call) {
if ($call[0] === $method) {
@ -388,11 +372,9 @@ class Definition
/**
* Check if the current definition has a given method to call after service initialization.
*
* @param string $method The method name to search for
*
* @return bool
*/
public function hasMethodCall($method)
public function hasMethodCall(string $method)
{
foreach ($this->calls as $call) {
if ($call[0] === $method) {
@ -444,7 +426,7 @@ class Definition
*
* @return $this
*/
public function setAutoconfigured($autoconfigured)
public function setAutoconfigured(bool $autoconfigured)
{
$this->changes['autoconfigured'] = true;
@ -486,11 +468,9 @@ class Definition
/**
* Gets a tag by name.
*
* @param string $name The tag name
*
* @return array An array of attributes
*/
public function getTag($name)
public function getTag(string $name)
{
return isset($this->tags[$name]) ? $this->tags[$name] : [];
}
@ -498,12 +478,9 @@ class Definition
/**
* Adds a tag for this definition.
*
* @param string $name The tag name
* @param array $attributes An array of attributes
*
* @return $this
*/
public function addTag($name, array $attributes = [])
public function addTag(string $name, array $attributes = [])
{
$this->tags[$name][] = $attributes;
@ -513,11 +490,9 @@ class Definition
/**
* Whether this definition has a tag with the given name.
*
* @param string $name
*
* @return bool
*/
public function hasTag($name)
public function hasTag(string $name)
{
return isset($this->tags[$name]);
}
@ -525,11 +500,9 @@ class Definition
/**
* Clears all tags for a given name.
*
* @param string $name The tag name
*
* @return $this
*/
public function clearTag($name)
public function clearTag(string $name)
{
unset($this->tags[$name]);
@ -551,11 +524,9 @@ class Definition
/**
* Sets a file to require before creating the service.
*
* @param string $file A full pathname to include
*
* @return $this
*/
public function setFile($file)
public function setFile(?string $file)
{
$this->changes['file'] = true;
@ -577,15 +548,13 @@ class Definition
/**
* Sets if the service must be shared or not.
*
* @param bool $shared Whether the service must be shared or not
*
* @return $this
*/
public function setShared($shared)
public function setShared(bool $shared)
{
$this->changes['shared'] = true;
$this->shared = (bool) $shared;
$this->shared = $shared;
return $this;
}
@ -603,15 +572,13 @@ class Definition
/**
* Sets the visibility of this service.
*
* @param bool $boolean
*
* @return $this
*/
public function setPublic($boolean)
public function setPublic(bool $boolean)
{
$this->changes['public'] = true;
$this->public = (bool) $boolean;
$this->public = $boolean;
$this->private = false;
return $this;
@ -635,13 +602,11 @@ class Definition
* but triggers a deprecation notice when accessed from the container,
* so that the service can be made really private in 4.0.
*
* @param bool $boolean
*
* @return $this
*/
public function setPrivate($boolean)
public function setPrivate(bool $boolean)
{
$this->private = (bool) $boolean;
$this->private = $boolean;
return $this;
}
@ -659,15 +624,13 @@ class Definition
/**
* Sets the lazy flag of this service.
*
* @param bool $lazy
*
* @return $this
*/
public function setLazy($lazy)
public function setLazy(bool $lazy)
{
$this->changes['lazy'] = true;
$this->lazy = (bool) $lazy;
$this->lazy = $lazy;
return $this;
}
@ -686,13 +649,11 @@ class Definition
* Sets whether this definition is synthetic, that is not constructed by the
* container, but dynamically injected.
*
* @param bool $boolean
*
* @return $this
*/
public function setSynthetic($boolean)
public function setSynthetic(bool $boolean)
{
$this->synthetic = (bool) $boolean;
$this->synthetic = $boolean;
return $this;
}
@ -712,13 +673,11 @@ class Definition
* Whether this definition is abstract, that means it merely serves as a
* template for other definitions.
*
* @param bool $boolean
*
* @return $this
*/
public function setAbstract($boolean)
public function setAbstract(bool $boolean)
{
$this->abstract = (bool) $boolean;
$this->abstract = $boolean;
return $this;
}
@ -738,14 +697,13 @@ class Definition
* Whether this definition is deprecated, that means it should not be called
* anymore.
*
* @param bool $status
* @param string $template Template message to use if the definition is deprecated
*
* @return $this
*
* @throws InvalidArgumentException when the message template is invalid
*/
public function setDeprecated($status = true, $template = null)
public function setDeprecated(bool $status = true, string $template = null)
{
if (null !== $template) {
if (preg_match('#[\r\n]|\*/#', $template)) {
@ -761,7 +719,7 @@ class Definition
$this->changes['deprecated'] = true;
$this->deprecated = (bool) $status;
$this->deprecated = $status;
return $this;
}
@ -784,7 +742,7 @@ class Definition
*
* @return string
*/
public function getDeprecationMessage($id)
public function getDeprecationMessage(string $id)
{
return str_replace('%service_id%', $id, $this->deprecationTemplate ?: self::$defaultDeprecationTemplate);
}
@ -834,15 +792,13 @@ class Definition
/**
* Enables/disables autowiring.
*
* @param bool $autowired
*
* @return $this
*/
public function setAutowired($autowired)
public function setAutowired(bool $autowired)
{
$this->changes['autowired'] = true;
$this->autowired = (bool) $autowired;
$this->autowired = $autowired;
return $this;
}

View File

@ -18,6 +18,7 @@ use Symfony\Component\DependencyInjection\Argument\ServiceLocator;
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\CheckCircularReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\ServiceReferenceGraphEdge;
use Symfony\Component\DependencyInjection\Compiler\ServiceReferenceGraphNode;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -339,7 +340,10 @@ EOF;
return $this->proxyDumper;
}
private function analyzeCircularReferences($sourceId, array $edges, &$checkedNodes, &$currentPath = [])
/**
* @param ServiceReferenceGraphEdge[] $edges
*/
private function analyzeCircularReferences(string $sourceId, array $edges, array &$checkedNodes, array &$currentPath = [])
{
$checkedNodes[$sourceId] = true;
$currentPath[$sourceId] = $sourceId;
@ -368,7 +372,7 @@ EOF;
unset($currentPath[$sourceId]);
}
private function connectCircularReferences($sourceId, &$currentPath, &$subPath = [])
private function connectCircularReferences(string $sourceId, array &$currentPath, array &$subPath = [])
{
$subPath[$sourceId] = $sourceId;
$currentPath[$sourceId] = $sourceId;
@ -391,7 +395,7 @@ EOF;
unset($subPath[$sourceId]);
}
private function collectLineage($class, array &$lineage)
private function collectLineage(string $class, array &$lineage)
{
if (isset($lineage[$class])) {
return;
@ -1284,9 +1288,8 @@ EOF;
$code = <<<'EOF'
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (isset($this->buildParameters[$name])) {
return $this->buildParameters[$name];
}
@ -1301,9 +1304,8 @@ EOF;
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
if (isset($this->buildParameters[$name])) {
return true;
}
@ -1311,7 +1313,7 @@ EOF;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}
@ -1334,7 +1336,7 @@ EOF;
EOF;
if (!$this->asFiles) {
$code = preg_replace('/^.*buildParameters.*\n.*\n.*\n/m', '', $code);
$code = preg_replace('/^.*buildParameters.*\n.*\n.*\n\n?/m', '', $code);
}
if ($dynamicPhp) {
@ -1891,7 +1893,7 @@ EOF;
return $this->doExport($value, true);
}
private function doExport($value, $resolveEnv = false)
private function doExport($value, bool $resolveEnv = false)
{
$shouldCacheValue = $resolveEnv && \is_string($value);
if ($shouldCacheValue && isset($this->exportedVariables[$value])) {

View File

@ -93,12 +93,8 @@ class XmlDumper extends Dumper
/**
* Adds a service.
*
* @param Definition $definition
* @param string $id
* @param \DOMElement $parent
*/
private function addService($definition, $id, \DOMElement $parent)
private function addService(Definition $definition, ?string $id, \DOMElement $parent)
{
$service = $this->document->createElement('service');
if (null !== $id) {
@ -217,12 +213,8 @@ class XmlDumper extends Dumper
/**
* Adds a service alias.
*
* @param string $alias
* @param Alias $id
* @param \DOMElement $parent
*/
private function addServiceAlias($alias, Alias $id, \DOMElement $parent)
private function addServiceAlias(string $alias, Alias $id, \DOMElement $parent)
{
$service = $this->document->createElement('service');
$service->setAttribute('id', $alias);
@ -265,13 +257,8 @@ class XmlDumper extends Dumper
/**
* Converts parameters.
*
* @param array $parameters
* @param string $type
* @param \DOMElement $parent
* @param string $keyAttribute
*/
private function convertParameters(array $parameters, $type, \DOMElement $parent, $keyAttribute = 'key')
private function convertParameters(array $parameters, string $type, \DOMElement $parent, string $keyAttribute = 'key')
{
$withKeys = array_keys($parameters) !== range(0, \count($parameters) - 1);
foreach ($parameters as $key => $value) {

View File

@ -303,7 +303,7 @@ class YamlDumper extends Dumper
return sprintf('%%%s%%', $id);
}
private function getExpressionCall($expression)
private function getExpressionCall(string $expression)
{
return sprintf('@=%s', $expression);
}

View File

@ -54,7 +54,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
/**
* {@inheritdoc}
*/
public function getEnv($prefix, $name, \Closure $getEnv)
public function getEnv(string $prefix, string $name, \Closure $getEnv)
{
$i = strpos($name, ':');

View File

@ -31,7 +31,7 @@ interface EnvVarProcessorInterface
*
* @throws RuntimeException on error
*/
public function getEnv($prefix, $name, \Closure $getEnv);
public function getEnv(string $prefix, string $name, \Closure $getEnv);
/**
* @return string[] The PHP-types managed by getEnv(), keyed by prefixes

View File

@ -31,7 +31,7 @@ trait BindTrait
*
* @return $this
*/
final public function bind($nameOrFqcn, $valueOrRef): object
final public function bind(string $nameOrFqcn, $valueOrRef): object
{
$valueOrRef = static::processValue($valueOrRef, true);
if (!preg_match('/^(?:(?:array|bool|float|int|string)[ \t]*+)?\$/', $nameOrFqcn) && !$valueOrRef instanceof Reference) {

View File

@ -25,7 +25,7 @@ trait CallTrait
*
* @throws InvalidArgumentException on empty $method param
*/
final public function call($method, array $arguments = []): object
final public function call(string $method, array $arguments = []): object
{
$this->definition->addMethodCall($method, static::processValue($arguments, true));

View File

@ -18,7 +18,7 @@ trait ClassTrait
*
* @return $this
*/
final public function class($class): object
final public function class(?string $class): object
{
$this->definition->setClass($class);

View File

@ -26,7 +26,7 @@ trait DecorateTrait
*
* @throws InvalidArgumentException in case the decorated service id and the new decorated service id are equals
*/
final public function decorate($id, $renamedId = null, $priority = 0): object
final public function decorate(?string $id, ?string $renamedId = null, int $priority = 0): object
{
$this->definition->setDecoratedService($id, $renamedId, $priority);

View File

@ -24,7 +24,7 @@ trait DeprecateTrait
*
* @throws InvalidArgumentException when the message template is invalid
*/
final public function deprecate($template = null): object
final public function deprecate(string $template = null): object
{
$this->definition->setDeprecated(true, $template);

View File

@ -16,11 +16,9 @@ trait FileTrait
/**
* Sets a file to require before creating the service.
*
* @param string $file A full pathname to include
*
* @return $this
*/
final public function file($file): object
final public function file(string $file): object
{
$this->definition->setFile($file);

View File

@ -16,11 +16,9 @@ trait ShareTrait
/**
* Sets if the service must be shared or not.
*
* @param bool $shared Whether the service must be shared or not
*
* @return $this
*/
final public function share($shared = true): object
final public function share(bool $shared = true): object
{
$this->definition->setShared($shared);

View File

@ -18,12 +18,9 @@ trait TagTrait
/**
* Adds a tag for this definition.
*
* @param string $name The tag name
* @param array $attributes An array of attributes
*
* @return $this
*/
final public function tag($name, array $attributes = []): object
final public function tag(string $name, array $attributes = []): object
{
if (!\is_string($name) || '' === $name) {
throw new InvalidArgumentException(sprintf('The tag name for service "%s" must be a non-empty string.', $this->id));

View File

@ -27,7 +27,7 @@ class EnvPlaceholderParameterBag extends ParameterBag
/**
* {@inheritdoc}
*/
public function get($name)
public function get(string $name)
{
if (0 === strpos($name, 'env(') && ')' === substr($name, -1) && 'env()' !== $name) {
$env = substr($name, 4, -1);

View File

@ -53,7 +53,7 @@ class FrozenParameterBag extends ParameterBag
/**
* {@inheritdoc}
*/
public function set($name, $value)
public function set(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}
@ -61,7 +61,7 @@ class FrozenParameterBag extends ParameterBag
/**
* {@inheritdoc}
*/
public function remove($name)
public function remove(string $name)
{
throw new LogicException('Impossible to call remove() on a frozen ParameterBag.');
}

View File

@ -64,10 +64,8 @@ class ParameterBag implements ParameterBagInterface
/**
* {@inheritdoc}
*/
public function get($name)
public function get(string $name)
{
$name = (string) $name;
if (!\array_key_exists($name, $this->parameters)) {
if (!$name) {
throw new ParameterNotFoundException($name);
@ -109,15 +107,15 @@ class ParameterBag implements ParameterBagInterface
* @param string $name The parameter name
* @param mixed $value The parameter value
*/
public function set($name, $value)
public function set(string $name, $value)
{
$this->parameters[(string) $name] = $value;
$this->parameters[$name] = $value;
}
/**
* {@inheritdoc}
*/
public function has($name)
public function has(string $name)
{
return \array_key_exists((string) $name, $this->parameters);
}
@ -127,9 +125,9 @@ class ParameterBag implements ParameterBagInterface
*
* @param string $name The parameter name
*/
public function remove($name)
public function remove(string $name)
{
unset($this->parameters[(string) $name]);
unset($this->parameters[$name]);
}
/**
@ -190,8 +188,7 @@ class ParameterBag implements ParameterBagInterface
/**
* Resolves parameters inside a string.
*
* @param string $value The string to resolve
* @param array $resolving An array of keys that are being resolved (used internally to detect circular references)
* @param array $resolving An array of keys that are being resolved (used internally to detect circular references)
*
* @return string The resolved string
*
@ -199,7 +196,7 @@ class ParameterBag implements ParameterBagInterface
* @throws ParameterCircularReferenceException if a circular reference if detected
* @throws RuntimeException when a given parameter has a type problem
*/
public function resolveString($value, array $resolving = [])
public function resolveString(string $value, array $resolving = [])
{
// we do this to deal with non string values (Boolean, integer, ...)
// as the preg_replace_callback throw an exception when trying

View File

@ -47,39 +47,32 @@ interface ParameterBagInterface
/**
* Gets a service container parameter.
*
* @param string $name The parameter name
*
* @return mixed The parameter value
*
* @throws ParameterNotFoundException if the parameter is not defined
*/
public function get($name);
public function get(string $name);
/**
* Removes a parameter.
*
* @param string $name The parameter name
*/
public function remove($name);
public function remove(string $name);
/**
* Sets a service container parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
* @param mixed $value The parameter value
*
* @throws LogicException if the parameter can not be set
*/
public function set($name, $value);
public function set(string $name, $value);
/**
* Returns true if a parameter name is defined.
*
* @param string $name The parameter name
*
* @return bool true if the parameter name is defined, false otherwise
*/
public function has($name);
public function has(string $name);
/**
* Replaces parameter placeholders (%name%) by their values for all parameters.

View File

@ -31,7 +31,7 @@ final class ReverseContainer
$this->serviceContainer = $serviceContainer;
$this->reversibleLocator = $reversibleLocator;
$this->tagName = $tagName;
$this->getServiceId = \Closure::bind(function ($service): ?string {
$this->getServiceId = \Closure::bind(function (object $service): ?string {
return array_search($service, $this->services, true) ?: array_search($service, $this->privates, true) ?: null;
}, $serviceContainer, Container::class);
}
@ -40,10 +40,8 @@ final class ReverseContainer
* Returns the id of the passed object when it exists as a service.
*
* To be reversible, services need to be either public or be tagged with "container.reversible".
*
* @param object $service
*/
public function getId($service): ?string
public function getId(object $service): ?string
{
if ($this->serviceContainer === $service) {
return 'service_container';

View File

@ -57,7 +57,7 @@ class ServiceLocator implements ServiceProviderInterface
}
}
public function __invoke($id)
public function __invoke(string $id)
{
return isset($this->factories[$id]) ? $this->get($id) : null;
}
@ -65,7 +65,7 @@ class ServiceLocator implements ServiceProviderInterface
/**
* @internal
*/
public function withContext($externalId, Container $container)
public function withContext(string $externalId, Container $container)
{
$locator = clone $this;
$locator->externalId = $externalId;

View File

@ -25,5 +25,5 @@ interface TaggedContainerInterface extends ContainerInterface
*
* @return array An array of tags
*/
public function findTaggedServiceIds($name);
public function findTaggedServiceIds(string $name);
}

View File

@ -75,7 +75,7 @@ class RegisterEnvVarProcessorsPassTest extends TestCase
class SimpleProcessor implements EnvVarProcessorInterface
{
public function getEnv($prefix, $name, \Closure $getEnv)
public function getEnv(string $prefix, string $name, \Closure $getEnv)
{
return $getEnv($name);
}

View File

@ -327,8 +327,8 @@ class ContainerBuilderTest extends TestCase
$builder->register('bar', 'stdClass');
$this->assertFalse($builder->hasAlias('bar'));
$builder->set('foobar', 'stdClass');
$builder->set('moo', 'stdClass');
$builder->set('foobar', new \stdClass());
$builder->set('moo', new \stdClass());
$this->assertCount(2, $builder->getAliases(), '->getAliases() does not return aliased services that have been overridden');
}

View File

@ -187,7 +187,7 @@ class ContainerTest extends TestCase
{
$sc = new Container();
$sc->set('foo', new \stdClass());
$sc->get('foo', null);
$sc->get('foo');
$sc->set('foo', null);
$this->assertFalse($sc->has('foo'), '->set() with null service resets the service');

View File

@ -28,18 +28,6 @@ class DefinitionTest extends TestCase
$this->assertEquals(['foo'], $def->getArguments(), '__construct() takes an optional array of arguments as its second argument');
}
/**
* @group legacy
* @expectedDeprecation Passing an instance of Symfony\Component\DependencyInjection\Parameter as class name to Symfony\Component\DependencyInjection\Definition in deprecated in Symfony 4.4 and will result in a TypeError in 5.0. Please pass the string "%parameter%" instead.
*/
public function testConstructorWithParameter()
{
$parameter = new Parameter('parameter');
$def = new Definition($parameter);
$this->assertSame($parameter, $def->getClass(), '__construct() accepts Parameter instances');
}
public function testSetGetFactory()
{
$def = new Definition();
@ -62,28 +50,6 @@ class DefinitionTest extends TestCase
$this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
}
/**
* @group legacy
* @expectedDeprecation Passing an instance of Symfony\Component\DependencyInjection\Parameter as class name to Symfony\Component\DependencyInjection\Definition in deprecated in Symfony 4.4 and will result in a TypeError in 5.0. Please pass the string "%parameter%" instead.
*/
public function testSetGetClassWithParameter()
{
$def = new Definition();
$parameter = new Parameter('parameter');
$this->assertSame($parameter, $def->setClass($parameter)->getClass(), '->getClass() returns the parameterized class name');
}
/**
* @group legacy
* @expectedDeprecation The class name passed to Symfony\Component\DependencyInjection\Definition is expected to be a string. Passing a stdClass is deprecated in Symfony 4.4 and will result in a TypeError in 5.0.
*/
public function testSetGetClassWithObject()
{
$def = new Definition();
$classObject = new \stdClass();
$this->assertSame($classObject, $def->setClass($classObject)->getClass(), '->getClass() returns the parameterized class name');
}
public function testSetGetDecoratedService()
{
$def = new Definition('stdClass');

View File

@ -1251,7 +1251,7 @@ class PhpDumperTest extends TestCase
class Rot13EnvVarProcessor implements EnvVarProcessorInterface
{
public function getEnv($prefix, $name, \Closure $getEnv)
public function getEnv(string $prefix, string $name, \Closure $getEnv)
{
return str_rot13($getEnv($name));
}

View File

@ -59,10 +59,8 @@ class ProjectServiceContainer extends Container
return $this->services['test'] = new \stdClass(['only dot' => '.', 'concatenation as value' => '.\'\'.', 'concatenation from the start value' => '\'\'.', '.' => 'dot as a key', '.\'\'.' => 'concatenation as a key', '\'\'.' => 'concatenation from the start key', 'optimize concatenation' => 'string1-string2', 'optimize concatenation with empty string' => 'string1string2', 'optimize concatenation from the start' => 'start', 'optimize concatenation at the end' => 'end', 'new line' => 'string with '."\n".'new line']);
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -73,14 +71,12 @@ class ProjectServiceContainer extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -63,10 +63,8 @@ class ProjectServiceContainer extends Container
return $this->services['test'] = new \stdClass(('wiz'.$this->targetDirs[1]), [('wiz'.$this->targetDirs[1]) => ($this->targetDirs[2].'/')]);
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -77,14 +75,12 @@ class ProjectServiceContainer extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -74,10 +74,8 @@ class ProjectServiceContainer extends Container
return $instance;
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -88,14 +86,12 @@ class ProjectServiceContainer extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -74,10 +74,8 @@ class Symfony_DI_PhpDumper_Test_EnvParameters extends Container
return $this->services['test'] = new ${($_ = $this->getEnv('FOO')) && false ?: "_"}($this->getEnv('Bar'), 'foo'.$this->getEnv('string:FOO').'baz', $this->getEnv('int:Baz'));
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -88,14 +86,12 @@ class Symfony_DI_PhpDumper_Test_EnvParameters extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -46,10 +46,8 @@ class ProjectServiceContainer extends Container
];
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -60,14 +58,12 @@ class ProjectServiceContainer extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -462,9 +462,8 @@ class ProjectServiceContainer extends Container
return $instance;
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (isset($this->buildParameters[$name])) {
return $this->buildParameters[$name];
}
@ -479,9 +478,8 @@ class ProjectServiceContainer extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
if (isset($this->buildParameters[$name])) {
return true;
}
@ -489,7 +487,7 @@ class ProjectServiceContainer extends Container
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -409,10 +409,8 @@ class ProjectServiceContainer extends Container
return new \SimpleFactoryClass('foo');
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -423,14 +421,12 @@ class ProjectServiceContainer extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -67,10 +67,8 @@ class ProjectServiceContainer extends Container
return $instance;
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -81,14 +79,12 @@ class ProjectServiceContainer extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -46,10 +46,8 @@ class Symfony_DI_PhpDumper_Test_Base64Parameters extends Container
];
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -60,14 +58,12 @@ class Symfony_DI_PhpDumper_Test_Base64Parameters extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -46,10 +46,8 @@ class Symfony_DI_PhpDumper_Test_CsvParameters extends Container
];
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -60,14 +58,12 @@ class Symfony_DI_PhpDumper_Test_CsvParameters extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -46,10 +46,8 @@ class Symfony_DI_PhpDumper_Test_DefaultParameters extends Container
];
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -60,14 +58,12 @@ class Symfony_DI_PhpDumper_Test_DefaultParameters extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -72,10 +72,8 @@ class ProjectServiceContainer extends Container
return $this->services['foo'] = new \stdClass(($this->privates['bar_%env(BAR)%'] ?? ($this->privates['bar_%env(BAR)%'] = new \stdClass())), ['baz_'.$this->getEnv('string:BAR') => new \stdClass()]);
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -86,14 +84,12 @@ class ProjectServiceContainer extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -409,10 +409,8 @@ class Symfony_DI_PhpDumper_Errored_Definition extends Container
return new \SimpleFactoryClass('foo');
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -423,14 +421,12 @@ class Symfony_DI_PhpDumper_Errored_Definition extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -96,10 +96,8 @@ class ProjectServiceContainer extends Container
return $this->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C2'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2(new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3());
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -110,14 +108,12 @@ class ProjectServiceContainer extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -46,10 +46,8 @@ class Symfony_DI_PhpDumper_Test_JsonParameters extends Container
];
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -60,14 +58,12 @@ class Symfony_DI_PhpDumper_Test_JsonParameters extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -46,10 +46,8 @@ class Symfony_DI_PhpDumper_Test_QueryStringParameters extends Container
];
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -60,14 +58,12 @@ class Symfony_DI_PhpDumper_Test_QueryStringParameters extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -77,10 +77,8 @@ class Symfony_DI_PhpDumper_Test_Rot13Parameters extends Container
]);
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -91,14 +89,12 @@ class Symfony_DI_PhpDumper_Test_Rot13Parameters extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -81,10 +81,8 @@ class Symfony_DI_PhpDumper_Test_Unsupported_Characters extends Container
return $this->services['foo*/oh-no'] = new \FooClass();
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -95,14 +93,12 @@ class Symfony_DI_PhpDumper_Test_Unsupported_Characters extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}

View File

@ -46,10 +46,8 @@ class Symfony_DI_PhpDumper_Test_UrlParameters extends Container
];
}
public function getParameter($name)
public function getParameter(string $name)
{
$name = (string) $name;
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}
@ -60,14 +58,12 @@ class Symfony_DI_PhpDumper_Test_UrlParameters extends Container
return $this->parameters[$name];
}
public function hasParameter($name)
public function hasParameter(string $name)
{
$name = (string) $name;
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
}