Closed widoz closed 5 months ago
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.
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. |
Objective | Addressed | Explanation |
---|---|---|
Add Psalm (#51) | ✅ |
.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.
.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: 454sources/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: 371Tools
PHPStan
13-13: Class Widoz\Wp\EntitiesSearch\Modules\E2e\Module implements unknown interface Inpsyde\Modularity\Module\ExecutableModule.
Fix #51
Summary by CodeRabbit
New Features
Chores
.gitignore
to exclude the/psalm
directory.vimeo/psalm
as a development dependency incomposer.json
.Documentation
phpstorm.meta.php
for better type hinting in PhpStorm.Refactor
$package
variable inplugin.php
.Style