From f5c88ab8c069347103ac8b253e21af70dce9dd7e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 08:56:38 +0000 Subject: [PATCH 1/3] Initial plan From dec88a78fd471f37f60fafd2ebb21c950f01a47f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 09:14:23 +0000 Subject: [PATCH 2/3] Add support for fieldMap with dot notation and corresponding test Co-authored-by: ADmad <142658+ADmad@users.noreply.github.com> --- src/Identity.php | 6 ++++++ tests/TestCase/IdentityTest.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/Identity.php b/src/Identity.php index 18d5281b..42111977 100644 --- a/src/Identity.php +++ b/src/Identity.php @@ -109,6 +109,12 @@ public function get(?string $field = null): mixed $map = $this->_config['fieldMap']; if (isset($map[$field])) { $field = $map[$field]; + } else { + // Check if the first segment of a dot-separated path has a mapping + $parts = explode('.', $field, 2); + if (count($parts) > 1 && isset($map[$parts[0]])) { + $field = $map[$parts[0]] . '.' . $parts[1]; + } } return Hash::get($this->data, $field); diff --git a/tests/TestCase/IdentityTest.php b/tests/TestCase/IdentityTest.php index 4f8ba363..6b13070e 100644 --- a/tests/TestCase/IdentityTest.php +++ b/tests/TestCase/IdentityTest.php @@ -61,6 +61,39 @@ public function testGet(): void $this->assertSame($data, $identity->get()); } + /** + * Test field mapping with dot notation + * + * @return void + */ + public function testFieldMappingWithDotNotation(): void + { + $data = [ + 'id' => 1, + 'user_account' => new Entity(['id' => 2, 'role' => 'admin']), + 'profile_data' => ['email' => 'test@example.com', 'preferences' => ['theme' => 'dark']], + ]; + + $identity = new Identity($data, [ + 'fieldMap' => [ + 'account' => 'user_account', + 'profile' => 'profile_data', + ], + ]); + + // Test that fieldMap works with dot notation for nested access + $this->assertSame('admin', $identity->get('account.role')); + $this->assertSame('test@example.com', $identity->get('profile.email')); + $this->assertSame('dark', $identity->get('profile.preferences.theme')); + + // Test that original field names still work with dot notation + $this->assertSame('admin', $identity->get('user_account.role')); + $this->assertSame('test@example.com', $identity->get('profile_data.email')); + + // Test that non-mapped fields with dot notation still work + $this->assertNull($identity->get('missing.field')); + } + /** * Test mapping fields * From 05fbe76e504b777ac020f1521e4c228e4b432f2e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 09:16:10 +0000 Subject: [PATCH 3/3] Address code review feedback: simplify condition and add direct access tests Co-authored-by: ADmad <142658+ADmad@users.noreply.github.com> --- src/Identity.php | 2 +- tests/TestCase/IdentityTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Identity.php b/src/Identity.php index 42111977..1f005160 100644 --- a/src/Identity.php +++ b/src/Identity.php @@ -112,7 +112,7 @@ public function get(?string $field = null): mixed } else { // Check if the first segment of a dot-separated path has a mapping $parts = explode('.', $field, 2); - if (count($parts) > 1 && isset($map[$parts[0]])) { + if (isset($parts[1]) && isset($map[$parts[0]])) { $field = $map[$parts[0]] . '.' . $parts[1]; } } diff --git a/tests/TestCase/IdentityTest.php b/tests/TestCase/IdentityTest.php index 6b13070e..9e007782 100644 --- a/tests/TestCase/IdentityTest.php +++ b/tests/TestCase/IdentityTest.php @@ -81,6 +81,10 @@ public function testFieldMappingWithDotNotation(): void ], ]); + // Test that mapped fields can be accessed directly + $this->assertInstanceOf(Entity::class, $identity->get('account')); + $this->assertSame(['email' => 'test@example.com', 'preferences' => ['theme' => 'dark']], $identity->get('profile')); + // Test that fieldMap works with dot notation for nested access $this->assertSame('admin', $identity->get('account.role')); $this->assertSame('test@example.com', $identity->get('profile.email'));