Skip to content

Commit 2a1b503

Browse files
authored
Use static return type in OTPHP\OTP (#265)
The new immutable interface was leading to type confusion, by having the common methods in OTP return static instead of self, PHP and static analyzers like PHPStan will understand that they are still working with a TOTP or HOTP class, rather than get confused and think we're operating on the underlying OTP class. Closes: #263
1 parent 126c99b commit 2a1b503

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/OTP.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function setLabel(string $label): void
102102
$this->setParameter('label', $label);
103103
}
104104

105-
public function withLabel(string $label): self
105+
public function withLabel(string $label): static
106106
{
107107
$otp = clone $this;
108108
$otp->setParameter('label', $label);
@@ -120,7 +120,7 @@ public function setIssuer(string $issuer): void
120120
$this->setParameter('issuer', $issuer);
121121
}
122122

123-
public function withIssuer(string $issuer): self
123+
public function withIssuer(string $issuer): static
124124
{
125125
$otp = clone $this;
126126
$otp->setParameter('issuer', $issuer);
@@ -138,7 +138,7 @@ public function setIssuerIncludedAsParameter(bool $issuer_included_as_parameter)
138138
$this->issuer_included_as_parameter = $issuer_included_as_parameter;
139139
}
140140

141-
public function withIssuerIncludedAsParameter(bool $issuer_included_as_parameter): self
141+
public function withIssuerIncludedAsParameter(bool $issuer_included_as_parameter): static
142142
{
143143
$otp = clone $this;
144144
$otp->issuer_included_as_parameter = $issuer_included_as_parameter;
@@ -200,7 +200,7 @@ public function setParameter(string $parameter, mixed $value): void
200200
}
201201
}
202202

203-
public function withParameter(string $parameter, mixed $value): self
203+
public function withParameter(string $parameter, mixed $value): static
204204
{
205205
$otp = clone $this;
206206
$otp->setParameter($parameter, $value);
@@ -213,7 +213,7 @@ public function setSecret(string $secret): void
213213
$this->setParameter('secret', $secret);
214214
}
215215

216-
public function withSecret(string $secret): self
216+
public function withSecret(string $secret): static
217217
{
218218
$otp = clone $this;
219219
$otp->setParameter('secret', $secret);
@@ -226,7 +226,7 @@ public function setDigits(int $digits): void
226226
$this->setParameter('digits', $digits);
227227
}
228228

229-
public function withDigits(int $digits): self
229+
public function withDigits(int $digits): static
230230
{
231231
$otp = clone $this;
232232
$otp->setParameter('digits', $digits);
@@ -239,7 +239,7 @@ public function setDigest(string $digest): void
239239
$this->setParameter('algorithm', $digest);
240240
}
241241

242-
public function withDigest(string $digest): self
242+
public function withDigest(string $digest): static
243243
{
244244
$otp = clone $this;
245245
$otp->setParameter('algorithm', $digest);

0 commit comments

Comments
 (0)