Skip to content

Commit 37fc5bd

Browse files
committed
perf(doc): Improve type coverage and doc comments
- Add type coverage for parameters and return types in phpstan configuration. - Update __call method in HasOptions trait to declare return type. - Modify setOption, getOption, and getValidatedOption methods to use mixed types. - Add suppression comments for multiple class declarations in doc comment rector files.
1 parent 19a2e87 commit 37fc5bd

8 files changed

Lines changed: 27 additions & 24 deletions

File tree

phpstan.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ parameters:
1616
lineBefore: 3
1717
lineAfter: 3
1818
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
19+
type_coverage:
20+
declare: 100
21+
return_type: 100
22+
param_type: 100
23+
property_type: 100
24+
constant_type: 100
1925
# checkOctaneCompatibility: true
2026
# checkModelProperties: true
2127
# checkMissingIterableValueType: true

src/Foundation/Client.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@
1313

1414
namespace Guanguans\Notify\Foundation;
1515

16-
use Guanguans\Notify\Foundation\Authenticators\AggregateAuthenticator;
1716
use Guanguans\Notify\Foundation\Authenticators\NullAuthenticator;
18-
use Guanguans\Notify\Foundation\Authenticators\OptionsAuthenticator;
1917
use Guanguans\Notify\Foundation\Concerns\Dumpable;
2018
use Guanguans\Notify\Foundation\Concerns\HasHttpClient;
2119
use Guanguans\Notify\Foundation\Contracts\Authenticator;
2220
use Guanguans\Notify\Foundation\Contracts\Message;
2321
use Guanguans\Notify\Foundation\Support\Utils;
2422
use GuzzleHttp\Exception\GuzzleException;
2523
use GuzzleHttp\Promise\PromiseInterface;
26-
use GuzzleHttp\RequestOptions;
2724
use Psr\Http\Message\ResponseInterface;
2825

2926
class Client implements Contracts\Client

src/Foundation/Concerns/HasOptions.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22

3-
/** @noinspection MissingReturnTypeInspection */
4-
/** @noinspection MissingParameterTypeDeclarationInspection */
5-
63
declare(strict_types=1);
74

85
/**
@@ -44,14 +41,16 @@ trait HasOptions
4441
/**
4542
* @throws \ReflectionException
4643
*/
47-
public function __call(string $name, array $arguments)
44+
public function __call(string $name, array $arguments): self
4845
{
49-
$defined = Utils::definedFor($this);
50-
5146
foreach ([null, 'snake', 'pascal', 'kebab'] as $case) {
52-
$casedName = $case ? Str::{$case}($name) : $name;
53-
54-
if (\in_array($casedName, $defined, true)) {
47+
if (
48+
\in_array(
49+
$casedName = $case ? Str::{$case}($name) : $name,
50+
$defined ??= Utils::definedFor($this),
51+
true
52+
)
53+
) {
5554
if ([] === $arguments) {
5655
throw new InvalidArgumentException(
5756
\sprintf('The method [%s::%s] require an argument.', static::class, $name),
@@ -65,7 +64,7 @@ public function __call(string $name, array $arguments)
6564
throw new BadMethodCallException(\sprintf('The method [%s::%s] does not exist.', static::class, $name));
6665
}
6766

68-
public function setOption(string $option, $value): self
67+
public function setOption(string $option, mixed $value): self
6968
{
7069
$this->options[$option] = $value;
7170

@@ -79,7 +78,7 @@ public function setOptions(array $options): self
7978
return $this;
8079
}
8180

82-
public function getOption(string $option, $default = null)
81+
public function getOption(string $option, mixed $default = null): mixed
8382
{
8483
return $this->options[$option] ?? $default;
8584
}
@@ -89,7 +88,7 @@ public function getOptions(): array
8988
return $this->options;
9089
}
9190

92-
public function getValidatedOption(string $option, $default = null)
91+
public function getValidatedOption(string $option, mixed $default = null): mixed
9392
{
9493
return $this->getValidatedOptions()[$option] ?? $default;
9594
}

src/Foundation/Rectors/HasHttpClientDocCommentRector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
/** @noinspection PhpMultipleClassDeclarationsInspection */
4+
35
declare(strict_types=1);
46

57
/**

src/Foundation/Rectors/HasOptionsDocCommentRector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
/** @noinspection PhpMultipleClassDeclarationsInspection */
4+
35
declare(strict_types=1);
46

57
/**

src/Foundation/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function __toString(): string
9898
}
9999

100100
/**
101-
* Create a instance from a PSR response.
101+
* Create an instance from a PSR response.
102102
*/
103103
public static function fromPsrResponse(ResponseInterface $response): self
104104
{

src/Foundation/Support/Arr.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static function set(array &$array, mixed $key, mixed $value): array
5454
return $array = $value;
5555
}
5656

57-
$keys = (array) explode('.', $key);
57+
$keys = explode('.', $key);
5858

5959
/** @noinspection SuspiciousLoopInspection */
6060
foreach ($keys as $i => $key) {
@@ -82,11 +82,10 @@ public static function set(array &$array, mixed $key, mixed $value): array
8282
/**
8383
* Get an item from an array using "dot" notation.
8484
*
85-
* @noinspection MultipleReturnStatementsInspection
86-
*
85+
* @param array|\ArrayAccess|mixed $array
8786
* @param null|array-key $key
8887
*/
89-
public static function get(array|\ArrayAccess $array, mixed $key, mixed $default = null): mixed
88+
public static function get(mixed $array, mixed $key, mixed $default = null): mixed
9089
{
9190
if (!static::accessible($array)) {
9291
return value($default);

src/Ntfy/Authenticator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(
2828
#[\SensitiveParameter]
2929
?string $password = null
3030
) {
31-
$authenticators = match (\func_num_args()) {
31+
parent::__construct(...match (\func_num_args()) {
3232
0 => [
3333
new NullAuthenticator,
3434
],
@@ -42,8 +42,6 @@ public function __construct(
4242
new BasicAuthenticator($usernameOrToken, $password),
4343
],
4444
default => throw new InvalidArgumentException('The number of arguments must be 0, 1 or 2.'),
45-
};
46-
47-
parent::__construct(...$authenticators);
45+
});
4846
}
4947
}

0 commit comments

Comments
 (0)