Conversation
There was a problem hiding this comment.
Pull request overview
This pull request modernizes the codebase by removing deprecated legacy classes and shortcode functionality while comprehensively updating type declarations throughout the library to leverage PHP's typed properties and constants.
Changes:
- Removed legacy compatibility classes (PostType, PostMeta, Taxonomy, TermMeta) and shortcode-related code
- Added strict type declarations and updated all property and method signatures with proper type hints
- Introduced auth_callback adapter methods in PostMeta and TermMeta for compatibility with johnbillion/args library
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| phpstan.neon.dist | Updated analysis path from src/ to inc/ directory |
| phpcs.xml.dist | Excluded MissingVar sniff to accommodate new typed properties |
| composer.json | Increased PHPStan memory limit for analysis |
| inc/TermMetaAdminUI.php | Added strict types, typed properties, void return types, and fixed action argument count |
| inc/TermMeta.php | Added strict types, typed constant, empty key validation, auth_callback adapter, and enhanced type annotations |
| inc/Taxonomy.php | Added strict types, typed constant and properties, improved type safety with array_map in set_object_types |
| inc/PostType.php | Added strict types, typed constant, comprehensive PHPStan type assertions for WordPress registration args |
| inc/PostMeta.php | Added strict types, typed constant, empty key validation, auth_callback adapter, and enhanced type annotations |
| inc/Container.php | Added strict types, typed properties, renamed parameter for clarity |
| inc/Admin/PostAction.php | Added strict types, typed constant, void return types |
| inc/Admin/PageView.php | Added strict types, void return type |
| inc/Admin/Page.php | Added strict types, typed constants and properties, improved type safety with nullable and union types |
| inc/Admin/AjaxAction.php | Added strict types, typed constant, void return types |
| inc/Contracts/Taxonomy.php | Added typed NAME constant to interface |
| inc/Contracts/Registrable.php | Added strict types declaration |
| inc/Shortcode.php | Removed - legacy shortcode functionality |
| inc/Contracts/ShortcodeView.php | Removed - legacy shortcode interface |
| inc/Legacy/TermMeta.php | Removed - deprecated legacy compatibility class |
| inc/Legacy/Taxonomy.php | Removed - deprecated legacy compatibility class |
| inc/Legacy/PostType.php | Removed - deprecated legacy compatibility class |
| inc/Legacy/PostMeta.php | Removed - deprecated legacy compatibility class |
| README.md | Added comprehensive usage examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * Post meta key. | ||
| */ | ||
| public const KEY = null; | ||
| public const string KEY = ''; |
There was a problem hiding this comment.
Changing the default value of KEY from null to an empty string is a breaking change. Child classes that previously relied on the constant being null (e.g., checking static::KEY === null) will need to be updated to check for an empty string instead. Consider documenting this breaking change in release notes or migration guide.
| * | ||
| * Implementations are expected to override this. | ||
| */ | ||
| public const string NAME = ''; |
There was a problem hiding this comment.
The Taxonomy interface now defines a NAME constant, but the PostType interface does not have an equivalent constant despite the PostType class defining public const string NAME = 'post';. Consider adding a NAME constant to the PostType interface for consistency, or document why Taxonomy needs this in its interface while PostType does not.
| public const string NAME = ''; | |
| public const NAME = ''; |
inc/PostMeta.php
Outdated
| * @return string Type of the data. | ||
| */ | ||
| /** @return 'array'|'boolean'|'integer'|'number'|'object'|'string' */ |
There was a problem hiding this comment.
There's a duplicate return type annotation. The PHPDoc @return annotation on line 108 appears to be redundant since line 106-107 already documents the return type. Consider removing line 108 or integrating it into the main docblock to avoid duplicate documentation.
| * @return string Type of the data. | |
| */ | |
| /** @return 'array'|'boolean'|'integer'|'number'|'object'|'string' */ | |
| * @return 'array'|'boolean'|'integer'|'number'|'object'|'string' Type of the data. | |
| */ |
inc/Admin/Page.php
Outdated
| @@ -137,16 +133,16 @@ class Page implements Registrable { | |||
| * | |||
| * @var string | |||
There was a problem hiding this comment.
The @var annotation incorrectly states the type as "string" but the property is actually typed as "string|false" on line 136. The documentation should be updated to match the actual type.
| * @var string | |
| * @var string|false |
inc/Admin/Page.php
Outdated
| @@ -253,7 +247,7 @@ private function get_callback() { | |||
| * | |||
| * @return string The hook name of the menu page. | |||
There was a problem hiding this comment.
The @return annotation incorrectly states the return type as "string" but the method signature on line 250 actually returns "string|false". The documentation should be updated to reflect the actual return type.
| * @return string The hook name of the menu page. | |
| * @return string|false The hook name of the menu page. |
| /** | ||
| * Term meta key. | ||
| */ | ||
| public const KEY = null; | ||
| public const string KEY = ''; |
There was a problem hiding this comment.
Changing the default value of KEY from null to an empty string is a breaking change. Child classes that previously relied on the constant being null (e.g., checking static::KEY === null) will need to be updated to check for an empty string instead. Consider documenting this breaking change in release notes or migration guide.
inc/TermMeta.php
Outdated
| * @return string Type of the data. | ||
| */ | ||
| /** @return 'array'|'boolean'|'integer'|'number'|'object'|'string' */ |
There was a problem hiding this comment.
There's a duplicate return type annotation. The PHPDoc @return annotation on line 108 appears to be redundant since line 106-107 already documents the return type. Consider removing line 108 or integrating it into the main docblock to avoid duplicate documentation.
| * @return string Type of the data. | |
| */ | |
| /** @return 'array'|'boolean'|'integer'|'number'|'object'|'string' */ | |
| * @return string Type of the data. One of 'array', 'boolean', 'integer', 'number', 'object', or 'string'. | |
| */ |
| /** | ||
| * Adapter for the narrower `johnbillion/args` auth callback signature. | ||
| * | ||
| * @since 0.1.0 | ||
| * | ||
| * @param bool $allowed Whether the user can add the post meta. | ||
| * @param string $meta_key The meta key. | ||
| * @param string $object_type Object type. | ||
| * @param string $object_subtype Object subtype. | ||
| * @return bool Whether the user is allowed to edit meta. | ||
| */ | ||
| public function auth_callback( bool $allowed, string $meta_key, string $object_type, string $object_subtype = '' ): bool { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| return $this->auth( $allowed, $meta_key, 0, 0, '', [] ); | ||
| } |
There was a problem hiding this comment.
The auth_callback adapter passes hardcoded dummy values (0, 0, '', []) for the object_id, user_id, cap, and caps parameters when calling the auth method. This means child classes that override the auth method will not have access to the actual values of these parameters when the callback is invoked via johnbillion/args. Consider documenting this limitation or ensuring that child classes that need these parameters override auth_callback instead of auth.
| /** | ||
| * Adapter for the narrower `johnbillion/args` auth callback signature. | ||
| * | ||
| * @since 0.1.0 | ||
| * | ||
| * @param bool $allowed Whether the user can add the term meta. | ||
| * @param string $meta_key The meta key. | ||
| * @param string $object_type Object type. | ||
| * @param string $object_subtype Object subtype. | ||
| * @return bool Whether the user is allowed to edit meta. | ||
| */ | ||
| public function auth_callback( bool $allowed, string $meta_key, string $object_type, string $object_subtype = '' ): bool { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| return $this->auth( $allowed, $meta_key, 0, 0, '', [] ); | ||
| } |
There was a problem hiding this comment.
The auth_callback adapter passes hardcoded dummy values (0, 0, '', []) for the object_id, user_id, cap, and caps parameters when calling the auth method. This means child classes that override the auth method will not have access to the actual values of these parameters when the callback is invoked via johnbillion/args. Consider documenting this limitation or ensuring that child classes that need these parameters override auth_callback instead of auth.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
* Initial plan * Fix PHPDoc annotations and add PostType NAME constant Co-authored-by: ocean90 <617637+ocean90@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ocean90 <617637+ocean90@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * menu_position?: int, | ||
| * menu_icon?: string, | ||
| * capability_type?: string|array<int, string>, | ||
| * capabilities?: string[], |
There was a problem hiding this comment.
The type annotation for capabilities is string[], but according to WordPress documentation, this should be an associative array with specific keys like 'edit_post', 'read_post', 'delete_post', etc., mapping to capability names. The more accurate type would be array<string, string> to reflect the associative nature of this array.
| * capabilities?: string[], | |
| * capabilities?: array<string, string>, |
| @@ -13,4 +13,10 @@ | |||
| * @since 0.3.2 | |||
| */ | |||
| interface Taxonomy { | |||
There was a problem hiding this comment.
For consistency with other interface files in the codebase (like Registrable.php), this interface should also include declare( strict_types=1 ); after the opening PHP tag and before the namespace declaration.
| @@ -13,4 +13,10 @@ | |||
| * @since 0.3.2 | |||
| */ | |||
| interface PostType { | |||
There was a problem hiding this comment.
For consistency with other interface files in the codebase (like Registrable.php), this interface should also include declare( strict_types=1 ); after the opening PHP tag and before the namespace declaration.
No description provided.