Spaghetti-Dojo / kensaku

A WordPress UI library to search Entities by Kind
https://spaghetti-dojo.github.io/kensaku/
GNU General Public License v2.0
0 stars 0 forks source link

Add psalm #53

Closed widoz closed 5 months ago

widoz commented 5 months ago

Fix #51

Summary by CodeRabbit

coderabbitai[bot] commented 5 months ago

Walkthrough

The recent changes introduce Psalm static analysis to the project, enhancing code quality and safety. This includes adding Psalm configuration, updating the workflow to run Psalm checks, and modifying several files to align with Psalm's requirements. Additionally, type declarations and annotations were refined to improve code clarity and robustness.

Changes

Files/Paths Change Summary
.github/workflows/php-qa.yml Added a new step for running Psalm static analysis after checking code styles.
.gitignore Excluded the /psalm directory.
.phpstorm.meta.php Introduced overrides for ContainerInterface::get method mapping specific keys to corresponding types.
composer.json Added vimeo/psalm as a dev dependency and updated scripts to run Psalm.
plugin.php Added type declarations and Psalm annotations for variables and include statements.
psalm.xml Introduced configuration settings for Psalm static analysis tool.
sources/server/src/Library.php Removed the default value for $baseUrl parameter in new method of Library class.
sources/server/src/Modules/BlockEditor/Module.php Adjusted handling of asset dependencies and version with robust parsing and fallback mechanisms.
sources/server/src/Modules/E2e/Module.php Changed @internal annotation and removed a commented-out PHPDoc block.
sources/server/src/Modules/Logging/Module.php Modified $asset array handling, extracting dependencies and version with fallbacks.

Assessment against linked issues

