Skip to content

Commit

Permalink
Merge branch 'release/3.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazz-Man committed Feb 4, 2023
2 parents c1b1b64 + 3c25e18 commit 80a6972
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 125 deletions.
35 changes: 0 additions & 35 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,11 @@ parameters:
count: 1
path: src/CustomPostType.php

-
message: "#^Method JazzMan\\\\Post\\\\CustomPostType\\:\\:registerTaxonomy\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/CustomPostType.php

-
message: "#^PHPDoc tag @var above a method has no effect\\.$#"
count: 1
path: src/CustomPostType.php

-
message: "#^PHPDoc tag @var for variable \\$args has no value type specified in iterable type array\\.$#"
count: 2
path: src/CustomPostType.php

-
message: "#^PHPDoc tag @var for variable \\$default_term has no value type specified in iterable type array\\.$#"
count: 2
path: src/CustomPostType.php

-
message: "#^PHPDoc tag @var for variable \\$rewrite has no value type specified in iterable type array\\.$#"
count: 2
path: src/CustomPostType.php

-
message: "#^Parameter \\#1 \\$args of function wp_dropdown_categories expects array\\{show_option_all\\?\\: string, show_option_none\\?\\: string, option_none_value\\?\\: string, orderby\\?\\: string, pad_counts\\?\\: bool, show_count\\?\\: bool\\|int, echo\\?\\: bool\\|int, hierarchical\\?\\: bool\\|int, \\.\\.\\.\\}, array\\{hide_empty\\: 0, hierarchical\\: 1, show_count\\: 0, orderby\\: 'name', name\\: non\\-falsy\\-string, value_field\\: 'slug', taxonomy\\: string, selected\\: mixed, \\.\\.\\.\\} given\\.$#"
count: 1
path: src/CustomPostType.php

-
message: "#^Method JazzMan\\\\Post\\\\PostTypeMessages\\:\\:bulkUpdatedMessages\\(\\) should return array\\<string, array\\<string, string\\>\\> but returns array\\<int\\|string, array\\<string, string\\>\\>\\.$#"
count: 1
path: src/PostTypeMessages.php

-
message: "#^Method JazzMan\\\\Post\\\\PostTypeMessages\\:\\:updatedMessages\\(\\) should return array\\<string, array\\<int\\|string, mixed\\>\\> but returns array\\<int\\|string, array\\<int\\|string, mixed\\>\\>\\.$#"
count: 1
path: src/PostTypeMessages.php

