Skip to content

Commit 5256702

Browse files
authored
Optimized codes (#676)
Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
1 parent b52d5e0 commit 5256702

3 files changed

Lines changed: 14 additions & 17 deletions

File tree

README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ use FriendsOfHyperf\ReCaptcha\Middleware\ReCaptchaMiddleware;
2525

2626
class V3CaptchaMiddleware extends ReCaptchaMiddleware
2727
{
28-
protected $version = 'v3';
29-
protected $action = 'register';
30-
protected $score = 0.35;
31-
protected $hostname;
28+
protected string $version = 'v3';
29+
protected string $action = 'register';
30+
protected float $score = 0.35;
31+
protected string $hostname;
3232
}
3333

3434
class V2CaptchaMiddleware extends ReCaptchaMiddleware
3535
{
36-
protected $version = 'v2';
37-
protected $action = 'register';
38-
protected $score = 0.35;
39-
protected $hostname;
36+
protected string $version = 'v2';
37+
protected string $action = 'register';
38+
protected float $score = 0.35;
39+
protected string $hostname;
4040
}
4141
```
4242

@@ -53,11 +53,8 @@ use Hyperf\Validation\Contract\ValidatorFactoryInterface;
5353

5454
class IndexController
5555
{
56-
/**
57-
* @Inject()
58-
* @var ValidatorFactoryInterface
59-
*/
60-
protected $validationFactory;
56+
#[Inject]
57+
protected ValidatorFactoryInterface $validationFactory;
6158

6259
public function foo(RequestInterface $request)
6360
{

src/Middleware/ReCaptchaMiddleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ abstract class ReCaptchaMiddleware implements MiddlewareInterface
2727
{
2828
protected string $version = 'v3';
2929

30-
protected string $action;
30+
protected string $action = '';
3131

3232
protected float $score = 0.34;
3333

34-
protected string $hostname;
34+
protected string $hostname = '';
3535

3636
protected string $inputName = 'g-recaptcha-response';
3737

src/ReCaptchaManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class ReCaptchaManager
2222
{
2323
/**
24-
* @var ReCaptcha[]
24+
* @var array<string, ReCaptcha>
2525
*/
2626
protected array $instances = [];
2727

@@ -43,7 +43,7 @@ public function get(?string $version = null): ReCaptcha
4343
throw new RuntimeException('Not publish yet, please run \'php bin/hyperf.php vendor:publish friendsofhyperf/recaptcha\'');
4444
}
4545

46-
$version ??= $this->config->get('recaptcha.default', 'v3');
46+
$version ??= (string) $this->config->get('recaptcha.default', 'v3');
4747
$secret = $this->config->get(sprintf('recaptcha.%s.secret_key', $version), '');
4848

4949
return $this->instances[$version] = make(ReCaptcha::class, [

0 commit comments

Comments
 (0)