Skip to content

Commit 3f2322c

Browse files
authored
Phpstan issues 1 (#405)
* Components fixed * Ongoing PHPStan issue addressed * Workflow added * Integration of Scrutinizer deleted * Badges added & design modified
1 parent 16e55ec commit 3f2322c

File tree

15 files changed

+97
-54
lines changed

15 files changed

+97
-54
lines changed

.github/workflows/deploy.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ jobs:
77
tag:
88
name: New tag
99
runs-on: ubuntu-latest
10+
permissions:
11+
id-token: write
12+
contents: read
13+
attestations: write
14+
timeout-minutes: 70
1015
steps:
1116
- name: Checkout project
1217
uses: actions/checkout@v4
@@ -16,7 +21,14 @@ jobs:
1621
run: composer run-script build
1722
- name: WordPress Plugin Deploy
1823
uses: 10up/action-wordpress-plugin-deploy@stable
24+
id: deploy
1925
env:
2026
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
2127
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
2228
SLUG: multisite-language-switcher
29+
with:
30+
generate-zip: true
31+
- name: Attest build provenance
32+
uses: johnbillion/[email protected]
33+
with:
34+
zip-path: ${{ steps.deploy.outputs.zip-path }}

.scrutinizer.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
A simple, powerful, and user-friendly plugin that adds multilingual support to your [WordPress multisite](https://wordpress.org/documentation/article/create-a-network/) installation, whether using multiple subdomains or folders. Multisite Language Switcher allows you to effortlessly manage translations for posts, pages, custom post types, categories, tags, and custom taxonomies.
44

5-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lloc/Multisite-Language-Switcher/badges/quality-score.png?s=a2e5dbac2690bbd427f2d48b84473482e7e24fdb)](https://scrutinizer-ci.com/g/lloc/Multisite-Language-Switcher/)
6-
[![codecov](https://codecov.io/gh/lloc/Multisite-Language-Switcher/graph/badge.svg?token=IlD4bX4KZ4)](https://codecov.io/gh/lloc/Multisite-Language-Switcher)
5+
[![WordPress Plugin Version](https://img.shields.io/wordpress/plugin/v/multisite-language-switcher.svg)](https://wordpress.org/plugins/multisite-language-switcher/)
6+
[![License](https://img.shields.io/badge/license-GPL_v2%2B-blue.svg)](http://opensource.org/licenses/GPL-2.0)
7+
[![WordPress Tested](https://img.shields.io/wordpress/v/multisite-language-switcher.svg)](https://wordpress.org/plugins/multisite-language-switcher/)
8+
[![codecov](https://codecov.io/gh/lloc/Multisite-Language-Switcher/graph/badge.svg?token=IlD4bX4KZ4)](https://codecov.io/gh/lloc/Multisite-Language-Switcher)
79

810
## Where to get the plugin
911

1012
[Download](http://downloads.wordpress.org/plugin/multisite-language-switcher.zip) the latest stable from the [WordPress Plugin Directory](https://wordpress.org/plugins/multisite-language-switcher/), and please remember to give this plugin [a five-star rating](https://wordpress.org/support/plugin/multisite-language-switcher/reviews/#new-post).
1113

12-
_Please note that the version of Multisite Language Switcher on GitHub is a work in progress._
14+
_Please note that while the master branch on GitHub is intended to be stable, it is not recommended for production use. Instead, please use the [official releases](https://github.com/lloc/Multisite-Language-Switcher/releases) for deployment._
1315

1416
If you plan to use the GitHub repository on a server, don't forget to run `composer install --no-dev`.
1517

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"scripts": {
3636
"test": "vendor/bin/phpunit",
37-
"coverage": "php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html tests/coverage",
37+
"coverage": "@php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html tests/coverage",
3838
"analyze": "vendor/bin/phpstan analyze",
3939
"playwright": "npx playwright test",
4040
"php74": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 7.4",

includes/ContentImport/Importers/Importer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
interface Importer {
1010

1111
/**
12-
* @param array $data
12+
* @param array<string, mixed> $data
1313
*
14-
* @return array
14+
* @return array<string, mixed>
1515
*/
1616
public function import( array $data );
1717

includes/ContentImport/Importers/PostMeta/Duplicating.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public static function info() {
2222
);
2323
}
2424

25+
/**
26+
* @param array<string, mixed> $data
27+
*
28+
* @return array<string, mixed>
29+
*/
2530
public function import( array $data ) {
2631
$source_blog_id = $this->import_coordinates->source_blog_id;
2732
$source_post_id = $this->import_coordinates->source_post_id;

includes/ContentImport/Importers/PostThumbnail/Linking.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public static function info() {
3232
);
3333
}
3434

35+
/**
36+
* @param array<string, mixed> $data
37+
*
38+
* @return array<string, mixed>
39+
*/
3540
public function import( array $data ) {
3641
$source_blog_id = $this->import_coordinates->source_blog_id;
3742
$source_post_id = $this->import_coordinates->source_post_id;
@@ -142,7 +147,7 @@ function ( &$entry ) {
142147
/**
143148
* @param int $source_post_thumbnail_id
144149
*
145-
* @return array
150+
* @return array<string, mixed>
146151
*/
147152
protected function get_attachment_meta( $source_post_thumbnail_id ) {
148153
$keys = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_attachment_image_alt' );

includes/ContentImport/LogWriters/AdminNoticeLogger.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ class AdminNoticeLogger extends MslsRegistryInstance implements LogWriter {
1515
*/
1616
protected $import_coordinates;
1717

18+
/**
19+
* @param array<string, mixed> $data
20+
*
21+
* @return void
22+
*/
1823
public function write( array $data ) {
1924
/* translators: %1$d: source post ID, %2$d: source blog ID, %3$d: destination post ID, %4$d: destination blog ID */
2025
$format = esc_html__( 'From post %1$d on site %2$d to post %3$d on site %4$d', 'multisite-language-switcher' );
@@ -108,9 +113,9 @@ public function write( array $data ) {
108113
}
109114

110115
/**
111-
* @param string $section_title
112-
* @param array $entries
113-
* @param bool $escape_entries
116+
* @param string $section_title
117+
* @param string[] $entries
118+
* @param bool $escape_entries
114119
*
115120
* @return string
116121
*/

includes/ContentImport/LogWriters/LogWriter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace lloc\Msls\ContentImport\LogWriters;
44

5-
65
interface LogWriter {
76
/**
87
* Writes the log to the destination.
98
*
10-
* @param array $data An array of data to log.
9+
* @param array<string, mixed> $data An array of data to log.
1110
*
1211
* @return mixed
1312
*/
1413
public function write( array $data );
15-
}
14+
}

includes/ContentImport/MetaBox.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
class MetaBox extends MslsRegistryInstance {
1616

17+
/**
18+
* @var array<string, mixed>
19+
*/
1720
protected array $data = array();
1821

1922
/**
@@ -90,6 +93,11 @@ function ( $lang ) use ( $mydata ) {
9093
echo wp_kses( $output, Component::get_allowed_html() );
9194
}
9295

96+
/**
97+
* @param array<string, mixed> $data
98+
*
99+
* @return string
100+
*/
93101
protected function inline_thickbox_url( array $data = array() ): string {
94102
$args = array_merge(
95103
array(
@@ -111,6 +119,12 @@ public function print_modal_html(): void {
111119
echo $this->inline_thickbox_html( true, $this->data );
112120
}
113121

122+
/**
123+
* @param bool $echo
124+
* @param array<string, mixed> $data
125+
*
126+
* @return string
127+
*/
114128
protected function inline_thickbox_html( $echo = true, array $data = array() ): string {
115129
if ( ! isset( $data['msls_import'] ) ) {
116130
return '';

includes/ContentImport/Relations.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
*/
1414
class Relations {
1515

16+
/**
17+
* @var array<int, array<int, mixed>>
18+
*/
1619
public array $to_create = array();
1720

21+
/**
22+
* @var array<int, array<int, mixed>>
23+
*/
1824
protected array $local_options = array();
1925

2026
/**
@@ -45,7 +51,7 @@ public function merge( Relations $relations = null ): void {
4551
}
4652

4753
/**
48-
* @return array
54+
* @return array<int, array<int, mixed>>
4955
*/
5056
public function get_data(): array {
5157
return $this->to_create;

includes/MslsAdmin.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function __call( $method, $args ) {
124124
/**
125125
* There is something wrong? Here comes the message...
126126
*
127-
* @return bool
127+
* @return void
128128
*/
129129
public function has_problems(): void {
130130
$message = '';
@@ -381,11 +381,12 @@ public function reference_user(): void {
381381

382382
/* translators: %s: maximum number of users */
383383
$format = __(
384-
'Multisite Language Switcher: Collection for reference user has been truncated because it exceeded the maximum of %s users. Please, use the hook "msls_reference_users" to filter the result before!',
384+
'Multisite Language Switcher: Collection for reference user has been truncated because it exceeded the maximum of %d users. Please, use the hook "msls_reference_users" to filter the result before!',
385385
'multisite-language-switcher'
386386
);
387387

388-
trigger_error( sprintf( esc_html( $format ), esc_attr( self::MAX_REFERENCE_USERS ) ) );
388+
// phpcs:ignore WordPress.Security.EscapeOutput
389+
trigger_error( sprintf( esc_html( $format ), strval( self::MAX_REFERENCE_USERS ) ) );
389390
}
390391

391392
// phpcs:ignore WordPress.Security.EscapeOutput

includes/MslsPostTag.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ public function add_input( string $taxonomy ): void {
106106
<input type="hidden" name="msls_post_type" id="msls_post_type" value="%s"/>
107107
<input type="hidden" name="msls_action" id="msls_action" value="suggest_terms"/>';
108108

109-
$item_format = '<label for="msls_title_%1$s">%2$s</label>
110-
<input type="hidden" id="msls_id_%1$s" name="msls_input_%3$s" value="%4$s"/>
111-
<input class="msls_title" id="msls_title_%1$s" name="msls_title_%1$s" type="text" value="%5$s"/>';
109+
$item_format = '<label for="msls_title_%1$d">%2$s</label>
110+
<input type="hidden" id="msls_id_%1$d" name="msls_input_%3$s" value="%4$s"/>
111+
<input class="msls_title" id="msls_title_%1$d" name="msls_title_%1$d" type="text" value="%5$s"/>';
112112

113113
echo '<div class="form-field">';
114114
$this->the_input( null, $title_format, $item_format );
@@ -138,11 +138,11 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void {
138138

139139
$item_format = '<tr class="form-field">
140140
<th scope="row">
141-
<label for="msls_title_%1$s">%2$s</label>
141+
<label for="msls_title_%1$d">%2$s</label>
142142
</th>
143143
<td>
144-
<input type="hidden" id="msls_id_%1$s" name="msls_input_%3$s" value="%4$s"/>
145-
<input class="msls_title" id="msls_title_%1$s" name="msls_title_%1$s" type="text" value="%5$s"/>
144+
<input type="hidden" id="msls_id_%1$d" name="msls_input_%3$s" value="%4$s"/>
145+
<input class="msls_title" id="msls_title_%1$d" name="msls_title_%1$d" type="text" value="%5$s"/>
146146
</td>
147147
</tr>';
148148

@@ -195,11 +195,17 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo
195195
}
196196
}
197197

198-
echo wp_kses(
199-
sprintf( $item_format, esc_attr( $blog->userblog_id ), $icon, esc_attr( $language ), esc_attr( $value ), esc_attr( $title ) ),
200-
$allowed_html
198+
$content = sprintf(
199+
$item_format,
200+
$blog->userblog_id,
201+
$icon,
202+
esc_attr( $language ),
203+
esc_attr( $value ),
204+
esc_attr( $title )
201205
);
202206

207+
echo wp_kses( $content, $allowed_html );
208+
203209
restore_current_blog();
204210
}
205211

includes/MslsPostTagClassic.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ public function print_option( MslsBlog $blog, string $type, MslsOptionsTax $myda
131131
'hide_empty' => false,
132132
)
133133
);
134-
if ( ! empty( $terms ) ) {
134+
135+
if ( is_array( $terms ) ) {
135136
foreach ( $terms as $term ) {
136137
$options .= sprintf(
137-
'<option value="%s" %s>%s</option>',
138-
esc_attr( $term->term_id ),
138+
'<option value="%d" %s>%s</option>',
139+
$term->term_id,
139140
selected( $term->term_id, $mydata->$language, false ),
140141
esc_html( $term->name )
141142
);

tests/phpunit/TestMslsPostTag.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function test_suggest(): void {
8686

8787
public function test_edit_input(): void {
8888
$taxonomy = \Mockery::mock( MslsTaxonomy::class );
89-
$taxonomy->shouldReceive( 'is_taxonomy' )->atLeast()->once()->andReturnTrue();
89+
$taxonomy->shouldReceive( 'is_taxonomy' )->atLeast()->once()->andReturn( true );
9090
$taxonomy->shouldReceive( 'get_request' )->atLeast()->once()->andReturn( 'post' );
9191
$taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( array( 'taxonomy', 'post_tag' ) );
9292

@@ -112,19 +112,19 @@ public function test_edit_input(): void {
112112
</th>
113113
</tr><tr class="form-field">
114114
<th scope="row">
115-
<label for="msls_title_"><a title="Edit the translation in the de_DE-blog" href="edit_term_link"><span class="language-badge de_DE"><span>de</span><span>DE</span></span></a>&nbsp;</label>
115+
<label for="msls_title_0"><a title="Edit the translation in the de_DE-blog" href="edit_term_link"><span class="language-badge de_DE"><span>de</span><span>DE</span></span></a>&nbsp;</label>
116116
</th>
117117
<td>
118-
<input type="hidden" id="msls_id_" name="msls_input_de_DE" value="42"/>
119-
<input class="msls_title" id="msls_title_" name="msls_title_" type="text" value="test-term-name"/>
118+
<input type="hidden" id="msls_id_0" name="msls_input_de_DE" value="42"/>
119+
<input class="msls_title" id="msls_title_0" name="msls_title_0" type="text" value="test-term-name"/>
120120
</td>
121121
</tr><tr class="form-field">
122122
<th scope="row">
123-
<label for="msls_title_"><a title="Create a new translation in the en_US-blog" href="/wp-admin/edit-tags.php"><span class="language-badge en_US"><span>en</span><span>US</span></span></a>&nbsp;</label>
123+
<label for="msls_title_0"><a title="Create a new translation in the en_US-blog" href="/wp-admin/edit-tags.php"><span class="language-badge en_US"><span>en</span><span>US</span></span></a>&nbsp;</label>
124124
</th>
125125
<td>
126-
<input type="hidden" id="msls_id_" name="msls_input_en_US" value=""/>
127-
<input class="msls_title" id="msls_title_" name="msls_title_" type="text" value=""/>
126+
<input type="hidden" id="msls_id_0" name="msls_input_en_US" value=""/>
127+
<input class="msls_title" id="msls_title_0" name="msls_title_0" type="text" value=""/>
128128
</td>
129129
</tr>';
130130

@@ -155,11 +155,11 @@ public function test_add_input(): void {
155155

156156
$output = '<div class="form-field"><h3>Multisite Language Switcher</h3>
157157
<input type="hidden" name="msls_post_type" id="msls_post_type" value="post"/>
158-
<input type="hidden" name="msls_action" id="msls_action" value="suggest_terms"/><label for="msls_title_"><a title="Create a new translation in the de_DE-blog" href="/wp-admin/edit-tags.php"><span class="language-badge de_DE"><span>de</span><span>DE</span></span></a>&nbsp;</label>
159-
<input type="hidden" id="msls_id_" name="msls_input_de_DE" value=""/>
160-
<input class="msls_title" id="msls_title_" name="msls_title_" type="text" value=""/><label for="msls_title_"><a title="Create a new translation in the en_US-blog" href="/wp-admin/edit-tags.php"><span class="language-badge en_US"><span>en</span><span>US</span></span></a>&nbsp;</label>
161-
<input type="hidden" id="msls_id_" name="msls_input_en_US" value=""/>
162-
<input class="msls_title" id="msls_title_" name="msls_title_" type="text" value=""/></div>';
158+
<input type="hidden" name="msls_action" id="msls_action" value="suggest_terms"/><label for="msls_title_0"><a title="Create a new translation in the de_DE-blog" href="/wp-admin/edit-tags.php"><span class="language-badge de_DE"><span>de</span><span>DE</span></span></a>&nbsp;</label>
159+
<input type="hidden" id="msls_id_0" name="msls_input_de_DE" value=""/>
160+
<input class="msls_title" id="msls_title_0" name="msls_title_0" type="text" value=""/><label for="msls_title_0"><a title="Create a new translation in the en_US-blog" href="/wp-admin/edit-tags.php"><span class="language-badge en_US"><span>en</span><span>US</span></span></a>&nbsp;</label>
161+
<input type="hidden" id="msls_id_0" name="msls_input_en_US" value=""/>
162+
<input class="msls_title" id="msls_title_0" name="msls_title_0" type="text" value=""/></div>';
163163

164164
$this->expectOutputString( $output );
165165

0 commit comments

Comments
 (0)