Skip to content

Commit

Permalink
Refactor + comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaGallinari committed Dec 11, 2023
1 parent 8b92902 commit df4ff0b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Command/ServiceChangesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
continue;
}

$definitionClass = $definition->getClass();
if (!is_string($definitionClass)) {
continue;
}

$aliasNormalized = strtolower($alias);
// ignore repositories and controllers 'cause they are magically registered
if (str_contains($aliasNormalized, 'repository') || str_contains($aliasNormalized, 'controller')) {
continue;
}

// the new service must be an "App" service
if (!str_starts_with($definitionClass, sprintf('%s\\', $this->namespacePrefix))) {
// this internal service class could have been replaced with an "App" class even though the original service alias is still untouched
$definitionClass = $definition->getClass();
if (!is_string($definitionClass)) {
continue;
}

// todo: search in $decoratedDefintions by alias?
if (!str_starts_with($definitionClass, sprintf('%s\\', $this->namespacePrefix))) {
// it could happen that the definition class of the decorating service is an "App" class,
// but it still be defined with original service class and alias..
// todo: i cannot find a way to test this case
$decoratedDef = $decoratedDefintions[$definitionClass]['definition'] ?? null;
if (!$decoratedDef) {
continue;
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/config/services_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ services:
decorates: sylius.customer_unique_address_adder



## test_it_detects_with_decorated_definition_strategy_those_decorated_services_that_changed
webgriffe_sylius_upgrade.service_changes_command.test_it_detects_with_decorated_definition_strategy_those_decorated_services_that_changed.decorate_province_naming_provider:
public: true
Expand All @@ -67,6 +68,7 @@ services:
- '@.inner'



## test_it_detects_with_alias_strategy_those_decorated_services_that_changed
webgriffe_sylius_upgrade.service_changes_command.test_it_detects_with_alias_strategy_those_decorated_services_that_changed.decorate_send_order_confirmation:
class: Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\test_it_detects_with_alias_strategy_those_decorated_services_that_changed\DecorateSendOrderConfirmationHandler
Expand Down

0 comments on commit df4ff0b

Please sign in to comment.