Skip to content

Remove legacy code, update typings#7

Open
ocean90 wants to merge 22 commits intomasterfrom
refactor
Open

Remove legacy code, update typings#7
ocean90 wants to merge 22 commits intomasterfrom
refactor

Conversation

@ocean90
Copy link
Member

@ocean90 ocean90 commented Jan 25, 2026

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 23 to +26
/**
* Post meta key.
*/
public const KEY = null;
public const string KEY = '';
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
*
* Implementations are expected to override this.
*/
public const string NAME = '';
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
public const string NAME = '';
public const NAME = '';

Copilot uses AI. Check for mistakes.
inc/PostMeta.php Outdated
Comment on lines 86 to 108
* @return string Type of the data.
*/
/** @return 'array'|'boolean'|'integer'|'number'|'object'|'string' */
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
* @return string Type of the data.
*/
/** @return 'array'|'boolean'|'integer'|'number'|'object'|'string' */
* @return 'array'|'boolean'|'integer'|'number'|'object'|'string' Type of the data.
*/

Copilot uses AI. Check for mistakes.
@@ -137,16 +133,16 @@ class Page implements Registrable {
*
* @var string
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
* @var string
* @var string|false

Copilot uses AI. Check for mistakes.
@@ -253,7 +247,7 @@ private function get_callback() {
*
* @return string The hook name of the menu page.
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
* @return string The hook name of the menu page.
* @return string|false The hook name of the menu page.

Copilot uses AI. Check for mistakes.
Comment on lines 23 to +26
/**
* Term meta key.
*/
public const KEY = null;
public const string KEY = '';
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
inc/TermMeta.php Outdated
Comment on lines 86 to 108
* @return string Type of the data.
*/
/** @return 'array'|'boolean'|'integer'|'number'|'object'|'string' */
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
* @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'.
*/

Copilot uses AI. Check for mistakes.
Comment on lines +177 to +190
/**
* 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, '', [] );
}
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

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 uses AI. Check for mistakes.
Comment on lines +177 to +190
/**
* 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, '', [] );
}
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

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 uses AI. Check for mistakes.
@ocean90
Copy link
Member Author

ocean90 commented Feb 3, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link

Copilot AI commented Feb 3, 2026

@ocean90 I've opened a new pull request, #8, to work on those changes. Once the pull request is ready, I'll request review from you.

* 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>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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[],
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
* capabilities?: string[],
* capabilities?: array<string, string>,

Copilot uses AI. Check for mistakes.
@@ -13,4 +13,10 @@
* @since 0.3.2
*/
interface Taxonomy {
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@@ -13,4 +13,10 @@
* @since 0.3.2
*/
interface PostType {
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

2 participants