minor #23613 [DI] Remove unused props from the PhpDumper (dunglas)

This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #23613).

Discussion
----------

[DI] Remove unused props from the PhpDumper

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | no
| New feature?  | no <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Commits
-------

f1aa45c [DI] Remove unused props from the PhpDumper
This commit is contained in:
Nicolas Grekas 2017-07-28 10:50:39 +02:00
commit 27a6c1f604
1 changed files with 14 additions and 17 deletions

View File

@ -255,12 +255,11 @@ class PhpDumper extends Dumper
/**
* Generates the require_once statement for service includes.
*
* @param string $id The service id
* @param Definition $definition
*
* @return string
*/
private function addServiceInclude($id, $definition)
private function addServiceInclude($definition)
{
$template = " require_once %s;\n";
$code = '';
@ -335,9 +334,9 @@ class PhpDumper extends Dumper
$code .= $this->addNewInstance($id, $sDefinition, '$'.$name, ' = ');
if (!$this->hasReference($id, $sDefinition->getMethodCalls(), true) && !$this->hasReference($id, $sDefinition->getProperties(), true)) {
$code .= $this->addServiceProperties(null, $sDefinition, $name);
$code .= $this->addServiceMethodCalls(null, $sDefinition, $name);
$code .= $this->addServiceConfigurator(null, $sDefinition, $name);
$code .= $this->addServiceProperties($sDefinition, $name);
$code .= $this->addServiceMethodCalls($sDefinition, $name);
$code .= $this->addServiceConfigurator($sDefinition, $name);
}
$code .= "\n";
@ -437,13 +436,12 @@ class PhpDumper extends Dumper
/**
* Adds method calls to a service definition.
*
* @param string $id
* @param Definition $definition
* @param string $variableName
*
* @return string
*/
private function addServiceMethodCalls($id, Definition $definition, $variableName = 'instance')
private function addServiceMethodCalls(Definition $definition, $variableName = 'instance')
{
$calls = '';
foreach ($definition->getMethodCalls() as $call) {
@ -458,7 +456,7 @@ class PhpDumper extends Dumper
return $calls;
}
private function addServiceProperties($id, Definition $definition, $variableName = 'instance')
private function addServiceProperties(Definition $definition, $variableName = 'instance')
{
$code = '';
foreach ($definition->getProperties() as $name => $value) {
@ -501,9 +499,9 @@ class PhpDumper extends Dumper
}
$name = (string) $this->definitionVariables->offsetGet($iDefinition);
$code .= $this->addServiceProperties(null, $iDefinition, $name);
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
$code .= $this->addServiceConfigurator(null, $iDefinition, $name);
$code .= $this->addServiceProperties($iDefinition, $name);
$code .= $this->addServiceMethodCalls($iDefinition, $name);
$code .= $this->addServiceConfigurator($iDefinition, $name);
}
if ('' !== $code) {
@ -516,13 +514,12 @@ class PhpDumper extends Dumper
/**
* Adds configurator definition.
*
* @param string $id
* @param Definition $definition
* @param string $variableName
*
* @return string
*/
private function addServiceConfigurator($id, Definition $definition, $variableName = 'instance')
private function addServiceConfigurator(Definition $definition, $variableName = 'instance')
{
if (!$callable = $definition->getConfigurator()) {
return '';
@ -633,14 +630,14 @@ EOF;
$code .= sprintf(" throw new RuntimeException('You have requested a synthetic service (\"%s\"). The DIC does not know how to construct this service.');\n }\n", $id);
} else {
$code .=
$this->addServiceInclude($id, $definition).
$this->addServiceInclude($definition).
$this->addServiceLocalTempVariables($id, $definition).
$this->addServiceInlinedDefinitions($id, $definition).
$this->addServiceInstance($id, $definition).
$this->addServiceInlinedDefinitionsSetup($id, $definition).
$this->addServiceProperties($id, $definition).
$this->addServiceMethodCalls($id, $definition).
$this->addServiceConfigurator($id, $definition).
$this->addServiceProperties($definition).
$this->addServiceMethodCalls($definition).
$this->addServiceConfigurator($definition).
$this->addServiceReturn($id, $definition)
;
}