Objective Addressed Explanation
Add Psalm (#51)

Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between eea36942c056cdc5832ad01ea409ef1d13507121 and 84f73232a605c0474ecba87eaa18436109b7bf21.
Files selected for processing (10) * .github/workflows/php-qa.yml (1 hunks) * .gitignore (1 hunks) * .phpstorm.meta.php (1 hunks) * composer.json (2 hunks) * plugin.php (2 hunks) * psalm.xml (1 hunks) * sources/server/src/Library.php (1 hunks) * sources/server/src/Modules/BlockEditor/Module.php (1 hunks) * sources/server/src/Modules/E2e/Module.php (2 hunks) * sources/server/src/Modules/Logging/Module.php (1 hunks)
Files skipped from review due to trivial changes (4) * .github/workflows/php-qa.yml * .gitignore * composer.json * psalm.xml
Additional context used
PHPStan
.phpstorm.meta.php
4-4: Function override not found. --- 5-5: Call to static method get() on an unknown class Psr\Container\ContainerInterface. --- 6-6: Function map not found. --- 9-9: Access to constant PROPERTIES on an unknown class Inpsyde\Modularity\Package. --- 9-9: Class Inpsyde\Modularity\Properties\Properties not found.
sources/server/src/Library.php
23-23: Method Widoz\Wp\EntitiesSearch\Library::package() has invalid return type Inpsyde\Modularity\Package. --- 25-25: Call to static method new() on an unknown class Inpsyde\Modularity\Properties\LibraryProperties. --- 30-30: Call to static method new() on an unknown class Inpsyde\Modularity\Package. --- 31-31: Call to static method new() on an unknown class Widoz\Wp\EntitiesSearch\Modules\Logging\Module. --- 32-32: Call to static method new() on an unknown class Widoz\Wp\EntitiesSearch\Modules\BlockEditor\Module.
plugin.php
17-17: Function Widoz\Wp\EntitiesSearch\package() has invalid return type Inpsyde\Modularity\Package. --- 24-24: Inner named functions are not supported by PHPStan. Consider refactoring to an anonymous function, class method, or a top-level-defined function. See issue #165 (https://github.com/phpstan/phpstan/issues/165) for more details. --- 35-35: Function autoload not found. --- 36-36: Call to static method new() on an unknown class Widoz\Wp\EntitiesSearch\Library. --- 36-36: Function plugin_dir_url not found. --- 42-42: Function add_action not found. --- 45-45: Call to static method new() on an unknown class Widoz\Wp\EntitiesSearch\Modules\E2e\Module.
sources/server/src/Modules/Logging/Module.php
13-13: Class Widoz\Wp\EntitiesSearch\Modules\Logging\Module implements unknown interface Inpsyde\Modularity\Module\ExecutableModule. --- 15-15: Class Widoz\Wp\EntitiesSearch\Modules\Logging\Module uses unknown trait Inpsyde\Modularity\Module\ModuleClassNameIdTrait. --- 26-26: Parameter $container of method Widoz\Wp\EntitiesSearch\Modules\Logging\Module::run() has invalid type Psr\Container\ContainerInterface. --- 28-28: Access to constant PROPERTIES on an unknown class Inpsyde\Modularity\Package. --- 32-32: Function add_action not found. --- 33-33: Access to constant PROPERTIES on an unknown class Inpsyde\Modularity\Package. --- 35-35: Function untrailingslashit not found. --- 36-36: Function untrailingslashit not found. --- 46-46: Function wp_register_script not found.
sources/server/src/Modules/BlockEditor/Module.php
13-13: Class Widoz\Wp\EntitiesSearch\Modules\BlockEditor\Module implements unknown interface Inpsyde\Modularity\Module\ExecutableModule. --- 15-15: Class Widoz\Wp\EntitiesSearch\Modules\BlockEditor\Module uses unknown trait Inpsyde\Modularity\Module\ModuleClassNameIdTrait. --- 26-26: Parameter $container of method Widoz\Wp\EntitiesSearch\Modules\BlockEditor\Module::run() has invalid type Psr\Container\ContainerInterface. --- 28-28: Function add_action not found. --- 29-29: Access to constant PROPERTIES on an unknown class Inpsyde\Modularity\Package. --- 31-31: Function untrailingslashit not found. --- 32-32: Function untrailingslashit not found. --- 43-43: Function wp_register_script not found.
sources/server/src/Modules/E2e/Module.php
13-13: Class Widoz\Wp\EntitiesSearch\Modules\E2e\Module implements unknown interface Inpsyde\Modularity\Module\ExecutableModule. --- 15-15: Class Widoz\Wp\EntitiesSearch\Modules\E2e\Module uses unknown trait Inpsyde\Modularity\Module\ModuleClassNameIdTrait. --- 43-43: Parameter $container of method Widoz\Wp\EntitiesSearch\Modules\E2e\Module::run() has invalid type Psr\Container\ContainerInterface. --- 54-54: Function add_action not found. --- 55-55: Access to constant PROPERTIES on an unknown class Inpsyde\Modularity\Package. --- 59-59: Function add_action not found. --- 70-70: Function register_post_type not found. --- 77-77: Parameter $properties of method Widoz\Wp\EntitiesSearch\Modules\E2e\Module::postTypesExample() has invalid type Inpsyde\Modularity\Properties\Properties. --- 79-79: Function untrailingslashit not found. --- 81-81: Function wp_register_script not found. --- 89-89: Function wp_register_script not found. --- 97-97: Function register_block_type_from_metadata not found. --- 101-101: Function register_block_type_from_metadata not found.
Additional comments not posted (7)
.phpstorm.meta.php (1)
`3-12`: The PHPStorm metadata configuration appears correctly set up to aid in type hinting for the `ContainerInterface::get` method. Ensure that the classes and constants referenced are correctly defined in your project to avoid issues during development.
Tools
PHPStan
4-4: Function override not found. --- 5-5: Call to static method get() on an unknown class Psr\Container\ContainerInterface. --- 6-6: Function map not found. --- 9-9: Access to constant PROPERTIES on an unknown class Inpsyde\Modularity\Package. --- 9-9: Class Inpsyde\Modularity\Properties\Properties not found.
sources/server/src/Library.php (2)
`11-11`: The modification to enforce a non-nullable string for `$baseUrl` enhances type safety and clarity in the `Library` class's usage. --- Line range hint `23-32`: Ensure that all classes and methods called in the `package` method are correctly defined and accessible within your project's scope. This includes `Modularity\Package`, `Modularity\Properties\LibraryProperties`, and the modules being added.
sources/server/src/Modules/Logging/Module.php (1)
`38-49`: The enhancements to asset handling in the `run` method, including type annotations and robust handling of dependencies and version information, are well-implemented. Ensure that the `wp_register_script` function is available in your project's scope.
Tools
PHPStan
46-46: Function wp_register_script not found.
sources/server/src/Modules/BlockEditor/Module.php (1)
`34-41`: The improvements to asset handling in the Block Editor module, including conditional dependency management based on debug mode, enhance the module's robustness and maintainability. Verify the availability of the `wp_register_script` function as used here.
Verification successful --- The `wp_register_script` function is confirmed to be a part of WordPress, as indicated by the project's description as a WordPress package. No further verification is needed. - `sources/server/src/Modules/BlockEditor/Module.php` - `sources/server/src/Modules/Logging/Module.php` - `sources/server/src/Modules/E2e/Module.php`
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify the existence of the wp_register_script function. # Test: Search for the function definition. Expect: Definition found in the project. ast-grep --lang php --pattern $'function wp_register_script($_, $_, $_, $_, $_) { $$$ }' ``` Length of output: 196 --- --- Script: ```shell #!/bin/bash # Description: Verify the existence of the wp_register_script function. # Test: Search for the function definition. Expect: Definition found in the project. rg 'function wp_register_script' ``` Length of output: 34 --- --- Script: ```shell #!/bin/bash # Description: Verify the usage and source of the wp_register_script function. # Test: Search for the usage of the wp_register_script function. rg 'wp_register_script' # Test: Search for import statements or comments that might indicate the source of wp_register_script. rg 'wp_register_script' -A 5 ``` Length of output: 2384 --- --- Script: ```shell #!/bin/bash # Description: Verify if wp_register_script is a WordPress function by searching for WordPress-related configurations or documentation. # Test: Search for WordPress-related configurations or documentation. rg 'WordPress' README.md rg 'WordPress' composer.json rg 'WordPress' wp-config.php ``` Length of output: 454
sources/server/src/Modules/E2e/Module.php (2)
`11-11`: The updated `@internal` annotation clarifies the intended scope of the `E2e` module within the project. This is a good practice for maintaining clarity in large projects. --- Line range hint `77-101`: The enhancements to handle custom post types and taxonomies in the `E2e` module are well-implemented. Ensure that the registration functions (`register_post_type`, `register_block_type_from_metadata`) are available in your project's scope.
Verification successful --- The functions `register_post_type` and `register_block_type_from_metadata` are indeed used within the project, specifically in the `sources/server/src/Modules/E2e/Module.php` file. This confirms that the registration functions are being utilized as intended. - `sources/server/src/Modules/E2e/Module.php`: `register_post_type` is used. - `sources/server/src/Modules/E2e/Module.php`: `register_block_type_from_metadata` is used.
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify the existence of the registration functions. # Test: Search for the function definitions. Expect: Definitions found in the project. ast-grep --lang php --pattern $'function $_($_, $_) { $$$ }' ``` Length of output: 168 --- --- Script: ```shell #!/bin/bash # Description: Verify the existence of the registration functions. # Test: Search for the function definitions. Expect: Definitions found in the project. rg 'function register_post_type' --type php rg 'function register_block_type_from_metadata' --type php ``` Length of output: 106 --- --- Script: ```shell #!/bin/bash # Description: Verify the usage of the registration functions within the project. # Test: Search for the usage of the functions. Expect: Usage found in the project. rg 'register_post_type' --type php rg 'register_block_type_from_metadata' --type php ``` Length of output: 371
Tools
PHPStan
13-13: Class Widoz\Wp\EntitiesSearch\Modules\E2e\Module implements unknown interface Inpsyde\Modularity\Module\ExecutableModule.
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.