-
-
Notifications
You must be signed in to change notification settings - Fork 41
Weak typing fixed #629
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
Weak typing fixed #629
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 |
|---|---|---|
|
|
@@ -9,12 +9,7 @@ | |
| */ | ||
| class MslsAdminIconTaxonomy extends MslsAdminIcon { | ||
|
|
||
| /** | ||
| * Path | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $path = 'edit-tags.php'; | ||
| protected string $path = 'edit-tags.php'; | ||
|
|
||
| /** | ||
| * Set href | ||
|
|
@@ -27,7 +22,7 @@ class MslsAdminIconTaxonomy extends MslsAdminIcon { | |
| public function set_href( int $id ): MslsAdminIcon { | ||
| $object_type = MslsTaxonomy::instance()->get_post_type(); | ||
|
|
||
| $this->href = get_edit_term_link( $id, $this->type, $object_type ); | ||
| $this->href = get_edit_term_link( $id, $this->type, $object_type ) ?? ''; | ||
|
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 $link = get_edit_term_link( $id, $this->type, $object_type );
$this->href = ! is_wp_error( $link ) ? (string) $link : ''; |
||
|
|
||
| return $this; | ||
| } | ||
|
|
@@ -38,9 +33,9 @@ public function set_href( int $id ): MslsAdminIcon { | |
| * @return MslsAdminIconTaxonomy | ||
| */ | ||
| public function set_path(): MslsAdminIcon { | ||
| $args = array( 'taxonomy' => $this->type ); | ||
| $post_type = MslsTaxonomy::instance()->get_post_type(); | ||
| $args = array( 'taxonomy' => $this->type ); | ||
|
|
||
| $post_type = MslsTaxonomy::instance()->get_post_type(); | ||
| if ( '' !== $post_type ) { | ||
| $args['post_type'] = $post_type; | ||
| } | ||
|
|
||
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.
The newly added typed properties are not initialized with default values. In PHP 7.4+, accessing an uninitialized typed property before it has been assigned a value will throw a
TypeError. Since these properties (like$language,$src,$href, and$id) are not initialized in the constructor but are accessed in methods such asget_img(),get_a(), andget_icon(), this will lead to runtime crashes if the setter methods are not called first. Initializing them with safe defaults (e.g.,''or0) ensures the object is always in a valid state.