diff --git a/includes/Component/Input/Text.php b/includes/Component/Input/Text.php
index 149d72797..16b0e7440 100644
--- a/includes/Component/Input/Text.php
+++ b/includes/Component/Input/Text.php
@@ -36,7 +36,7 @@ final class Text extends Component {
*/
public function __construct( string $key, ?string $value, int $size = self::DEFAULT_SIZE, bool $read_only = false ) {
$this->key = $key;
- $this->value = $value;
+ $this->value = $value ?? '';
$this->size = $size;
$this->readonly = $read_only ? ' readonly="readonly"' : '';
}
diff --git a/includes/MslsAdmin.php b/includes/MslsAdmin.php
index 1c0a1173a..b21f30ef4 100644
--- a/includes/MslsAdmin.php
+++ b/includes/MslsAdmin.php
@@ -98,7 +98,7 @@ public function get_options_page_link(): string {
*
* @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] );
@@ -433,8 +433,9 @@ public function content_priority(): void {
* @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'] ?? '';
// phpcs:ignore WordPress.Security.EscapeOutput
echo ( new Text( "rewrite_{$key}", $value, 30, true ) )->render();
diff --git a/includes/MslsAdminIcon.php b/includes/MslsAdminIcon.php
index 1245c5dce..4faa0cc06 100644
--- a/includes/MslsAdminIcon.php
+++ b/includes/MslsAdminIcon.php
@@ -13,23 +13,21 @@
*/
class MslsAdminIcon {
- protected string $icon_type = 'action';
- protected string $language;
- public string $origin_language;
- protected string $src;
- protected string $href;
- protected int $blog_id;
- protected string $type;
- protected string $path = 'post-new.php';
- protected int $id;
+ protected string $icon_type = 'action';
+ protected string $language = '';
+ public string $origin_language = '';
+ protected string $src = '';
+ protected string $href = '';
+ protected int $blog_id = 0;
+ protected string $type = '';
+ protected string $path = 'post-new.php';
+ protected int $id = 0;
const TYPE_FLAG = 'flag';
const TYPE_LABEL = 'label';
/**
* Constructor
- *
- * @param string $type
*/
public function __construct( ?string $type = null ) {
$this->type = $type ?? '';
@@ -37,16 +35,11 @@ public function __construct( ?string $type = null ) {
$this->set_path();
}
- /**
- * @return string
- */
- public function __toString() {
+ public function __toString(): string {
return $this->get_a();
}
/**
- * @param ?string $type
- *
* @return MslsAdminIcon|MslsAdminIconTaxonomy
*/
public static function create( ?string $type = null ) {
@@ -61,10 +54,6 @@ public static function create( ?string $type = null ) {
/**
* Set the icon path
- *
- * @param string $icon_type
- *
- * @return MslsAdminIcon
*/
public function set_icon_type( string $icon_type ): MslsAdminIcon {
$this->icon_type = $icon_type;
@@ -74,8 +63,6 @@ public function set_icon_type( string $icon_type ): MslsAdminIcon {
/**
* Set the path by type
- *
- * @return MslsAdminIcon
*/
public function set_path(): MslsAdminIcon {
if ( 'post' !== $this->type ) {
@@ -86,39 +73,18 @@ public function set_path(): MslsAdminIcon {
return $this;
}
- /**
- * Set language
- *
- * @param string $language
- *
- * @return MslsAdminIcon
- */
public function set_language( string $language ): MslsAdminIcon {
$this->language = $language;
return $this;
}
- /**
- * Set src
- *
- * @param string $src
- *
- * @return MslsAdminIcon
- */
public function set_src( string $src ): MslsAdminIcon {
$this->src = $src;
return $this;
}
- /**
- * Set href
- *
- * @param int $id
- *
- * @return MslsAdminIcon
- */
public function set_href( int $id ): MslsAdminIcon {
$this->href = get_edit_post_link( $id ) ?? '';
@@ -127,10 +93,6 @@ public function set_href( int $id ): MslsAdminIcon {
/**
* Sets the id of the object this icon is for
- *
- * @param int $id
- *
- * @return MslsAdminIcon
*/
public function set_id( int $id ): MslsAdminIcon {
$this->id = $id;
@@ -140,10 +102,6 @@ public function set_id( int $id ): MslsAdminIcon {
/**
* Sets the origin language for this icon
- *
- * @param string $origin_language
- *
- * @return MslsAdminIcon
*/
public function set_origin_language( string $origin_language ): MslsAdminIcon {
$this->origin_language = $origin_language;
@@ -153,8 +111,6 @@ public function set_origin_language( string $origin_language ): MslsAdminIcon {
/**
* Get image as html-tag
- *
- * @return string
*/
public function get_img(): string {
return sprintf( '
', $this->language, $this->src );
@@ -162,8 +118,6 @@ public function get_img(): string {
/**
* Get link as html-tag
- *
- * @return string
*/
public function get_a(): string {
if ( empty( $this->href ) ) {
@@ -185,18 +139,12 @@ public function get_a(): string {
return sprintf( '%3$s ', esc_attr( $title ), esc_url( $href ), $this->get_icon() );
}
- /**
- * @return bool
- */
protected function should_quick_create(): bool {
return 0 !== $this->id
&& '' !== $this->origin_language
&& msls_options()->activate_quick_create;
}
- /**
- * @return string
- */
protected function get_quick_create_a(): string {
$collection = msls_blog_collection();
$source_blog_id = $collection->get_blog_id( $this->origin_language );
@@ -218,8 +166,6 @@ protected function get_quick_create_a(): string {
/**
* Get icon as html-tag
- *
- * @return string
*/
public function get_icon(): string {
if ( ! $this->language ) {
@@ -254,8 +200,6 @@ public function get_icon(): string {
/**
* Creates new admin link
- *
- * @return string
*/
public function get_edit_new(): string {
$path = $this->path;
diff --git a/includes/MslsJson.php b/includes/MslsJson.php
index 7aaa0937f..7aabd10ff 100644
--- a/includes/MslsJson.php
+++ b/includes/MslsJson.php
@@ -40,7 +40,7 @@ public function add( $value, $label ) {
*
* @return int
*/
- public static function compare( array $a, array $b ) {
+ public static function compare( array $a, array $b ): int {
return strnatcmp( $a['label'], $b['label'] );
}
@@ -63,7 +63,9 @@ public function get(): array {
* @return string
*/
public function encode(): string {
- return wp_json_encode( $this->get() );
+ $json_string = wp_json_encode( $this->get() );
+
+ return is_string( $json_string ) ? $json_string : '';
}
/**
diff --git a/includes/MslsMetaBox.php b/includes/MslsMetaBox.php
index 58b0f4a58..8cf607a04 100644
--- a/includes/MslsMetaBox.php
+++ b/includes/MslsMetaBox.php
@@ -10,6 +10,7 @@
use lloc\Msls\Component\Wrapper;
use lloc\Msls\ContentImport\MetaBox as ContentImportMetaBox;
use WP_Post;
+use WP_Post_Type;
/**
* Meta box for the edit mode of the (custom) post types
@@ -206,10 +207,9 @@ public function render_select(): void {
$icon->set_href( $linked_post_id );
}
- $selects = '';
- $p_object = get_post_type_object( $type );
-
- if ( $p_object->hierarchical ) {
+ $selects = '';
+ $pt_object = get_post_type_object( $type );
+ if ( $pt_object instanceof WP_Post_Type && $pt_object->hierarchical ) {
$args = array(
'post_type' => $type,
'selected' => $mydata->$language,
diff --git a/includes/MslsPostTag.php b/includes/MslsPostTag.php
index 27d497d1a..d5a156862 100644
--- a/includes/MslsPostTag.php
+++ b/includes/MslsPostTag.php
@@ -7,6 +7,7 @@
}
use lloc\Msls\Component\Component;
+use WP_Term;
/**
* Post Tag
@@ -91,7 +92,7 @@ public static function suggest(): void {
)
);
- wp_die( wp_json_encode( $results ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ wp_die( (string) wp_json_encode( $results ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
public static function init(): void {
@@ -208,7 +209,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo
if ( $mydata->has_value( $language ) ) {
$term = get_term( $mydata->$language, $type );
- if ( is_object( $term ) ) {
+ if ( $term instanceof WP_Term ) {
$icon->set_href( (int) $mydata->$language );
$value = $mydata->$language;
$title = $term->name;