Skip to content

Commit 265fbb4

Browse files
committed
Themes: Fix type issues in core themes and remove PHPStan suppression comments.
Developed in #10951 Props westonruter, sabernhardt, justlevine. See #64238, #61175. git-svn-id: https://develop.svn.wordpress.org/trunk@61676 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 02b9161 commit 265fbb4

7 files changed

Lines changed: 25 additions & 14 deletions

File tree

src/wp-content/themes/twentyfourteen/inc/featured-content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public static function delete_transient() {
212212
* @since Twenty Fourteen 1.0
213213
*
214214
* @param WP_Query $query WP_Query object.
215-
* @return WP_Query Possibly-modified WP_Query.
215+
* @return void
216216
*/
217217
public static function pre_get_posts( $query ) {
218218

src/wp-content/themes/twentytwenty/inc/template-tags.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* @param array $args Arguments for displaying the site logo either as an image or text.
3131
* @param bool $display Display or return the HTML.
32-
* @return string Compiled HTML based on our arguments.
32+
* @return string|void Compiled HTML based on our arguments.
3333
*/
3434
function twentytwenty_site_logo( $args = array(), $display = true ) {
3535
$logo = get_custom_logo();
@@ -107,7 +107,7 @@ function twentytwenty_site_logo( $args = array(), $display = true ) {
107107
* @since Twenty Twenty 1.0
108108
*
109109
* @param bool $display Display or return the HTML.
110-
* @return string The HTML to display.
110+
* @return string|void The HTML to display.
111111
*/
112112
function twentytwenty_site_description( $display = true ) {
113113
$description = get_bloginfo( 'description' );
@@ -249,7 +249,7 @@ function twentytwenty_edit_post_link( $link, $post_id, $text ) {
249249
*
250250
* @param int $post_id The ID of the post.
251251
* @param string $location The location where the meta is shown.
252-
* @return string Post meta HTML.
252+
* @return string|void Post meta HTML.
253253
*/
254254
function twentytwenty_get_post_meta( $post_id = null, $location = 'single-top' ) {
255255

src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ public function __construct() {
3535
public function register( $wp_customize ) {
3636

3737
// Change site-title & description to postMessage.
38-
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; // @phpstan-ignore-line. Assume that this setting exists.
39-
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; // @phpstan-ignore-line. Assume that this setting exists.
38+
foreach ( array( 'blogname', 'blogdescription' ) as $setting_id ) {
39+
$setting = $wp_customize->get_setting( $setting_id );
40+
if ( $setting ) {
41+
$setting->transport = 'postMessage';
42+
}
43+
}
4044

4145
// Add partial for blogname.
4246
$wp_customize->selective_refresh->add_partial(

src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function enqueue_scripts() {
9898
if ( is_rtl() ) {
9999
$url = get_template_directory_uri() . '/assets/css/style-dark-mode-rtl.css';
100100
}
101-
wp_enqueue_style( 'tt1-dark-mode', $url, array( 'twenty-twenty-one-style' ), wp_get_theme()->get( 'Version' ) ); // @phpstan-ignore-line. Version is always a string.
101+
wp_enqueue_style( 'tt1-dark-mode', $url, array( 'twenty-twenty-one-style' ), wp_get_theme()->get( 'Version' ) );
102102
}
103103

104104
/**

src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-svg-icons.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,17 @@ public static function get_svg( $group, $icon, $size ) {
181181
*
182182
* @since Twenty Twenty-One 1.0
183183
*
184-
* @param array $arr Array of icons.
184+
* @param array<string, string> $arr Array of icons.
185185
*/
186186
$arr = apply_filters( "twenty_twenty_one_svg_icons_{$group}", $arr );
187187

188188
$svg = '';
189-
if ( array_key_exists( $icon, $arr ) ) {
189+
if ( isset( $arr[ $icon ] ) && is_string( $arr[ $icon ] ) ) {
190190
$repl = sprintf( '<svg class="svg-icon" width="%d" height="%d" aria-hidden="true" role="img" focusable="false" ', $size, $size );
191191

192-
$svg = preg_replace( '/^<svg /', $repl, trim( $arr[ $icon ] ) ); // Add extra attributes to SVG code.
192+
$svg = (string) preg_replace( '/^<svg /', $repl, trim( $arr[ $icon ] ) ); // Add extra attributes to SVG code.
193193
}
194194

195-
// @phpstan-ignore-next-line.
196195
return $svg;
197196
}
198197

src/wp-content/themes/twentytwentyone/inc/template-functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ function twenty_twenty_one_get_non_latin_css( $type = 'front-end' ) {
339339
}
340340

341341
// Return the specified styles.
342-
return twenty_twenty_one_generate_css( // @phpstan-ignore-line.
342+
return twenty_twenty_one_generate_css(
343343
implode( ',', $elements[ $type ] ),
344344
'font-family',
345345
implode( ',', $font_family[ $locale ] ),
346-
null,
347-
null,
346+
'',
347+
'',
348348
false
349349
);
350350
}

src/wp-includes/class-wp-theme.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,14 @@ public function cache_delete() {
866866
*
867867
* @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
868868
* @return string|array|false String or array (for Tags header) on success, false on failure.
869+
*
870+
* @phpstan-return (
871+
* $header is 'Tags'
872+
* ? string[]|false
873+
* : ( $header is 'Name'|'ThemeURI'|'Description'|'Author'|'AuthorURI'|'Version'|'Template'|'Status'|'TextDomain'|'DomainPath'|'RequiresWP'|'RequiresPHP'|'UpdateURI'
874+
* ? string|false
875+
* : false )
876+
* )
869877
*/
870878
public function get( $header ) {
871879
if ( ! isset( $this->headers[ $header ] ) ) {

0 commit comments

Comments
 (0)