Skip to content

Commit 93b8a91

Browse files
authored
PHPStan Level 5 reached (#413)
* PHPStan Level 5 reached * Sort lines in .distignore
1 parent de24979 commit 93b8a91

21 files changed

+80
-72
lines changed

.distignore

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
/.wordpress-org
1+
.distignore
2+
.gitattributes
3+
.gitignore
4+
.scrutinizer.yml
25
/.git
36
/.github
47
/.idea
58
/.phpunit.cache
69
/.vscode
10+
/.wordpress-org
711
/bin
812
/build
913
/diagrams
@@ -14,22 +18,18 @@
1418
/out
1519
/src
1620
/tests
17-
.distignore
18-
.gitattributes
19-
.gitignore
20-
.scrutinizer.yml
2121
Changelog.md
2222
Diagrams.md
2323
README.md
2424
composer.json
2525
composer.lock
26+
multisite-language-switcher.zip
2627
package-lock.json
2728
package.json
2829
patchwork.json
2930
phpcs.xml
3031
phpdoc.xml
31-
phpstan.neon
32+
phpstan.neon.dist
3233
phpunit.xml
3334
playwright.config.ts
34-
setup.sh
35-
multisite-language-switcher.zip
35+
setup.sh

MultisiteLanguageSwitcher.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ function msls_get_query(): ?\lloc\Msls\MslsOptionsQuery {
230230
return \lloc\Msls\MslsOptionsQuery::create();
231231
}
232232

233+
/**
234+
* Trivial void function for actions that do not return anything.
235+
*
236+
* @return void
237+
*/
238+
if ( ! function_exists( '__return_void' ) ) {
239+
function __return_void(): void {
240+
}
241+
}
242+
233243
lloc\Msls\MslsPlugin::init();
234244
lloc\Msls\MslsCli::init();
235245
}

build/translations.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

