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
16 changes: 8 additions & 8 deletions .distignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/.wordpress-org
.distignore
.gitattributes
.gitignore
.scrutinizer.yml
/.git
/.github
/.idea
/.phpunit.cache
/.vscode
/.wordpress-org
/bin
/build
/diagrams
Expand All @@ -14,22 +18,18 @@
/out
/src
/tests
.distignore
.gitattributes
.gitignore
.scrutinizer.yml
Changelog.md
Diagrams.md
README.md
composer.json
composer.lock
multisite-language-switcher.zip
package-lock.json
package.json
patchwork.json
phpcs.xml
phpdoc.xml
phpstan.neon
phpstan.neon.dist
phpunit.xml
playwright.config.ts
setup.sh
multisite-language-switcher.zip
setup.sh
10 changes: 10 additions & 0 deletions MultisiteLanguageSwitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ function msls_get_query(): ?\lloc\Msls\MslsOptionsQuery {
return \lloc\Msls\MslsOptionsQuery::create();
}

/**
* Trivial void function for actions that do not return anything.
*
* @return void
*/
if ( ! function_exists( '__return_void' ) ) {
function __return_void(): void {
}
}

lloc\Msls\MslsPlugin::init();
lloc\Msls\MslsCli::init();
}
2 changes: 1 addition & 1 deletion build/translations.json

Large diffs are not rendered by default.

19 changes: 6 additions & 13 deletions includes/ContentImport/ContentImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,8 @@
* @var MslsMain
*/
protected $main;

/**
* @var ImportLogger
*/
protected $logger;
/**
* @var Relations
*/
protected $relations;
protected ?ImportLogger $logger;
protected ?Relations $relations;

/**
* @var bool Whether the class should handle requests or not.
Expand All @@ -48,9 +41,9 @@
/**
* ContentImporter constructor.
*
* @param \lloc\Msls\MslsMain|null $main
* @param ?MslsMain $main
*/
public function __construct( MslsMain $main = null ) {
public function __construct( ?MslsMain $main = null ) {
$this->main = $main ?: MslsMain::create();
}

Expand Down Expand Up @@ -154,7 +147,7 @@
return false;
}

if ( ! isset( $_POST['msls_import'] ) ) {

Check warning on line 150 in includes/ContentImport/ContentImporter.php

View workflow job for this annotation

GitHub Actions / test

WordPress.Security.NonceVerification.Missing

Processing form data without nonce verification.
return false;
}

Expand Down Expand Up @@ -237,9 +230,9 @@

// also prevent MSLS from saving
if ( false === $handle ) {
add_action( 'msls_main_save', '__return_false' );
add_action( 'msls_main_save', '__return_void' );
} else {
remove_action( 'msls_main_save', '__return_false' );
remove_action( 'msls_main_save', '__return_void' );
}
}

Expand Down Expand Up @@ -381,7 +374,7 @@
return $empty;
}

