Skip to content

Commit cef12ac

Browse files
committed
User: deduplicated lazy-loading of stored data
1 parent b0deda3 commit cef12ac

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/Security/User.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ final public function logout(bool $clearIdentity = false): void
133133
*/
134134
final public function isLoggedIn(): bool
135135
{
136-
if ($this->authenticated === null) {
137-
$this->getStoredData();
138-
}
139-
136+
$this->loadStoredData();
140137
return (bool) $this->authenticated;
141138
}
142139

@@ -147,16 +144,17 @@ final public function isLoggedIn(): bool
147144
*/
148145
final public function getIdentity(): ?IIdentity
149146
{
150-
if ($this->authenticated === null) {
151-
$this->getStoredData();
152-
}
153-
147+
$this->loadStoredData();
154148
return $this->identity;
155149
}
156150

157151

158-
private function getStoredData(): void
152+
private function loadStoredData(): void
159153
{
154+
if ($this->authenticated !== null) {
155+
return;
156+
}
157+
160158
(function (bool $state, ?IIdentity $id, ?int $reason) use (&$identity) {
161159
$identity = $id;
162160
$this->authenticated = $state;

0 commit comments

Comments
 (0)