Skip to content

Commit d8599bd

Browse files
committed
refactor: ♻️ Simplify the reconciliation logic
1 parent f582f14 commit d8599bd

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

modules/ppcp-store-sync/src/Registration/ReconciliationService.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,21 @@ public function reconcile(): void {
4141
$desired = $this->settings->should_initialize_features();
4242
$actual = $this->registration->is_registered();
4343

44-
if ( $desired && ! $actual ) {
45-
if ( $this->should_auto_register() ) {
46-
$this->register();
47-
}
48-
} elseif ( ! $desired && $actual ) {
44+
// State has not changed, do nothing.
45+
if ( $desired === $actual ) {
46+
return;
47+
}
48+
49+
// Integration was disabled, clean up and unregister.
50+
if ( ! $desired ) {
4951
$this->registration->deregister();
52+
53+
return;
54+
}
55+
56+
// Integration is enabled, let's check te auto-register flag before acting.
57+
if ( $this->should_auto_register() ) {
58+
$this->register();
5059
}
5160
}
5261

0 commit comments

Comments
 (0)