From 187238dff737faab3d8d9ddce2f40a49fdfbf9d9 Mon Sep 17 00:00:00 2001 From: Joel Krebs Date: Tue, 14 Jan 2025 07:11:05 -0800 Subject: [PATCH] Make ThriftContextPropState::getPrivacyUniverse private Summary: People should rarely code against the raw universe designator value. Instead they should code against the wrapper and in fact many callers already do that. So let's just make this explicit by making the raw getter private. Reviewed By: gkunasag-fb Differential Revision: D68153213 fbshipit-source-id: 9915466fa042281245b9b61f1acb86d470634a82 --- thrift/lib/hack/src/ThriftContextPropState.php | 9 ++++++++- .../hack/src/__tests__/ThriftContextPropStateTest.php | 5 +++-- .../src/contextprop/ImmutableThriftContextPropState.php | 2 +- .../__tests__/UpdateUniverseContextHandlerTest.php | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/thrift/lib/hack/src/ThriftContextPropState.php b/thrift/lib/hack/src/ThriftContextPropState.php index a3d57884728..40ede8e6316 100644 --- a/thrift/lib/hack/src/ThriftContextPropState.php +++ b/thrift/lib/hack/src/ThriftContextPropState.php @@ -315,7 +315,14 @@ public function setExperimentIds(vec $eids)[write_props]: void { $this->dirty(); } - public function getPrivacyUniverse()[]: ?int { + /** + * This should not be exposed publicly, and instead call + * getPrivacyUniverseDesignator + * + * @return the raw privacy universe as an int. + * @see getPrivacyUniverseDesignator + */ + private function getPrivacyUniverse()[]: ?int { return $this->storage->privacyUniverse; } diff --git a/thrift/lib/hack/src/__tests__/ThriftContextPropStateTest.php b/thrift/lib/hack/src/__tests__/ThriftContextPropStateTest.php index b905baa8542..60073c79f7e 100644 --- a/thrift/lib/hack/src/__tests__/ThriftContextPropStateTest.php +++ b/thrift/lib/hack/src/__tests__/ThriftContextPropStateTest.php @@ -105,9 +105,10 @@ public function testTraceContext(): void { public function testPrivacyUniverse(): void { $tcps = ThriftContextPropState::get(); - expect($tcps->getPrivacyUniverse())->toBeNull(); + expect($tcps->getPrivacyUniverseDesignator())->toBeNull(); $tcps->setPrivacyUniverse(123); - expect($tcps->getPrivacyUniverse())->toEqual(123); + expect($tcps->getPrivacyUniverseDesignator()?->getValue())->toNotBeNullAnd() + ->toEqual(123); } public function testInitialization()[defaults]: void { diff --git a/thrift/lib/hack/src/contextprop/ImmutableThriftContextPropState.php b/thrift/lib/hack/src/contextprop/ImmutableThriftContextPropState.php index 349b6b01a05..ab7e517b388 100644 --- a/thrift/lib/hack/src/contextprop/ImmutableThriftContextPropState.php +++ b/thrift/lib/hack/src/contextprop/ImmutableThriftContextPropState.php @@ -57,7 +57,7 @@ public function getExperimentIds()[]: vec { } public function getPrivacyUniverse()[]: ?int { - return $this->state->getPrivacyUniverse(); + return $this->state->getPrivacyUniverseDesignator()?->getValue(); } public function getRequestPriority()[]: ?RequestPriority { diff --git a/thrift/lib/hack/src/contextprop/__tests__/UpdateUniverseContextHandlerTest.php b/thrift/lib/hack/src/contextprop/__tests__/UpdateUniverseContextHandlerTest.php index c3e7d4e484c..b0f4ee5a979 100644 --- a/thrift/lib/hack/src/contextprop/__tests__/UpdateUniverseContextHandlerTest.php +++ b/thrift/lib/hack/src/contextprop/__tests__/UpdateUniverseContextHandlerTest.php @@ -184,7 +184,7 @@ classname $thrift_service_name, private function assertNullUniverse(): void { $context_prop_state = ThriftContextPropState::get(); expect($context_prop_state)->toNotBeNull(); - expect($context_prop_state->getPrivacyUniverse())->toBeNull(); + expect($context_prop_state->getPrivacyUniverseDesignator())->toBeNull(); } private function assertUniverse(