-
-
Notifications
You must be signed in to change notification settings - Fork 27
feat: Add PHPStan type testing #970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b191b9a
feat: add PHPStan type checking configuration and composer script
huangdijia 894922f
Add comprehensive PHPStan type tests for all helper functions (#971)
Copilot 59894aa
Move call() tests to Functions.php and update type assertions
huangdijia 5c47d7e
fix: remove unnecessary backslash from Throwable type hint in dispatc…
huangdijia 1c809ee
refactor: rename check:types script to type-testing for clarity
huangdijia 1c34be5
fix: move type-testing script to the correct position in composer.json
huangdijia 3886513
fix: remove unnecessary blank line before type-testing script in comp…
huangdijia 6939a70
feat: add Support.php with various utility classes and type assertions
huangdijia 447611e
fix: add return type hints for __invoke methods in ClientBuilderFacto…
huangdijia 4ee356d
feat: add PHPStan type assertion tests for macros component (#973)
Copilot f3d7040
feat: add PHPStan type testing for cache component (#972)
Copilot fd48474
fix: remove unused imports in Cache and Macros components
huangdijia 6bf4907
feat: update PHPStan configuration and enhance type assertions in var…
huangdijia d83334e
fix: update parameter type hint for Str::of method
huangdijia 12ba868
fix: remove unused Factory method tests in Cache Manager
huangdijia c4cb2c3
feat: add type testing step in CI workflow
huangdijia 0acc572
fix: comment out unused setMultiple tests in Repository
huangdijia de85c6e
fix: comment out unused getMultiple tests in Repository
huangdijia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| parameters: | ||
| level: max | ||
| paths: | ||
| - types | ||
| scanFiles: | ||
| - src/macros/output/Hyperf/Collection/Arr.php | ||
| - src/macros/output/Hyperf/Collection/Collection.php | ||
| - src/macros/output/Hyperf/Collection/LazyCollection.php | ||
| - src/macros/output/Hyperf/HttpServer/Contract/RequestInterface.php | ||
| - src/macros/output/Hyperf/HttpServer/Request.php | ||
| - src/macros/output/Hyperf/Stringable/Str.php | ||
| - src/macros/output/Hyperf/Stringable/Stringable.php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,302 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * This file is part of friendsofhyperf/components. | ||
| * | ||
| * @link https://github.com/friendsofhyperf/components | ||
| * @document https://github.com/friendsofhyperf/components/blob/main/README.md | ||
| * @contact huangdijia@gmail.com | ||
| */ | ||
|
|
||
| namespace Hyperf\HttpServer; | ||
|
|
||
| use Closure; | ||
| use Hyperf\Support\Fluent; | ||
| use Psr\Http\Message\ServerRequestInterface; | ||
|
|
||
| class Request | ||
| { | ||
| /** | ||
| * Get an array of all of the files on the request. | ||
| */ | ||
| public function allFiles(): array | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the request contains a non-empty value for any of the given inputs. | ||
| * | ||
| * @param array|string $keys | ||
| */ | ||
| public function anyFilled($keys): bool | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve input as a boolean value. | ||
| * | ||
| * Returns true when value is "1", "true", "on", and "yes". Otherwise, returns false. | ||
| * | ||
| * @param null|string $key | ||
| * @param bool $default | ||
| */ | ||
| public function boolean($key = null, $default = false): bool | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve input from the request as a collection. | ||
| */ | ||
| public function collect(null|array|string $key = null): \Hyperf\Collection\Collection | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve input from the request as a Carbon instance. | ||
| */ | ||
| public function date(string $key, ?string $format = null, ?string $tz = null): ?\Carbon\Carbon | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Get all of the input except for a specified array of items. | ||
| * | ||
| * @param array|mixed $keys | ||
| */ | ||
| public function except($keys): array | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * @param null|Closure(ServerRequestInterface):ServerRequestInterface $closure | ||
| */ | ||
| public static function fake(?Closure $closure = null): ServerRequestInterface | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the request contains a non-empty value for an input item. | ||
| */ | ||
| public function filled(array|string $key): bool | ||
| { | ||
| } | ||
|
|
||
| public function float(string $key, $default = null): float | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve input from the request as a Fluent object instance. | ||
| */ | ||
| public function fluent(null|array|string $key = null): Fluent | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the request contains any of the given inputs. | ||
| */ | ||
| public function hasAny(array|string $keys): bool | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the given input key is an empty string for "has". | ||
| */ | ||
| public function isEmptyString(string $key): bool | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the request contains an empty value for an input item. | ||
| */ | ||
| public function isNotFilled(array|string $key): bool | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Get the keys for all of the input and files. | ||
| */ | ||
| public function keys(): array | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Get the host name. | ||
| */ | ||
| public function host(): string | ||
| { | ||
| } | ||
|
|
||
| public function getHost(): string | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Get the HTTP host being requested. | ||
| */ | ||
| public function httpHost(): string | ||
| { | ||
| } | ||
|
|
||
| public function getHttpHost(): string | ||
| { | ||
| } | ||
|
|
||
| public function getPort(): int | ||
| { | ||
| } | ||
|
|
||
| public function getPsrRequest(): ?ServerRequestInterface | ||
| { | ||
| } | ||
|
|
||
| public function getScheme(): string | ||
| { | ||
| } | ||
|
|
||
| public function isSecure(): bool | ||
| { | ||
| } | ||
|
|
||
| public function getSchemeAndHttpHost(): string | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Get the scheme and HTTP host. | ||
| */ | ||
| public function schemeAndHttpHost(): string | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Merge new input into the current request's input array. | ||
| * | ||
| * @return $this | ||
| */ | ||
| public function merge(array $input): self | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Merge new input into the request's input, but only when that key is missing from the request. | ||
| * | ||
| * @return $this | ||
| */ | ||
| public function mergeIfMissing(array $input): self | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the request is missing a given input item key. | ||
| * | ||
| * @param array|string $key | ||
| */ | ||
| public function missing($key): bool | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Get a subset containing the provided keys with values from the input data. | ||
| * | ||
| * @param array|mixed $keys | ||
| */ | ||
| public function only($keys): array | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the current request is asking for JSON. | ||
| */ | ||
| public function wantsJson(): bool | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Apply the callback if the request contains a non-empty value for the given input item key. | ||
| * | ||
| * @return $this|mixed | ||
| */ | ||
| public function whenFilled(string $key, callable $callback, ?callable $default = null) | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Apply the callback if the request contains the given input item key. | ||
| * | ||
| * @return $this|mixed | ||
| */ | ||
| public function whenHas(string $key, callable $callback, ?callable $default = null) | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the request is sending JSON. | ||
| */ | ||
| public function isJson(): bool | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve input from the request as an enum. | ||
| * | ||
| * @template TEnum | ||
| * | ||
| * @param string $key | ||
| * @param class-string<TEnum> $enumClass | ||
| * @return null|TEnum | ||
| */ | ||
| public function enum($key, $enumClass) | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the request contains a given input item key. | ||
| * | ||
| * @param array|string $key | ||
| */ | ||
| public function exists($key): bool | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve input from the request as a Stringable instance. | ||
| * | ||
| * @param string $key | ||
| * @param mixed $default | ||
| * @return \Hyperf\Stringable\Stringable | ||
| */ | ||
| public function str($key, $default = null) | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve input from the request as a Stringable instance. | ||
| * | ||
| * @param string $key | ||
| * @param mixed $default | ||
| * @return \Hyperf\Stringable\Stringable | ||
| */ | ||
| public function string($key, $default = null) | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve input as an integer value. | ||
| * | ||
| * @param string $key | ||
| * @param int $default | ||
| */ | ||
| public function integer($key, $default = 0): int | ||
| { | ||
| } | ||
|
|
||
| public function validate(array $rules, array $messages = [], array $customAttributes = []): array | ||
| { | ||
| } | ||
|
|
||
| public function validateWithBag(string $errorBag, array $rules, array $messages = [], array $customAttributes = []): array | ||
| { | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
阻止桩类在生产环境被自动加载:建议改为 PHPStan stubs 或排除 classmap
该文件声明了完整的 Hyperf\HttpServer\Request 桩类,方法均为空且大多带返回类型。一旦被 Composer 在运行时加载:
建议:
若短期无法迁移,请至少为这些方法提供统一兜底(如直接抛出 LogicException),防止误用:
示例(选取少量代表方法,其他方法同理处理):
此外,可在需要处添加
🧰 Tools
🪛 PHPMD (2.15.0)
32-32: Avoid unused parameters such as '$keys'. (undefined)
(UnusedFormalParameter)
44-44: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
44-44: Avoid unused parameters such as '$default'. (undefined)
(UnusedFormalParameter)
51-51: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
58-58: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
58-58: Avoid unused parameters such as '$format'. (undefined)
(UnusedFormalParameter)
58-58: Avoid unused parameters such as '$tz'. (undefined)
(UnusedFormalParameter)
67-67: Avoid unused parameters such as '$keys'. (undefined)
(UnusedFormalParameter)
74-74: Avoid unused parameters such as '$closure'. (undefined)
(UnusedFormalParameter)
81-81: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
85-85: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
85-85: Avoid unused parameters such as '$default'. (undefined)
(UnusedFormalParameter)
92-92: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
99-99: Avoid unused parameters such as '$keys'. (undefined)
(UnusedFormalParameter)
106-106: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
113-113: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
178-178: Avoid unused parameters such as '$input'. (undefined)
(UnusedFormalParameter)
187-187: Avoid unused parameters such as '$input'. (undefined)
(UnusedFormalParameter)
196-196: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
205-205: Avoid unused parameters such as '$keys'. (undefined)
(UnusedFormalParameter)
221-221: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
221-221: Avoid unused parameters such as '$callback'. (undefined)
(UnusedFormalParameter)
221-221: Avoid unused parameters such as '$default'. (undefined)
(UnusedFormalParameter)
230-230: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
230-230: Avoid unused parameters such as '$callback'. (undefined)
(UnusedFormalParameter)
230-230: Avoid unused parameters such as '$default'. (undefined)
(UnusedFormalParameter)
250-250: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
250-250: Avoid unused parameters such as '$enumClass'. (undefined)
(UnusedFormalParameter)
259-259: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
270-270: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
270-270: Avoid unused parameters such as '$default'. (undefined)
(UnusedFormalParameter)
281-281: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
281-281: Avoid unused parameters such as '$default'. (undefined)
(UnusedFormalParameter)
291-291: Avoid unused parameters such as '$key'. (undefined)
(UnusedFormalParameter)
291-291: Avoid unused parameters such as '$default'. (undefined)
(UnusedFormalParameter)
295-295: Avoid unused parameters such as '$rules'. (undefined)
(UnusedFormalParameter)
295-295: Avoid unused parameters such as '$messages'. (undefined)
(UnusedFormalParameter)
295-295: Avoid unused parameters such as '$customAttributes'. (undefined)
(UnusedFormalParameter)
299-299: Avoid unused parameters such as '$errorBag'. (undefined)
(UnusedFormalParameter)
299-299: Avoid unused parameters such as '$rules'. (undefined)
(UnusedFormalParameter)
299-299: Avoid unused parameters such as '$messages'. (undefined)
(UnusedFormalParameter)
299-299: Avoid unused parameters such as '$customAttributes'. (undefined)
(UnusedFormalParameter)
🤖 Prompt for AI Agents