Skip to content

Commit

Permalink
Make ThriftContextPropState::getPrivacyUniverse private
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Joel Krebs authored and facebook-github-bot committed Jan 14, 2025
1 parent b742ec2 commit 187238d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
9 changes: 8 additions & 1 deletion thrift/lib/hack/src/ThriftContextPropState.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,14 @@ public function setExperimentIds(vec<int> $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;
}

Expand Down
5 changes: 3 additions & 2 deletions thrift/lib/hack/src/__tests__/ThriftContextPropStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getExperimentIds()[]: vec<int> {
}

public function getPrivacyUniverse()[]: ?int {
return $this->state->getPrivacyUniverse();
return $this->state->getPrivacyUniverseDesignator()?->getValue();
}

public function getRequestPriority()[]: ?RequestPriority {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ classname<IThriftClient> $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(
Expand Down

0 comments on commit 187238d

Please sign in to comment.