includes/ContentImport/ContentImporter.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,8 @@ class ContentImporter extends MslsRegistryInstance {
2525
* @var MslsMain
2626
*/
2727
protected $main;
28-
29-
/**
30-
* @var ImportLogger
31-
*/
32-
protected $logger;
33-
/**
34-
* @var Relations
35-
*/
36-
protected $relations;
28+
protected ?ImportLogger $logger;
29+
protected ?Relations $relations;
3730

3831
/**
3932
* @var bool Whether the class should handle requests or not.
@@ -48,9 +41,9 @@ class ContentImporter extends MslsRegistryInstance {
4841
/**
4942
* ContentImporter constructor.
5043
*
51-
* @param \lloc\Msls\MslsMain|null $main
44+
* @param ?MslsMain $main
5245
*/
53-
public function __construct( MslsMain $main = null ) {
46+
public function __construct( ?MslsMain $main = null ) {
5447
$this->main = $main ?: MslsMain::create();
5548
}
5649

@@ -237,9 +230,9 @@ public function handle( $handle ) {
237230

238231
// also prevent MSLS from saving
239232
if ( false === $handle ) {
240-
add_action( 'msls_main_save', '__return_false' );
233+
add_action( 'msls_main_save', '__return_void' );
241234
} else {
242-
remove_action( 'msls_main_save', '__return_false' );
235+
remove_action( 'msls_main_save', '__return_void' );
243236
}
244237
}
245238

includes/ContentImport/Importers/Map.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function ( $factory ) use ( $import_coordinates ) {
4141
/**
4242
* Returns a filtered list of factories that will provide the importers.
4343
*
44-
* @return array An associative array in the shape [ <string: $slug> => <ImportersFactory: $factory> ]
44+
* @return array<string, ImportersBaseFactory> An associative array in the shape [ <string: $slug> => <ImportersFactory: $factory> ]
4545
* @since TBD
4646
*/
4747
public function factories() {

includes/ContentImport/Relations.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ protected function create_local_to_source(): void {
115115
/**
116116
* Sets a relation that should be created.
117117
*
118-
* @param OptionsTaxInterface $creator
119-
* @param string $dest_lang
120-
* @param int $dest_post_id
118+
* @param OptionsInterface $creator
119+
* @param string $dest_lang
120+
* @param int $dest_post_id
121121
*/
122122
public function should_create( OptionsInterface $creator, $dest_lang, $dest_post_id ): void {
123123
$this->to_create[] = array( $creator, $dest_lang, $dest_post_id );

includes/LinkInterface.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace lloc\Msls;
4+
5+
/**
6+
* Interface for the link types
7+
*
8+
* @property string $txt
9+
* @property string $src
10+
* @property string $alt
11+
* @property string $url
12+
*
13+
* @package Msls
14+
* @phpstan-require-extends MslsLink
15+
*/
16+
interface LinkInterface {
17+
18+
public function __toString(): string;
19+
}

includes/MslsAdmin.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,7 @@ public function content_priority(): void {
426426
*/
427427
public function render_rewrite( $key ): void {
428428
$rewrite = get_post_type_object( $key )->rewrite;
429-
430-
$value = '';
431-
if ( true === $rewrite ) {
432-
$value = $key;
433-
} elseif ( ! empty( $rewrite['slug'] ) ) {
434-
$value = $rewrite['slug'];
435-
}
429+
$value = $rewrite['slug'] ?? '';
436430

437431
// phpcs:ignore WordPress.Security.EscapeOutput
438432
echo ( new Text( "rewrite_{$key}", $value, 30, true ) )->render();

includes/MslsBlog.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function get_alpha2() {
110110
}
111111

112112
/**
113-
* @param MslsOptions $options
113+
* @param OptionsInterface $options
114114
*
115115
* @return string|null
116116
*/
@@ -123,9 +123,9 @@ public function get_url( $options ) {
123123
}
124124

125125
/**
126-
* @param MslsOptions $options
126+
* @param OptionsInterface $options
127127
*
128-
* @return string|null
128+
* @return ?string
129129
*/
130130
protected function get_permalink( $options ) {
131131
$url = null;

includes/MslsLink.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
* Link type: Image and text
77
*
88
* @package Msls
9-
* @property string $txt
10-
* @property string $src
11-
* @property string $alt
12-
* @property string $url
139
*/
14-
class MslsLink extends MslsGetSet {
10+
class MslsLink extends MslsGetSet implements LinkInterface {
1511

1612
/**
1713
* Output format
@@ -63,9 +59,9 @@ public static function get_types_description(): array {
6359
*
6460
* @param ?int $display
6561
*
66-
* @return MslsLink
62+
* @return LinkInterface
6763
*/
68-
public static function create( ?int $display ): MslsLink {
64+
public static function create( ?int $display ): LinkInterface {
6965
$types = self::get_types();
7066
if ( ! in_array( $display, array_keys( $types ), true ) ) {
7167
$display = 0;
@@ -75,13 +71,13 @@ public static function create( ?int $display ): MslsLink {
7571

7672
if ( has_filter( 'msls_link_create' ) ) {
7773
/**
78-
* @param MslsLink $obj
74+
* @param LinkInterface $obj
7975
* @param int $display
8076
*
81-
* @return MslsLink
77+
* @return LinkInterface
8278
*/
8379
$obj = apply_filters( 'msls_link_create', $obj, $display );
84-
if ( in_array( __CLASS__, $types ) || is_subclass_of( $obj, __CLASS__ ) ) {
80+
if ( $obj instanceof LinkInterface ) {
8581
return $obj;
8682
}
8783
}
@@ -102,10 +98,8 @@ public static function callback( $x ) {
10298

10399
/**
104100
* Handles the request to print the object
105-
*
106-
* @return string
107101
*/
108-
public function __toString() {
102+
public function __toString(): string {
109103
$temp = $this->get_arr();
110104

111105
return str_replace(

includes/MslsLinkImageOnly.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @package Msls
99
*/
10-
class MslsLinkImageOnly extends MslsLink {
10+
class MslsLinkImageOnly extends MslsLink implements LinkInterface {
1111

1212
/**
1313
* Output format

includes/MslsLinkTextImage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @package Msls
99
*/
10-
class MslsLinkTextImage extends MslsLink {
10+
class MslsLinkTextImage extends MslsLink implements LinkInterface {
1111

1212
/**
1313
* Output format

includes/MslsLinkTextOnly.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @package Msls
99
*/
10-
class MslsLinkTextOnly extends MslsLink {
10+
class MslsLinkTextOnly extends MslsLink implements LinkInterface {
1111

1212
/**
1313
* Output format

includes/MslsOptions.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class MslsOptions extends MslsGetSet implements OptionsInterface {
5959
*
6060
* @param int $id
6161
*
62-
* @return MslsOptions
62+
* @return OptionsInterface
6363
*/
6464
public static function create( $id = 0 ) {
6565
if ( is_admin() ) {
@@ -195,12 +195,7 @@ public function set( $arr ): bool {
195195
return true;
196196
}
197197

198-
/**
199-
* @param string $language
200-
*
201-
* @return string
202-
*/
203-
public function get_permalink( $language ) {
198+
public function get_permalink( string $language ): string {
204199
/**
205200
* Filters the url by language
206201
*
@@ -240,10 +235,8 @@ public function get_tax_query() {
240235

241236
/**
242237
* Get current link
243-
*
244-
* @return string
245238
*/
246-
public function get_current_link() {
239+
public function get_current_link(): string {
247240
return home_url( '/' );
248241
}
249242

includes/MslsOptionsQueryAuthor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function has_value( string $language ): bool {
4848
*
4949
* @return string
5050
*/
51-
public function get_current_link() {
51+
public function get_current_link(): string {
5252
return get_author_posts_url( $this->author_id );
5353
}
5454
}

includes/MslsOptionsQueryDay.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function has_value( string $language ): bool {
5656
*
5757
* @return string
5858
*/
59-
public function get_current_link() {
59+
public function get_current_link(): string {
6060
return get_day_link( $this->year, $this->monthnum, $this->day );
6161
}
6262
}

includes/MslsOptionsQueryPostType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function has_value( string $language ): bool {
4343
*
4444
* @return string
4545
*/
46-
public function get_current_link() {
46+
public function get_current_link(): string {
4747
return (string) get_post_type_archive_link( $this->post_type );
4848
}
4949
}

includes/MslsOptionsTax.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function get_postlink( $language ) {
9393
*
9494
* @return string
9595
*/
96-
public function get_current_link() {
96+
public function get_current_link(): string {
9797
return $this->get_term_link( $this->get_arg( 0, 0 ) );
9898
}
9999

includes/MslsOutput.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function get( ?int $display, bool $filter = false, $exists = false ): arr
6868
* Returns HTML-link for an item of the output-arr
6969
*
7070
* @param string $url
71-
* @param MslsLink $link
71+
* @param LinkInterface $link
7272
* @param bool $is_current_blog
7373
*
7474
* @since 0.9.8
@@ -190,9 +190,9 @@ public function set_tags( array $arr = array() ): MslsOutput {
190190
/**
191191
* Returns true if the requirements not fulfilled
192192
*
193-
* @param MslsOptions|null $thing
194-
* @param boolean $exists
195-
* @param string $language
193+
* @param ?OptionsInterface $thing
194+
* @param boolean $exists
195+
* @param string $language
196196
*
197197
* @return boolean
198198
*/

includes/OptionsInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44

55
interface OptionsInterface {
66

7+
public function has_value( string $key ): bool;
8+
9+
public function get_current_link(): string;
10+
11+
public function get_permalink( string $language ): string;
712
}

tests/phpunit/TestMslsAdmin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,12 @@ function test_rewrite_pinko(): void {
260260
$obj = $this->MslsAdminFactory();
261261

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

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

267267
$this->expectOutputString(
268-
'<input type="text" class="regular-text" id="rewrite_pinko" name="msls[rewrite_pinko]" value="pinko" size="30" readonly="readonly"/>'
268+
'<input type="text" class="regular-text" id="rewrite_pinko" name="msls[rewrite_pinko]" value="" size="30" readonly="readonly"/>'
269269
);
270270
$obj->rewrite_pinko( 'pinko' );
271271
}

0 commit comments

Comments
 (0)