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

Skip to content

Commit 9024c07

Browse files
vicbfabpot
authored andcommitted
[2.3] [DI] Improve the generated PHPDoc of the dumped PHP container
1 parent 8a351f0 commit 9024c07

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,19 +441,30 @@ private function addService($id, $definition)
441441
$this->referenceVariables = array();
442442
$this->variableCount = 0;
443443

444-
$return = '';
444+
$return = array();
445+
445446
if ($definition->isSynthetic()) {
446-
$return = sprintf('@throws RuntimeException always since this service is expected to be injected dynamically');
447+
$return[] = '@throws RuntimeException always since this service is expected to be injected dynamically';
447448
} elseif ($class = $definition->getClass()) {
448-
$return = sprintf("@return %s A %s instance.", 0 === strpos($class, '%') ? 'Object' : $class, $class);
449+
$return[] = sprintf("@return %s A %s instance.", 0 === strpos($class, '%') ? 'object' : $class, $class);
449450
} elseif ($definition->getFactoryClass()) {
450-
$return = sprintf('@return Object An instance returned by %s::%s().', $definition->getFactoryClass(), $definition->getFactoryMethod());
451+
$return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryClass(), $definition->getFactoryMethod());
451452
} elseif ($definition->getFactoryService()) {
452-
$return = sprintf('@return Object An instance returned by %s::%s().', $definition->getFactoryService(), $definition->getFactoryMethod());
453+
$return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryService(), $definition->getFactoryMethod());
454+
}
455+
456+
$scope = $definition->getScope();
457+
if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) {
458+
if ($return && 0 === strpos($return[count($return) - 1], '@return')) {
459+
$return[] = '';
460+
}
461+
$return[] = sprintf("@throws InactiveScopeException when the '%s' service is requested while the '%s' scope is not active", $id, $scope);
453462
}
454463

464+
$return = implode("\n * ", $return);
465+
455466
$doc = '';
456-
if (ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope()) {
467+
if (ContainerInterface::SCOPE_PROTOTYPE !== $scope) {
457468
$doc .= <<<EOF
458469
459470
*
@@ -484,8 +495,7 @@ protected function get{$name}Service()
484495
485496
EOF;
486497

487-
$scope = $definition->getScope();
488-
if (ContainerInterface::SCOPE_CONTAINER !== $scope && ContainerInterface::SCOPE_PROTOTYPE !== $scope) {
498+
if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) {
489499
$code .= <<<EOF
490500
if (!isset(\$this->scopedServices['$scope'])) {
491501
throw new InactiveScopeException('$id', '$scope');

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected function getFooService()
102102
* This service is shared.
103103
* This method always returns the same instance of the service.
104104
*
105-
* @return Object A %baz_class% instance.
105+
* @return object A %baz_class% instance.
106106
*/
107107
protected function getFoo_BazService()
108108
{
@@ -116,7 +116,7 @@ protected function getFoo_BazService()
116116
/**
117117
* Gets the 'foo_bar' service.
118118
*
119-
* @return Object A %foo_class% instance.
119+
* @return object A %foo_class% instance.
120120
*/
121121
protected function getFooBarService()
122122
{

0 commit comments

Comments
 (0)