Skip to content
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

Add psalm #53

Merged
merged 2 commits into from
Jun 2, 2024
Merged

Add psalm #53

merged 2 commits into from
Jun 2, 2024

Conversation

widoz
Copy link
Member

@widoz widoz commented Jun 2, 2024

Fix #51

Summary by CodeRabbit

  • New Features

    • Added static analysis checks using Psalm in the workflow.
    • Introduced Psalm configuration settings.
  • Chores

    • Updated .gitignore to exclude the /psalm directory.
    • Added vimeo/psalm as a development dependency in composer.json.
  • Documentation

    • Introduced phpstorm.meta.php for better type hinting in PhpStorm.
  • Refactor

    • Improved type declarations and handling of dependencies and versions in asset files.
    • Enhanced type declaration for the $package variable in plugin.php.
  • Style

    • Updated annotations for internal usage and removed unnecessary PHPDoc blocks.

Copy link

coderabbitai bot commented Jun 2, 2024

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 eea3694 and 84f7323.

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 (phpstan/phpstan#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:

#!/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:

#!/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:

#!/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:

#!/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:

#!/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:

#!/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:

#!/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
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
plugin.php (1)

Line range hint 19-30: The use of a static variable for $package and the Psalm suppress annotation are appropriate for handling dynamic includes and maintaining a singleton pattern in the plugin. Consider refactoring the autoload function into a top-level function or a static method to resolve the PHPStan issue.

- function autoload(string $projectRoot): void {
+ static function autoload(string $projectRoot): void {
Tools
PHPStan

17-17: Function Widoz\Wp\EntitiesSearch\package() has invalid return type Inpsyde\Modularity\Package.

@widoz widoz merged commit 53984e5 into main Jun 2, 2024
4 checks passed
@widoz widoz deleted the add-psalm branch June 2, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Psalm
1 participant