Skip to content

Commit

Permalink
Phpstan issues 1 (#405)
Browse files Browse the repository at this point in the history
* Components fixed
* Ongoing PHPStan issue addressed
* Workflow added
* Integration of Scrutinizer deleted
* Badges added & design modified
  • Loading branch information
lloc authored Nov 29, 2024
1 parent 16e55ec commit 3f2322c
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 54 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ jobs:
tag:
name: New tag
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
attestations: write
timeout-minutes: 70
steps:
- name: Checkout project
uses: actions/checkout@v4
Expand All @@ -16,7 +21,14 @@ jobs:
run: composer run-script build
- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@stable
id: deploy
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SLUG: multisite-language-switcher
with:
generate-zip: true
- name: Attest build provenance
uses: johnbillion/[email protected]
with:
zip-path: ${{ steps.deploy.outputs.zip-path }}
13 changes: 0 additions & 13 deletions .scrutinizer.yml

This file was deleted.

8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

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.

[![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/)
[![codecov](https://codecov.io/gh/lloc/Multisite-Language-Switcher/graph/badge.svg?token=IlD4bX4KZ4)](https://codecov.io/gh/lloc/Multisite-Language-Switcher)
[![WordPress Plugin Version](https://img.shields.io/wordpress/plugin/v/multisite-language-switcher.svg)](https://wordpress.org/plugins/multisite-language-switcher/)
[![License](https://img.shields.io/badge/license-GPL_v2%2B-blue.svg)](http://opensource.org/licenses/GPL-2.0)
[![WordPress Tested](https://img.shields.io/wordpress/v/multisite-language-switcher.svg)](https://wordpress.org/plugins/multisite-language-switcher/)
[![codecov](https://codecov.io/gh/lloc/Multisite-Language-Switcher/graph/badge.svg?token=IlD4bX4KZ4)](https://codecov.io/gh/lloc/Multisite-Language-Switcher)

## Where to get the plugin

[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).

_Please note that the version of Multisite Language Switcher on GitHub is a work in progress._
_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._

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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"scripts": {
"test": "vendor/bin/phpunit",
"coverage": "php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html tests/coverage",
"coverage": "@php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html tests/coverage",
"analyze": "vendor/bin/phpstan analyze",
"playwright": "npx playwright test",
"php74": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 7.4",
Expand Down
4 changes: 2 additions & 2 deletions includes/ContentImport/Importers/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
interface Importer {

/**
* @param array $data
* @param array<string, mixed> $data
*
* @return array
* @return array<string, mixed>
*/
public function import( array $data );

Expand Down
5 changes: 5 additions & 0 deletions includes/ContentImport/Importers/PostMeta/Duplicating.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public static function info() {
);
}

/**
* @param array<string, mixed> $data
*
* @return array<string, mixed>
*/
public function import( array $data ) {
$source_blog_id = $this->import_coordinates->source_blog_id;
$source_post_id = $this->import_coordinates->source_post_id;
Expand Down
7 changes: 6 additions & 1 deletion includes/ContentImport/Importers/PostThumbnail/Linking.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public static function info() {
);
}

/**
* @param array<string, mixed> $data
*
* @return array<string, mixed>
*/
public function import( array $data ) {
$source_blog_id = $this->import_coordinates->source_blog_id;
$source_post_id = $this->import_coordinates->source_post_id;
Expand Down Expand Up @@ -142,7 +147,7 @@ function ( &$entry ) {
/**
* @param int $source_post_thumbnail_id
*
* @return array
* @return array<string, mixed>
*/
protected function get_attachment_meta( $source_post_thumbnail_id ) {
$keys = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_attachment_image_alt' );
Expand Down
11 changes: 8 additions & 3 deletions includes/ContentImport/LogWriters/AdminNoticeLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class AdminNoticeLogger extends MslsRegistryInstance implements LogWriter {
*/
protected $import_coordinates;

/**
* @param array<string, mixed> $data
*
* @return void
*/
public function write( array $data ) {
/* translators: %1$d: source post ID, %2$d: source blog ID, %3$d: destination post ID, %4$d: destination blog ID */
$format = esc_html__( 'From post %1$d on site %2$d to post %3$d on site %4$d', 'multisite-language-switcher' );
Expand Down Expand Up @@ -108,9 +113,9 @@ public function write( array $data ) {
}

/**
* @param string $section_title
* @param array $entries
* @param bool $escape_entries
* @param string $section_title
* @param string[] $entries
* @param bool $escape_entries
*
* @return string
*/
Expand Down
5 changes: 2 additions & 3 deletions includes/ContentImport/LogWriters/LogWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace lloc\Msls\ContentImport\LogWriters;


interface LogWriter {
/**
* Writes the log to the destination.
*
* @param array $data An array of data to log.
* @param array<string, mixed> $data An array of data to log.
*
* @return mixed
*/
public function write( array $data );
}
}
14 changes: 14 additions & 0 deletions includes/ContentImport/MetaBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

class MetaBox extends MslsRegistryInstance {

/**
* @var array<string, mixed>
*/
protected array $data = array();

/**
Expand Down Expand Up @@ -90,6 +93,11 @@ function ( $lang ) use ( $mydata ) {
echo wp_kses( $output, Component::get_allowed_html() );
}

/**
* @param array<string, mixed> $data
*
* @return string
*/
protected function inline_thickbox_url( array $data = array() ): string {
$args = array_merge(
array(
Expand All @@ -111,6 +119,12 @@ public function print_modal_html(): void {
echo $this->inline_thickbox_html( true, $this->data );
}

/**
* @param bool $echo
* @param array<string, mixed> $data
*
* @return string
*/
protected function inline_thickbox_html( $echo = true, array $data = array() ): string {
if ( ! isset( $data['msls_import'] ) ) {
return '';
Expand Down
8 changes: 7 additions & 1 deletion includes/ContentImport/Relations.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
*/
class Relations {

/**
* @var array<int, array<int, mixed>>
*/
public array $to_create = array();

/**
* @var array<int, array<int, mixed>>
*/
protected array $local_options = array();

/**
Expand Down Expand Up @@ -45,7 +51,7 @@ public function merge( Relations $relations = null ): void {
}

/**
* @return array
* @return array<int, array<int, mixed>>
*/
public function get_data(): array {
return $this->to_create;
Expand Down
7 changes: 4 additions & 3 deletions includes/MslsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function __call( $method, $args ) {
/**
* There is something wrong? Here comes the message...
*
* @return bool
* @return void
*/
public function has_problems(): void {
$message = '';
Expand Down Expand Up @@ -381,11 +381,12 @@ public function reference_user(): void {

/* translators: %s: maximum number of users */
$format = __(
'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!',
'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!',
'multisite-language-switcher'
);

trigger_error( sprintf( esc_html( $format ), esc_attr( self::MAX_REFERENCE_USERS ) ) );
// phpcs:ignore WordPress.Security.EscapeOutput
trigger_error( sprintf( esc_html( $format ), strval( self::MAX_REFERENCE_USERS ) ) );

Check warning on line 389 in includes/MslsAdmin.php

View workflow job for this annotation

GitHub Actions / test

WordPress.PHP.DevelopmentFunctions.error_log_trigger_error

trigger_error() found. Debug code should not normally be used in production.
}

// phpcs:ignore WordPress.Security.EscapeOutput
Expand Down
24 changes: 15 additions & 9 deletions includes/MslsPostTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public function add_input( string $taxonomy ): void {
<input type="hidden" name="msls_post_type" id="msls_post_type" value="%s"/>
<input type="hidden" name="msls_action" id="msls_action" value="suggest_terms"/>';

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

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

$item_format = '<tr class="form-field">
<th scope="row">
<label for="msls_title_%1$s">%2$s</label>
<label for="msls_title_%1$d">%2$s</label>
</th>
<td>
<input type="hidden" id="msls_id_%1$s" name="msls_input_%3$s" value="%4$s"/>
<input class="msls_title" id="msls_title_%1$s" name="msls_title_%1$s" type="text" value="%5$s"/>
<input type="hidden" id="msls_id_%1$d" name="msls_input_%3$s" value="%4$s"/>
<input class="msls_title" id="msls_title_%1$d" name="msls_title_%1$d" type="text" value="%5$s"/>
</td>
</tr>';

Expand Down Expand Up @@ -195,11 +195,17 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo
}
}

echo wp_kses(
sprintf( $item_format, esc_attr( $blog->userblog_id ), $icon, esc_attr( $language ), esc_attr( $value ), esc_attr( $title ) ),
$allowed_html
$content = sprintf(
$item_format,
$blog->userblog_id,
$icon,
esc_attr( $language ),
esc_attr( $value ),
esc_attr( $title )
);

echo wp_kses( $content, $allowed_html );

restore_current_blog();
}

Expand Down
7 changes: 4 additions & 3 deletions includes/MslsPostTagClassic.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ public function print_option( MslsBlog $blog, string $type, MslsOptionsTax $myda
'hide_empty' => false,
)
);
if ( ! empty( $terms ) ) {

if ( is_array( $terms ) ) {
foreach ( $terms as $term ) {
$options .= sprintf(
'<option value="%s" %s>%s</option>',
esc_attr( $term->term_id ),
'<option value="%d" %s>%s</option>',
$term->term_id,
selected( $term->term_id, $mydata->$language, false ),
esc_html( $term->name )
);
Expand Down
24 changes: 12 additions & 12 deletions tests/phpunit/TestMslsPostTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function test_suggest(): void {

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

Expand All @@ -112,19 +112,19 @@ public function test_edit_input(): void {
</th>
</tr><tr class="form-field">
<th scope="row">
<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>
<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>
</th>
<td>
<input type="hidden" id="msls_id_" name="msls_input_de_DE" value="42"/>
<input class="msls_title" id="msls_title_" name="msls_title_" type="text" value="test-term-name"/>
<input type="hidden" id="msls_id_0" name="msls_input_de_DE" value="42"/>
<input class="msls_title" id="msls_title_0" name="msls_title_0" type="text" value="test-term-name"/>
</td>
</tr><tr class="form-field">
<th scope="row">
<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>
<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>
</th>
<td>
<input type="hidden" id="msls_id_" name="msls_input_en_US" value=""/>
<input class="msls_title" id="msls_title_" name="msls_title_" type="text" value=""/>
<input type="hidden" id="msls_id_0" name="msls_input_en_US" value=""/>
<input class="msls_title" id="msls_title_0" name="msls_title_0" type="text" value=""/>
</td>
</tr>';

Expand Down Expand Up @@ -155,11 +155,11 @@ public function test_add_input(): void {

$output = '<div class="form-field"><h3>Multisite Language Switcher</h3>
<input type="hidden" name="msls_post_type" id="msls_post_type" value="post"/>
<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>
<input type="hidden" id="msls_id_" name="msls_input_de_DE" value=""/>
<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>
<input type="hidden" id="msls_id_" name="msls_input_en_US" value=""/>
<input class="msls_title" id="msls_title_" name="msls_title_" type="text" value=""/></div>';
<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>
<input type="hidden" id="msls_id_0" name="msls_input_de_DE" value=""/>
<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>
<input type="hidden" id="msls_id_0" name="msls_input_en_US" value=""/>
<input class="msls_title" id="msls_title_0" name="msls_title_0" type="text" value=""/></div>';

$this->expectOutputString( $output );

Expand Down

0 comments on commit 3f2322c

Please sign in to comment.