-
message: "#^Function app_get_post_type_labels\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
60 changes: 30 additions & 30 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@
<code>$postarr</code>
</ArgumentTypeCoercion>
<InvalidArgument>
<code>[
'description' =&gt; 'Archive posts associated with each post type.',
'public' =&gt; false,
'show_in_nav_menus' =&gt; false,
'show_in_admin_bar' =&gt; false,
'exclude_from_search' =&gt; true,
'show_ui' =&gt; true,
'show_in_menu' =&gt; true,
'can_export' =&gt; true,
'delete_with_user' =&gt; false,
'hierarchical' =&gt; false,
'has_archive' =&gt; false,
'menu_icon' =&gt; 'dashicons-media-text',
'query_var' =&gt; 'hdptap_cpt_archive',
'menu_position' =&gt; 26,
'show_in_rest' =&gt; true,
'labels' =&gt; $labels,
'supports' =&gt; $supports,
]</code>
<code>false</code>
</InvalidArgument>
<PossiblyInvalidPropertyFetch>
<code>$post-&gt;post_name</code>
</PossiblyInvalidPropertyFetch>
<UndefinedPropertyFetch>
<code>$object-&gt;add_archive_page</code>
<code>$wpPostType-&gt;add_archive_page</code>
<code>$wpPostType-&gt;add_archive_page</code>
</UndefinedPropertyFetch>
</file>
<file src="src/CustomPostType.php">
<PossiblyInvalidDocblockTag>
<code>@var array $args</code>
<code>@var array|bool $rewrite {</code>
<code>@var array|string $default_term {</code>
<code>@var bool $_builtin</code>
<code>@var bool $hierarchical</code>
<code>@var bool $public</code>
<code>@var bool $publicly_queryable</code>
<code>@var bool $show_admin_column</code>
<code>@var bool $show_in_menu</code>
<code>@var bool $show_in_nav_menus</code>
<code>@var bool $show_in_quick_edit</code>
<code>@var bool $show_in_rest</code>
<code>@var bool $show_tagcloud</code>
<code>@var bool $show_ui</code>
<code>@var bool $sort</code>
<code>@var bool|callable $meta_box_cb</code>
<code>@var bool|string $query_var</code>
<code>@var callable $meta_box_sanitize_cb</code>
<code>@var callable $update_count_callback</code>
<code>@var string $description</code>
<code>@var string $rest_base</code>
<code>@var string $rest_controller_class</code>
<code>@var string $rest_namespace</code>
<code>@var string[] $capabilities {</code>
<code>@var string[] $labels</code>
</PossiblyInvalidDocblockTag>
<ArgumentTypeCoercion>
<code>$options</code>
</ArgumentTypeCoercion>
<NoValue>
<code>$col</code>
</NoValue>
</file>
</files>
5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@
</stubs>
<globals>
<var name="ABSPATH" type="string"/>
<var name="wpdb" type="\wpdb"/>
<var name="post" type="\WP_Post|null"/>
<var name="current_screen" type="\WP_Screen|null"/>
<var name="post_type" type="string|null"/>
<var name="post_type_object" type="null|\WP_Post_Type"/>
</globals>
</psalm>
37 changes: 24 additions & 13 deletions src/ArchivePostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ArchivePostType implements AutoloadInterface {
private const ARCHIVE_POST_TYPE = 'hdptap_cpt_archive';

/**
* @var array<string,false|\WP_Post>
* @var array<array-key|string,\WP_Post>
*/
private static array $store = [];

Expand Down Expand Up @@ -132,12 +132,15 @@ private static function createArchivePages(string $postType, \WP_Post_Type $wpPo
private static function adminMenuCorrection(string $parentFile = ''): string {
global $current_screen;

if (!$current_screen instanceof \WP_Screen) {
return $parentFile;
}

/** @var null|int $postId */
$postId = filter_input(INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT);
// if this is a post edit screen for the archive page post type.
if (!empty($postId) && 'post' === $current_screen->base && self::ARCHIVE_POST_TYPE === $current_screen->post_type) {
// get the plugin options.

/** @var null|\WP_Post $post */
$post = get_post($postId);

// if we have an archive post type returned.
Expand Down Expand Up @@ -192,7 +195,7 @@ private static function archiveTitle(string $title, string $postType): string {
$archivePost = self::getPostTypeArchive($postType);

if ($archivePost instanceof \WP_Post) {
return apply_filters('the_title', $archivePost->post_title);
return (string) apply_filters('the_title', $archivePost->post_title);
}

return $title;
Expand All @@ -214,7 +217,7 @@ private static function archiveDescription(string $description, \WP_Post_Type $w
$archivePost = self::getPostTypeArchive($wpPostType->name);

if ($archivePost instanceof \WP_Post) {
return apply_filters('the_content', $archivePost->post_content);
return (string) apply_filters('the_content', $archivePost->post_content);
}

return $description;
Expand All @@ -223,14 +226,12 @@ private static function archiveDescription(string $description, \WP_Post_Type $w
return $description;
}

/**
* @return null|\WP_Post
*/
private static function getPostTypeArchive(string $postType) {
private static function getPostTypeArchive(string $postType): ?\WP_Post {
global $wpdb;

if (empty(self::$store[$postType])) {
$postId = $wpdb->get_var($wpdb->prepare(<<<SQL
/** @var string|void $prepare */
$prepare = $wpdb->prepare(<<<SQL
SELECT
ID
FROM {$wpdb->posts}
Expand All @@ -239,13 +240,23 @@ private static function getPostTypeArchive(string $postType) {
AND post_type = %s
AND post_name = %s
LIMIT 1
SQL, 'hdptap_cpt_archive', $postType));
SQL, 'hdptap_cpt_archive', $postType);

if (empty($prepare)) {
return null;
}

/** @var null|int|string $postId */
$postId = $wpdb->get_var($prepare);

if (null !== $postId) {
self::$store[$postType] = \WP_Post::get_instance((int) $postId);
/** @var \WP_Post $post */
$post = \WP_Post::get_instance((int) $postId);

self::$store[$postType] = $post;
}
}

return empty(self::$store[$postType]) ? null : self::$store[$postType];
return !empty(self::$store[$postType]) ? self::$store[$postType] : null;
}
}
50 changes: 5 additions & 45 deletions src/CustomPostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function setColumns(array $columns = []): void {
*/
static function (array $wp_columns = []) use ($columns): array {
$newColumns = [];
$newColumns['cb'] = $wp_columns['cb'];
$newColumns['title'] = $wp_columns['title'];
$date = $wp_columns['date'];
$newColumns['cb'] = (string) $wp_columns['cb'];
$newColumns['title'] = (string) $wp_columns['title'];
$date = (string) $wp_columns['date'];
unset($wp_columns['cb'], $wp_columns['title'], $wp_columns['date']);

foreach (['cb', 'title', 'date'] as $col) {
Expand All @@ -53,6 +53,7 @@ static function (array $wp_columns = []) use ($columns): array {
}
}

/** @var array<string,string> $merge */
$merge = wp_parse_args($wp_columns, $columns);

foreach ($merge as $key => $value) {
Expand Down Expand Up @@ -114,48 +115,7 @@ static function (string $col = '', int $postId = 0) use ($callback): void {
}

/**
* @param array $options {
*
* @var string[] $labels
* @var string $description
* @var bool $public
* @var bool $publicly_queryable
* @var bool $hierarchical
* @var bool $show_ui
* @var bool $show_in_menu
* @var bool $show_in_nav_menus
* @var bool $show_in_rest
* @var string $rest_base
* @var string $rest_namespace
* @var string $rest_controller_class
* @var bool $show_tagcloud
* @var bool $show_in_quick_edit
* @var bool $show_admin_column
* @var bool|callable $meta_box_cb
* @var callable $meta_box_sanitize_cb
* @var string[] $capabilities {
* @var string $manage_terms
* @var string $edit_terms
* @var string $delete_terms
* @var string $assign_terms
* }
* @var array|bool $rewrite {
* @var string $slug
* @var bool $with_front
* @var bool $hierarchical
* @var int $ep_mask
* }
* @var bool|string $query_var
* @var callable $update_count_callback
* @var array|string $default_term {
* @var string $name
* @var string $slug
* @var string $description
* }
* @var bool $sort
* @var array $args
* @var bool $_builtin
* }
* @param array<string,mixed> $options
*/
public function registerTaxonomy(string $taxonomy, array $options = []): void {
$taxonomy = sanitize_key($taxonomy);
Expand Down
11 changes: 9 additions & 2 deletions src/PostTypeMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class PostTypeMessages implements AutoloadInterface {
public function load(): void {
add_filter('post_updated_messages', /**
* @psalm-param array<string, array<string, string>> $messages
*
* @return array[]
*
* @psalm-return array<string, array<int|string, mixed>>
Expand All @@ -15,6 +17,9 @@ static function (array $messages = []): array {
return self::updatedMessages($messages);
});
add_filter('bulk_post_updated_messages', /**
* @psalm-param array<string, array<string, string>> $messages
* @psalm-param array<string, int> $counts
*
* @return string[][]
*
* @psalm-return array<string, array<string, string>>
Expand All @@ -41,6 +46,7 @@ private static function bulkUpdatedMessages(array $messages = [], array $counts
return $messages;
}

/** @var string $post_type */
if (!empty($messages[$post_type])) {
return $messages;
}
Expand Down Expand Up @@ -92,6 +98,7 @@ private static function updatedMessages(array $messages = []): array {
return $messages;
}

/** @var string $post_type */
if (!empty($messages[$post_type])) {
return $messages;
}
Expand Down Expand Up @@ -157,8 +164,8 @@ private static function getPostTypeLabelForMessages() {
return false;
}

$singular = empty($labels['singular_name']) ? false : $labels['singular_name'];
$plural = empty($labels['all_items']) ? false : $labels['all_items'];
$singular = empty($labels['singular_name']) ? false : (string) $labels['singular_name'];
$plural = empty($labels['all_items']) ? false : (string) $labels['all_items'];

if (empty($singular)) {
return false;
Expand Down

0 comments on commit 80a6972

Please sign in to comment.