Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/Component/Input/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"' : '';
}
Expand Down
7 changes: 4 additions & 3 deletions includes/MslsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
*
* @return mixed
*/
public function __call( $method, $args ) {
public function __call( string $method, $args ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

According to the PHP documentation for the __call magic method, the second argument should be an array of the arguments passed to the method. It's good practice to type-hint it as array for better code clarity and robustness, especially in a PR focused on strengthening types.

public function __call( string $method, array $args ) {

$parts = explode( '_', $method, 2 );
if ( 2 === count( $parts ) && 'rewrite' === $parts[0] ) {
$this->render_rewrite( $parts[1] );
Expand Down Expand Up @@ -244,7 +244,7 @@
*
* @since 1.0
*/
do_action( self::MSLS_REGISTER_ACTION, __CLASS__ );

Check warning on line 247 in includes/MslsAdmin.php

View workflow job for this annotation

GitHub Actions / test

WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound

Hook names invoked by a theme/plugin should start with the theme/plugin prefix. Found: "self::MSLS_REGISTER_ACTION".
}

/**
Expand Down Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / test

WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound

Hook names invoked by a theme/plugin should start with the theme/plugin prefix. Found: "self::MSLS_ACTION_PREFIX . $section".

return count( $map );
}
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The rewrite property of a WP_Post_Type object can be false if rewrites are disabled. In that case, $rewrite would be assigned false, and attempting to access $rewrite['slug'] would result in a warning: "Cannot use a scalar value as an array".

To handle this correctly, you should check if $rewrite is an array before trying to access an element from it.

$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();
Expand Down
76 changes: 10 additions & 66 deletions includes/MslsAdminIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,33 @@
*/
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 ?? '';

$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 ) {
Expand All @@ -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;
Expand All @@ -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 ) {
Expand All @@ -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 ) ?? '';

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -153,17 +111,13 @@ public function set_origin_language( string $origin_language ): MslsAdminIcon {

/**
* Get image as html-tag
*
* @return string
*/
public function get_img(): string {
return sprintf( '<img alt="%s" src="%s" />', $this->language, $this->src );
}

/**
* Get link as html-tag
*
* @return string
*/
public function get_a(): string {
if ( empty( $this->href ) ) {
Expand All @@ -185,18 +139,12 @@ public function get_a(): string {
return sprintf( '<a title="%1$s" href="%2$s">%3$s</a>&nbsp;', 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 );
Expand All @@ -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 ) {
Expand Down Expand Up @@ -254,8 +200,6 @@ public function get_icon(): string {

/**
* Creates new admin link
*
* @return string
*/
public function get_edit_new(): string {
$path = $this->path;
Expand Down
6 changes: 4 additions & 2 deletions includes/MslsJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );
}

Expand All @@ -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 : '';
}

/**
Expand Down
8 changes: 4 additions & 4 deletions includes/MslsMetaBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions includes/MslsPostTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
}

use lloc\Msls\Component\Component;
use WP_Term;

/**
* Post Tag
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
Loading