minor #39292 [DependencyInjection] Add missing parameter type declarations to loader classes (derrabus)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[DependencyInjection] Add missing parameter type declarations to loader classes

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

This PR adds missing parameter type declarations to the loader classes of the DI component. We initially omitted them in order to stay compatible to the Config component of 4.4. But that compatibility was dropped afterwards and we somehow forgot to add the types here.

Commits
-------

de0dbd88d2 [DependencyInjection] Add missing parameter type declarations to loader classes.
This commit is contained in:
Fabien Potencier 2020-12-05 16:47:19 +01:00
commit 751352c741
6 changed files with 8 additions and 10 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
$this->load('container1.php', $container); $this->load('container1.php');
$container->loadFromExtension('security', [ $container->loadFromExtension('security', [
'encoders' => [ 'encoders' => [

View File

@ -1,6 +1,6 @@
<?php <?php
$this->load('container1.php', $container); $this->load('container1.php');
$container->loadFromExtension('security', [ $container->loadFromExtension('security', [
'encoders' => [ 'encoders' => [

View File

@ -1,6 +1,6 @@
<?php <?php
$this->load('container1.php', $container); $this->load('container1.php');
$container->loadFromExtension('security', [ $container->loadFromExtension('security', [
'encoders' => [ 'encoders' => [

View File

@ -50,7 +50,7 @@ abstract class FileLoader extends BaseFileLoader
* *
* @param bool|string $ignoreErrors Whether errors should be ignored; pass "not_found" to ignore only when the loaded resource is not found * @param bool|string $ignoreErrors Whether errors should be ignored; pass "not_found" to ignore only when the loaded resource is not found
*/ */
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null, $exclude = null) public function import($resource, string $type = null, $ignoreErrors = false, string $sourceResource = null, $exclude = null)
{ {
$args = \func_get_args(); $args = \func_get_args();
@ -87,7 +87,7 @@ abstract class FileLoader extends BaseFileLoader
* @param string $resource The directory to look for classes, glob-patterns allowed * @param string $resource The directory to look for classes, glob-patterns allowed
* @param string|string[]|null $exclude A globbed path of files to exclude or an array of globbed paths of files to exclude * @param string|string[]|null $exclude A globbed path of files to exclude or an array of globbed paths of files to exclude
*/ */
public function registerClasses(Definition $prototype, $namespace, $resource, $exclude = null) public function registerClasses(Definition $prototype, string $namespace, string $resource, $exclude = null)
{ {
if ('\\' !== substr($namespace, -1)) { if ('\\' !== substr($namespace, -1)) {
throw new InvalidArgumentException(sprintf('Namespace prefix must end with a "\\": "%s".', $namespace)); throw new InvalidArgumentException(sprintf('Namespace prefix must end with a "\\": "%s".', $namespace));
@ -134,10 +134,8 @@ abstract class FileLoader extends BaseFileLoader
/** /**
* Registers a definition in the container with its instanceof-conditionals. * Registers a definition in the container with its instanceof-conditionals.
*
* @param string $id
*/ */
protected function setDefinition($id, Definition $definition) protected function setDefinition(string $id, Definition $definition)
{ {
$this->container->removeBindings($id); $this->container->removeBindings($id);

View File

@ -28,7 +28,7 @@ class PhpFileLoader extends FileLoader
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function load($resource, $type = null) public function load($resource, string $type = null)
{ {
// the container and loader variables are exposed to the included file below // the container and loader variables are exposed to the included file below
$container = $this->container; $container = $this->container;

View File

@ -38,7 +38,7 @@ class GlobFileLoaderTest extends TestCase
class GlobFileLoaderWithoutImport extends GlobFileLoader class GlobFileLoaderWithoutImport extends GlobFileLoader
{ {
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null, $exclude = null) public function import($resource, string $type = null, $ignoreErrors = false, string $sourceResource = null, $exclude = null)
{ {
} }
} }