if ( ! isset( $_POST['msls_import'] ) ) {

Check warning on line 377 in includes/ContentImport/ContentImporter.php

View workflow job for this annotation

GitHub Actions / test

WordPress.Security.NonceVerification.Missing

Processing form data without nonce verification.
return $empty;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/ContentImport/Importers/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function ( $factory ) use ( $import_coordinates ) {
/**
* Returns a filtered list of factories that will provide the importers.
*
* @return array An associative array in the shape [ <string: $slug> => <ImportersFactory: $factory> ]
* @return array<string, ImportersBaseFactory> An associative array in the shape [ <string: $slug> => <ImportersFactory: $factory> ]
* @since TBD
*/
public function factories() {
Expand Down
6 changes: 3 additions & 3 deletions includes/ContentImport/Relations.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ protected function create_local_to_source(): void {
/**
* Sets a relation that should be created.
*
* @param OptionsTaxInterface $creator
* @param string $dest_lang
* @param int $dest_post_id
* @param OptionsInterface $creator
* @param string $dest_lang
* @param int $dest_post_id
*/
public function should_create( OptionsInterface $creator, $dest_lang, $dest_post_id ): void {
$this->to_create[] = array( $creator, $dest_lang, $dest_post_id );
Expand Down
19 changes: 19 additions & 0 deletions includes/LinkInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace lloc\Msls;

/**
* Interface for the link types
*
* @property string $txt
* @property string $src
* @property string $alt
* @property string $url
*
* @package Msls
* @phpstan-require-extends MslsLink
*/
interface LinkInterface {

public function __toString(): string;
}
8 changes: 1 addition & 7 deletions includes/MslsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
* Register the form-elements
*/
public function register(): void {
register_setting( 'msls', 'msls', array( $this, 'validate' ) );

Check warning on line 206 in includes/MslsAdmin.php

View workflow job for this annotation

GitHub Actions / test

PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic

Dynamic argument passed in third parameter of register_setting(). Please ensure proper sanitization.

$sections = array(
'language_section' => __( 'Language Settings', 'multisite-language-switcher' ),
Expand Down Expand Up @@ -386,7 +386,7 @@
);

// 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 Expand Up @@ -426,13 +426,7 @@
*/
public function render_rewrite( $key ): void {
$rewrite = get_post_type_object( $key )->rewrite;

$value = '';
if ( true === $rewrite ) {
$value = $key;
} elseif ( ! empty( $rewrite['slug'] ) ) {
$value = $rewrite['slug'];
}
$value = $rewrite['slug'] ?? '';

// phpcs:ignore WordPress.Security.EscapeOutput
echo ( new Text( "rewrite_{$key}", $value, 30, true ) )->render();
Expand Down
6 changes: 3 additions & 3 deletions includes/MslsBlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function get_alpha2() {
}

/**
* @param MslsOptions $options
* @param OptionsInterface $options
*
* @return string|null
*/
Expand All @@ -123,9 +123,9 @@ public function get_url( $options ) {
}

/**
* @param MslsOptions $options
* @param OptionsInterface $options
*
* @return string|null
* @return ?string
*/
protected function get_permalink( $options ) {
$url = null;
Expand Down
20 changes: 7 additions & 13 deletions includes/MslsLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
* Link type: Image and text
*
* @package Msls
* @property string $txt
* @property string $src
* @property string $alt
* @property string $url
*/
class MslsLink extends MslsGetSet {
class MslsLink extends MslsGetSet implements LinkInterface {

/**
* Output format
Expand Down Expand Up @@ -63,9 +59,9 @@ public static function get_types_description(): array {
*
* @param ?int $display
*
* @return MslsLink
* @return LinkInterface
*/
public static function create( ?int $display ): MslsLink {
public static function create( ?int $display ): LinkInterface {
$types = self::get_types();
if ( ! in_array( $display, array_keys( $types ), true ) ) {
$display = 0;
Expand All @@ -75,13 +71,13 @@ public static function create( ?int $display ): MslsLink {

if ( has_filter( 'msls_link_create' ) ) {
/**
* @param MslsLink $obj
* @param LinkInterface $obj
* @param int $display
*
* @return MslsLink
* @return LinkInterface
*/
$obj = apply_filters( 'msls_link_create', $obj, $display );
if ( in_array( __CLASS__, $types ) || is_subclass_of( $obj, __CLASS__ ) ) {
if ( $obj instanceof LinkInterface ) {
return $obj;
}
}
Expand All @@ -102,10 +98,8 @@ public static function callback( $x ) {

/**
* Handles the request to print the object
*
* @return string
*/
public function __toString() {
public function __toString(): string {
$temp = $this->get_arr();

return str_replace(
Expand Down
2 changes: 1 addition & 1 deletion includes/MslsLinkImageOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @package Msls
*/
class MslsLinkImageOnly extends MslsLink {
class MslsLinkImageOnly extends MslsLink implements LinkInterface {

/**
* Output format
Expand Down
2 changes: 1 addition & 1 deletion includes/MslsLinkTextImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
*
* @package Msls
*/
class MslsLinkTextImage extends MslsLink {
class MslsLinkTextImage extends MslsLink implements LinkInterface {

/**
* Output format
*
* @var string
*/
protected $format_string = '{txt} <img src="{src}" alt="{alt}"/>';

Check warning on line 17 in includes/MslsLinkTextImage.php

View workflow job for this annotation

GitHub Actions / test

PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage

Images should be added using wp_get_attachment_image() or similar functions

/**
* Get the description
Expand Down
2 changes: 1 addition & 1 deletion includes/MslsLinkTextOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @package Msls
*/
class MslsLinkTextOnly extends MslsLink {
class MslsLinkTextOnly extends MslsLink implements LinkInterface {

/**
* Output format
Expand Down
13 changes: 3 additions & 10 deletions includes/MslsOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MslsOptions extends MslsGetSet implements OptionsInterface {
*
* @param int $id
*
* @return MslsOptions
* @return OptionsInterface
*/
public static function create( $id = 0 ) {
if ( is_admin() ) {
Expand Down Expand Up @@ -195,12 +195,7 @@ public function set( $arr ): bool {
return true;
}

/**
* @param string $language
*
* @return string
*/
public function get_permalink( $language ) {
public function get_permalink( string $language ): string {
/**
* Filters the url by language
*
Expand Down Expand Up @@ -240,10 +235,8 @@ public function get_tax_query() {

/**
* Get current link
*
* @return string
*/
public function get_current_link() {
public function get_current_link(): string {
return home_url( '/' );
}

Expand Down
2 changes: 1 addition & 1 deletion includes/MslsOptionsQueryAuthor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function has_value( string $language ): bool {
*
* @return string
*/
public function get_current_link() {
public function get_current_link(): string {
return get_author_posts_url( $this->author_id );
}
}
2 changes: 1 addition & 1 deletion includes/MslsOptionsQueryDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function has_value( string $language ): bool {
*
* @return string
*/
public function get_current_link() {
public function get_current_link(): string {
return get_day_link( $this->year, $this->monthnum, $this->day );
}
}
2 changes: 1 addition & 1 deletion includes/MslsOptionsQueryPostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function has_value( string $language ): bool {
*
* @return string
*/
public function get_current_link() {
public function get_current_link(): string {
return (string) get_post_type_archive_link( $this->post_type );
}
}
2 changes: 1 addition & 1 deletion includes/MslsOptionsTax.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function get_postlink( $language ) {
*
* @return string
*/
public function get_current_link() {
public function get_current_link(): string {
return $this->get_term_link( $this->get_arg( 0, 0 ) );
}

Expand Down
8 changes: 4 additions & 4 deletions includes/MslsOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function get( ?int $display, bool $filter = false, $exists = false ): arr
* Returns HTML-link for an item of the output-arr
*
* @param string $url
* @param MslsLink $link
* @param LinkInterface $link
* @param bool $is_current_blog
*
* @since 0.9.8
Expand Down Expand Up @@ -190,9 +190,9 @@ public function set_tags( array $arr = array() ): MslsOutput {
/**
* Returns true if the requirements not fulfilled
*
* @param MslsOptions|null $thing
* @param boolean $exists
* @param string $language
* @param ?OptionsInterface $thing
* @param boolean $exists
* @param string $language
*
* @return boolean
*/
Expand Down
5 changes: 5 additions & 0 deletions includes/OptionsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@

interface OptionsInterface {

public function has_value( string $key ): bool;

public function get_current_link(): string;

public function get_permalink( string $language ): string;
}
4 changes: 2 additions & 2 deletions tests/phpunit/TestMslsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ function test_rewrite_pinko(): void {
$obj = $this->MslsAdminFactory();

$post_type = \Mockery::mock( \WP_Post_Type::class );
$post_type->rewrite = true;
$post_type->rewrite = true; // this should not be possible

Functions\when( 'get_post_type_object' )->justReturn( $post_type );

$this->expectOutputString(
'<input type="text" class="regular-text" id="rewrite_pinko" name="msls[rewrite_pinko]" value="pinko" size="30" readonly="readonly"/>'
'<input type="text" class="regular-text" id="rewrite_pinko" name="msls[rewrite_pinko]" value="" size="30" readonly="readonly"/>'
);
$obj->rewrite_pinko( 'pinko' );
}
Expand Down
Loading