Skip to content

Commit d9563eb

Browse files
authored
Feature/phpstan upgrade (#431)
* Upgrade and issues resolved
1 parent 36f3a00 commit d9563eb

16 files changed

+53
-43
lines changed

MultisiteLanguageSwitcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ function msls_get_post( int $id ): \lloc\Msls\MslsOptionsPost {
208208
* - is_tax
209209
*
210210
* @param int $id
211-
* @return \lloc\Msls\MslsOptionsTax
211+
* @return \lloc\Msls\OptionsTaxInterface
212212
*/
213-
function msls_get_tax( int $id ): \lloc\Msls\MslsOptionsTax {
213+
function msls_get_tax( int $id ): \lloc\Msls\OptionsTaxInterface {
214214
return \lloc\Msls\MslsOptionsTax::create( $id );
215215
}
216216

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
"require-dev": {
1313
"phpunit/phpunit": "^10",
1414
"brain/monkey": "^2.6",
15-
"phpstan/phpstan": "^1.11",
16-
"szepeviktor/phpstan-wordpress": "^1.3",
15+
"phpstan/phpstan": "^2.1.0",
16+
"szepeviktor/phpstan-wordpress": "^2.0.0",
1717
"phpstan/extension-installer": "^1.3",
1818
"antecedent/patchwork": "^2.1",
1919
"squizlabs/php_codesniffer": "^3.9",
2020
"phpcompatibility/php-compatibility": "^9.3",
2121
"wp-coding-standards/wpcs": "^3.0",
2222
"smeghead/php-class-diagram": "^1.3",
23-
"phpstan/phpstan-mockery": "^1.1"
23+
"phpstan/phpstan-mockery": "^2.0.0"
2424
},
2525
"autoload": {
2626
"psr-4": {

includes/Component/Icon/IconLabel.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace lloc\Msls\Component\Icon;
44

55
use lloc\Msls\Component\Icon;
6-
use lloc\Msls\MslsPlugin;
76

87
/**
98
* Class IconLabel

includes/ContentImport/AttachmentPathFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function filter_attachment_url( $url, $attachment_id ) {
9393
protected function get_source_post( $attachment_id, $msls_imported ) {
9494
$source_post = get_blog_post( $msls_imported['blog'], $msls_imported['post'] );
9595

96-
if ( empty( $source_post ) || ! $source_post instanceof \WP_Post ) {
96+
if ( ! $source_post instanceof \WP_Post ) {
9797
delete_post_meta( $attachment_id, self::LINKED );
9898

9999
return false;

includes/ContentImport/ContentImporter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function import_content( ImportCoordinates $import_coordinates, array $po
285285
* Returning a non `null` value here will override the creation of the importers map completely
286286
* and use the one returned in the filter.
287287
*
288-
* @param null $importers
288+
* @param ?array $importers
289289
* @param ImportCoordinates $import_coordinates
290290
*/
291291
$importers = apply_filters( 'msls_content_import_importers', null, $import_coordinates );
@@ -297,7 +297,7 @@ public function import_content( ImportCoordinates $import_coordinates, array $po
297297
$this->logger = $this->logger ?: new ImportLogger( $import_coordinates );
298298
$this->relations = $this->relations ?: new Relations( $import_coordinates );
299299

300-
if ( ! empty( $importers ) && is_array( $importers ) ) {
300+
if ( ! empty( $importers ) ) {
301301
$source_post_id = $import_coordinates->source_post_id;
302302
$dest_lang = $import_coordinates->dest_lang;
303303
$dest_post_id = $import_coordinates->dest_post_id;

includes/ContentImport/ImportCoordinates.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ImportCoordinates {
2626
public $dest_post_id;
2727

2828
/**
29-
* @var \WP_Post
29+
* @var ?\WP_Post
3030
*/
3131
public $source_post;
3232

@@ -55,9 +55,11 @@ public function validate() {
5555
if ( ! get_blog_post( $this->source_blog_id, $this->source_post_id ) ) {
5656
return false;
5757
}
58+
5859
if ( ! get_blog_post( $this->dest_blog_id, $this->dest_post_id ) ) {
5960
return false;
6061
}
62+
6163
if ( ! $this->source_post instanceof \WP_Post ) {
6264
return false;
6365
}

includes/ContentImport/Importers/Map.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Map extends MslsRegistryInstance {
1616
public function make( ImportCoordinates $import_coordinates ) {
1717
$importers = array_map(
1818
function ( $factory ) use ( $import_coordinates ) {
19-
/** @var ImportersFactory $factory */
19+
/** @var ImportersBaseFactory $factory */
2020
return $factory->make( $import_coordinates );
2121
},
2222
$this->factories()

includes/MslsAdmin.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ public function get_options_page_link(): string {
8686
*/
8787
public function __call( $method, $args ) {
8888
$parts = explode( '_', $method, 2 );
89-
90-
if ( is_array( $parts ) && 'rewrite' === $parts[0] ) {
89+
if ( count( $parts ) > 0 && 'rewrite' === $parts[0] ) {
9190
$this->render_rewrite( $parts[1] );
9291
return;
9392
}

includes/MslsBlogCollection.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,8 @@ public function get_blogs_of_reference_user( MslsOptions $options ) {
134134
);
135135

136136
$blogs = get_blogs_of_user( $reference_user );
137-
138-
/**
139-
* @todo Check if this is still useful
140-
*/
141-
if ( is_array( $blogs ) ) {
142-
foreach ( $blogs as $key => $blog ) {
143-
$blogs[ $key ]->blog_id = $blog->userblog_id;
144-
}
137+
foreach ( $blogs as $key => $blog ) {
138+
$blogs[ $key ]->blog_id = $blog->userblog_id;
145139
}
146140

147141
return $blogs;

includes/MslsOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public function get_available_languages(): array {
370370
/**
371371
* The 'blog'-slug-problem :/
372372
*
373-
* @param string $url
373+
* @param mixed $url
374374
* @param MslsOptions $options
375375
*
376376
* @return string

includes/MslsOptionsTax.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MslsOptionsTax extends MslsOptions implements OptionsTaxInterface {
1616
/**
1717
* @param int $id
1818
*
19-
* @return MslsOptionsTax
19+
* @return OptionsTaxInterface
2020
*/
2121
public static function create( $id = 0 ): OptionsTaxInterface {
2222
$id = ! empty( $id ) ? (int) $id : get_queried_object_id();
@@ -33,23 +33,33 @@ public static function create( $id = 0 ): OptionsTaxInterface {
3333
switch ( $req ) {
3434
case 'category':
3535
$options = new MslsOptionsTaxTermCategory( $id );
36+
add_filter( 'msls_get_postlink', array( $options, 'check_base' ), 9, 2 );
3637
break;
3738
case 'post_tag':
3839
$options = new MslsOptionsTaxTerm( $id );
40+
add_filter( 'msls_get_postlink', array( $options, 'check_base' ), 9, 2 );
3941
break;
4042
default:
41-
$options = new MslsOptionsTax( $id );
43+
global $wp_rewrite;
44+
45+
$options = new MslsOptionsTax( $id );
46+
$options->with_front = ! empty( $wp_rewrite->extra_permastructs[ $options->get_tax_query() ]['with_front'] );
4247
}
4348

44-
if ( method_exists( $options, 'check_base' ) ) {
45-
add_filter( 'msls_get_postlink', array( $options, 'check_base' ), 9, 2 );
46-
} else {
47-
global $wp_rewrite;
49+
return $options;
50+
}
4851

49-
$options->with_front = ! empty( $wp_rewrite->extra_permastructs[ $options->get_tax_query() ]['with_front'] );
52+
/**
53+
* @param int $id
54+
*
55+
* @return string
56+
*/
57+
public function get_content_type( int $id ): string {
58+
if ( is_admin() ) {
59+
return msls_content_types()->acl_request();
5060
}
5161

52-
return $options;
62+
return ( is_category() ? 'category' : is_tag( $id ) ) ? 'post_tag' : '';
5363
}
5464

5565
/**

includes/MslsOptionsTaxTerm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MslsOptionsTaxTerm extends MslsOptionsTax implements OptionsTaxInterface {
2323
/**
2424
* Check and correct URL
2525
*
26-
* @param string $url
26+
* @param mixed $url
2727
* @param MslsOptionsTaxTerm $options
2828
*
2929
* @return string

includes/MslsPostTagClassic.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo
108108
/**
109109
* Prints options inputs
110110
*
111-
* @param MslsBlog $blog
112-
* @param string $type
113-
* @param MslsOptionsTax $mydata
114-
* @param string $item_format
111+
* @param MslsBlog $blog
112+
* @param string $type
113+
* @param OptionsTaxInterface $mydata
114+
* @param string $item_format
115115
*/
116-
public function print_option( MslsBlog $blog, string $type, MslsOptionsTax $mydata, string $item_format ): void {
116+
public function print_option( MslsBlog $blog, string $type, OptionsTaxInterface $mydata, string $item_format ): void {
117117
switch_to_blog( $blog->userblog_id );
118118

119119
$language = $blog->get_language();

includes/MslsRequest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,34 @@ public static function get_config( string $name ): array {
1717
return $config;
1818
}
1919

20-
public static function has_var( string $name, ?int $input_type = null ): bool {
20+
public static function has_var( string $var_name, ?int $input_type = null ): bool {
2121
if ( null === $input_type ) {
2222
try {
23-
list( $input_type, ) = self::get_config( $name );
23+
list( $input_type, ) = self::get_config( $var_name );
2424
} catch ( \InvalidArgumentException $e ) {
2525
return false;
2626
}
2727
}
2828

29-
return filter_has_var( $input_type, $name );
29+
return filter_has_var( $input_type, $var_name );
3030
}
3131

3232
/**
3333
* @return mixed
3434
*/
35-
public static function get_var( string $name, ?int $input_type = null ) {
35+
public static function get_var( string $var_name, ?int $input_type = null ) {
3636
try {
37-
list($type, $filter) = self::get_config( $name );
37+
list($type, $filter) = self::get_config( $var_name );
3838
} catch ( \InvalidArgumentException $e ) {
3939
return null;
4040
}
4141

42-
return filter_input( $input_type ?? $type, $name, $filter );
42+
$type = $input_type ?? $type;
43+
if ( in_array( $type, array( INPUT_POST, INPUT_GET, INPUT_COOKIE, INPUT_ENV, INPUT_SERVER ), true ) ) {
44+
return filter_input( $type, $var_name, $filter );
45+
}
46+
47+
return null;
4348
}
4449

4550
/**

includes/MslsSqlCacher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @example https://gist.githubusercontent.com/lloc/2c232cef3f910acf692f/raw/91e5fe9ada922a82a32b83eaabad1e2a2ee50338/MslsSqlCacher.php
99
*
1010
* @method mixed get_var( string $sql )
11-
* @method array get_results( string $sql )
11+
* @method mixed[] get_results( string $sql )
1212
* @method string prepare( string $sql, mixed $a, $b = '', $c = '' )
1313
* @method mixed query( string $sql )
1414
* @property string $posts

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
parameters:
22
level: 6
33
inferPrivatePropertyTypeFromConstructor: true
4+
treatPhpDocTypesAsCertain: false
45
paths:
56
- MultisiteLanguageSwitcher.php
67
- includes

0 commit comments

Comments
 (0)