-
-
Notifications
You must be signed in to change notification settings - Fork 41
Fix weak typing #630
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
Fix weak typing #630
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,7 +98,7 @@ | |
| * | ||
| * @return mixed | ||
| */ | ||
| public function __call( $method, $args ) { | ||
| public function __call( string $method, $args ) { | ||
| $parts = explode( '_', $method, 2 ); | ||
| if ( 2 === count( $parts ) && 'rewrite' === $parts[0] ) { | ||
| $this->render_rewrite( $parts[1] ); | ||
|
|
@@ -244,7 +244,7 @@ | |
| * | ||
| * @since 1.0 | ||
| */ | ||
| do_action( self::MSLS_REGISTER_ACTION, __CLASS__ ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -344,7 +344,7 @@ | |
| * | ||
| * @since 2.4.4 | ||
| */ | ||
| do_action( self::MSLS_ACTION_PREFIX . $section, __CLASS__, $section ); | ||
|
Check warning on line 347 in includes/MslsAdmin.php
|
||
|
|
||
| return count( $map ); | ||
| } | ||
|
|
@@ -433,8 +433,9 @@ | |
| * @param mixed $key | ||
| */ | ||
| public function render_rewrite( $key ): void { | ||
| $rewrite = get_post_type_object( $key )->rewrite; | ||
| $value = $rewrite['slug'] ?? ''; | ||
| $pt_object = get_post_type_object( $key ); | ||
| $rewrite = $pt_object ? $pt_object->rewrite : array(); | ||
| $value = $rewrite['slug'] ?? ''; | ||
|
Comment on lines
+437
to
+438
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The To handle this correctly, you should check if $rewrite = $pt_object ? $pt_object->rewrite : null;
$value = is_array( $rewrite ) ? ( $rewrite['slug'] ?? '' ) : ''; |
||
|
|
||
| // phpcs:ignore WordPress.Security.EscapeOutput | ||
| echo ( new Text( "rewrite_{$key}", $value, 30, true ) )->render(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the PHP documentation for the
__callmagic method, the second argument should be an array of the arguments passed to the method. It's good practice to type-hint it asarrayfor better code clarity and robustness, especially in a PR focused on strengthening types.