Skip to content

Commit 6972d40

Browse files
committed
phpstan issues
1 parent 7462d63 commit 6972d40

17 files changed

Lines changed: 199 additions & 239 deletions

.distignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
/src
2222
/tests
2323
AGENTS.md
24+
CLAUDE.md
2425
Changelog.md
2526
Diagrams.md
2627
README.md

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
.phpunit.cache
55
.phpunit.result.cache
66
.vscode/
7-
composer.lock
8-
composer.phar
7+
CLAUDE.md
98
assets/js/msls-widget-block/
109
assets/js/msls.js
10+
composer.lock
11+
composer.phar
1112
multisite-language-switcher.zip
1213
multisite-language-switcher/
1314
node_modules/
1415
out/
1516
phpunit.xml.bak
16-
tests/coverage/
1717
tests/coverage.xml
18+
tests/coverage/
1819
tests/playwright-report/
1920
tests/playwright-results/
2021
tests/playwright/.env.local

.phpstan.neon.dist

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
parameters:
2-
level: 6
2+
level: 8
33
paths:
44
- MultisiteLanguageSwitcher.php
55
- includes
66
bootstrapFiles:
77
- tests/phpstan/bootstrap.php
8-
ignoreErrors:
9-
- '/^Class lloc\\Msls\\MslsWidget extends generic class WP_Widget but does not specify its types: T$/'

.wp-env.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{
2-
"phpVersion": "8.3",
3-
"multisite": true,
4-
"plugins": [
5-
"."
6-
],
72
"env": {
83
"tests": {
94
"config": {
@@ -19,5 +14,10 @@
1914
},
2015
"mappings": {
2116
"wp-content/plugins/multisite-language-switcher": "."
22-
}
17+
},
18+
"multisite": true,
19+
"phpVersion": "8.3",
20+
"plugins": [
21+
"."
22+
]
2323
}

MultisiteLanguageSwitcher.php

Lines changed: 1 addition & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -49,201 +49,9 @@
4949
define( 'MSLS_PLUGIN_PATH', plugin_basename( __FILE__ ) );
5050
define( 'MSLS_PLUGIN__FILE__', __FILE__ );
5151

52+
require_once __DIR__ . '/includes/functions.php';
5253
require_once __DIR__ . '/includes/deprectated.php';
5354

54-
/**
55-
* Get the output for using the links to the translations in your code
56-
*
57-
* @package Msls
58-
* @param mixed $attr
59-
* @return string
60-
*/
61-
function msls_get_switcher( $attr ): string {
62-
$arr = is_array( $attr ) ? $attr : array();
63-
$obj = apply_filters( 'msls_get_output', null );
64-
65-
return ! is_null( $obj ) ? strval( $obj->set_tags( $arr ) ) : '';
66-
}
67-
68-
/**
69-
* Output the links to the translations in your template
70-
*
71-
* You can call this function directly like that
72-
*
73-
* if ( function_exists ( 'the_msls' ) )
74-
* the_msls();
75-
*
76-
* or just use it as shortcode [sc_msls]
77-
*
78-
* @package Msls
79-
* @uses get_the_msls
80-
*
81-
* @param string[] $arr
82-
*/
83-
function msls_the_switcher( array $arr = array() ): void {
84-
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
85-
echo msls_get_switcher( $arr );
86-
}
87-
88-
/**
89-
* Gets the URL of the country flag-icon for a specific locale
90-
*
91-
* @param string $locale
92-
*
93-
* @return string
94-
*/
95-
function msls_get_flag_url( string $locale ): string {
96-
return ( new \lloc\Msls\MslsOptions() )->get_flag_url( $locale );
97-
}
98-
99-
/**
100-
* Gets the description for a blog for a specific locale
101-
*
102-
* @param string $locale
103-
* @param string $preset
104-
*
105-
* @return string
106-
*/
107-
function msls_get_blog_description( string $locale, string $preset = '' ): string {
108-
$blog = msls_blog( $locale );
109-
110-
return $blog ? $blog->get_description() : $preset;
111-
}
112-
113-
/**
114-
* Gets the permalink for a translation of the current post in a given language
115-
*
116-
* @param string $locale
117-
* @param string $preset
118-
*
119-
* @return string
120-
*/
121-
function msls_get_permalink( string $locale, string $preset = '' ): string {
122-
$url = null;
123-
$blog = msls_blog( $locale );
124-
125-
if ( $blog ) {
126-
$options = \lloc\Msls\MslsOptions::create();
127-
$url = $blog->get_url( $options );
128-
}
129-
130-
return $url ?? $preset;
131-
}
132-
133-
/**
134-
* Looks for the MslsBlog instance for a specific locale
135-
*
136-
* @param string $locale
137-
*
138-
* @return \lloc\Msls\MslsBlog|null
139-
*/
140-
function msls_blog( string $locale ): ?\lloc\Msls\MslsBlog {
141-
return msls_blog_collection()->get_blog( $locale );
142-
}
143-
144-
/**
145-
* Gets the MslsBlogCollection instance
146-
*
147-
* @return \lloc\Msls\MslsBlogCollection
148-
*/
149-
function msls_blog_collection(): \lloc\Msls\MslsBlogCollection {
150-
return \lloc\Msls\MslsBlogCollection::instance();
151-
}
152-
153-
/**
154-
* Gets the MslsOptions instance
155-
*
156-
* @return \lloc\Msls\MslsOptions
157-
*/
158-
function msls_options(): \lloc\Msls\MslsOptions {
159-
return \lloc\Msls\MslsOptions::instance();
160-
}
161-
162-
/**
163-
* Gets the MslsContentTypes instance
164-
*
165-
* @return \lloc\Msls\MslsContentTypes
166-
*/
167-
function msls_content_types(): \lloc\Msls\MslsContentTypes {
168-
return \lloc\Msls\MslsContentTypes::create();
169-
}
170-
171-
/**
172-
* Gets the MslsPostType instance
173-
*
174-
* @return \lloc\Msls\MslsPostType
175-
*/
176-
function msls_post_type(): \lloc\Msls\MslsPostType {
177-
return \lloc\Msls\MslsPostType::instance();
178-
}
179-
180-
/**
181-
* Gets the MslsTaxonomy instance
182-
*
183-
* @return \lloc\Msls\MslsTaxonomy
184-
*/
185-
function msls_taxonomy(): \lloc\Msls\MslsTaxonomy {
186-
return \lloc\Msls\MslsTaxonomy::instance();
187-
}
188-
189-
/**
190-
* Gets the MslsOutput instance
191-
*
192-
* @return \lloc\Msls\MslsOutput
193-
*/
194-
function msls_output(): \lloc\Msls\MslsOutput {
195-
return \lloc\Msls\MslsOutput::create();
196-
}
197-
198-
/**
199-
* Retrieves the MslsOptionsPost instance.
200-
*
201-
* @param int $id
202-
* @return \lloc\Msls\MslsOptionsPost
203-
*/
204-
function msls_get_post( int $id ): \lloc\Msls\MslsOptionsPost {
205-
return new \lloc\Msls\MslsOptionsPost( $id );
206-
}
207-
208-
/**
209-
* Retrieves the MslsOptionsTax instance.
210-
*
211-
* Determines the current query based on conditional tags:
212-
* - is_category
213-
* - is_tag
214-
* - is_tax
215-
*
216-
* @param int $id
217-
* @return \lloc\Msls\OptionsTaxInterface
218-
*/
219-
function msls_get_tax( int $id ): \lloc\Msls\OptionsTaxInterface {
220-
return \lloc\Msls\MslsOptionsTax::create( $id );
221-
}
222-
223-
/**
224-
* Retrieves the MslsOptionsQuery instance.
225-
*
226-
* Determines the current query based on conditional tags:
227-
* - is_day
228-
* - is_month
229-
* - is_year
230-
* - is_author
231-
* - is_post_type_archive
232-
*
233-
* @return ?\lloc\Msls\MslsOptionsQuery
234-
*/
235-
function msls_get_query(): ?\lloc\Msls\MslsOptionsQuery {
236-
return \lloc\Msls\MslsOptionsQuery::create();
237-
}
238-
239-
/**
240-
* Trivial void function for actions that do not return anything.
241-
*
242-
* @return void
243-
*/
244-
function msls_return_void(): void {
245-
}
246-
24755
lloc\Msls\MslsPlugin::init();
24856
lloc\Msls\MslsCli::init();
24957
}

includes/Component/Input/Text.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class Text extends Component {
1414
protected $key;
1515

1616
/**
17-
* @var string
17+
* @var ?string
1818
*/
1919
protected $value;
2020

@@ -48,7 +48,7 @@ public function render(): string {
4848
return sprintf(
4949
'<input type="text" class="regular-text" id="%1$s" name="msls[%1$s]" value="%2$s" size="%3$d"%4$s/>',
5050
esc_attr( $this->key ),
51-
esc_attr( $this->value ),
51+
esc_attr( (string) $this->value ),
5252
$this->size,
5353
$this->readonly // phpcs:ignore WordPress.Security.EscapeOutput
5454
);

includes/ContentImport/ContentImporter.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ContentImporter extends MslsRegistryInstance {
6060
* @param ?MslsMain $main
6161
*/
6262
public function __construct( ?MslsMain $main = null ) {
63-
$this->main = ! is_null( $main ) ? $main : MslsMain::create();
63+
$this->main = $main ?? MslsMain::create();
6464
}
6565

6666
/**
@@ -175,7 +175,7 @@ protected function pre_flight_check() {
175175
/**
176176
* Parses the source blog and post IDs from the $_POST array validating them.
177177
*
178-
* @return int[]|bool
178+
* @return array{int, int}|false
179179
*/
180180
public function parse_sources() {
181181
if ( ! MslsRequest::has_var( 'msls_import' ) ) {
@@ -202,7 +202,7 @@ protected function get_the_blog_post_ID( $blog_id ) {
202202

203203
$id = get_the_ID();
204204

205-
if ( ! empty( $id ) ) {
205+
if ( false !== $id && $id > 0 ) {
206206
restore_current_blog();
207207

208208
return $id;
@@ -225,11 +225,11 @@ protected function get_the_blog_post_ID( $blog_id ) {
225225
* @param int $blog_id
226226
* @param array<string, mixed> $data
227227
*
228-
* @return bool|int
228+
* @return int
229229
*/
230230
protected function insert_blog_post( $blog_id, array $data = array() ) {
231231
if ( empty( $data ) ) {
232-
return false;
232+
return 0;
233233
}
234234

235235
switch_to_blog( $blog_id );
@@ -242,7 +242,7 @@ protected function insert_blog_post( $blog_id, array $data = array() ) {
242242
}
243243
$this->handle( true );
244244

245-
$this->has_created_post = $post_id > 0 ? $post_id : false;
245+
$this->has_created_post = $post_id > 0 ? $post_id : 0;
246246

247247
restore_current_blog();
248248

@@ -312,12 +312,12 @@ public function import_content( ImportCoordinates $import_coordinates, array $po
312312
$importers = Map::instance()->make( $import_coordinates );
313313
}
314314

315-
if ( is_null( $this->get_logger() ) ) {
316-
$this->set_logger( new ImportLogger( $import_coordinates ) );
315+
if ( is_null( $this->logger ) ) {
316+
$this->logger = new ImportLogger( $import_coordinates );
317317
}
318318

319-
if ( is_null( $this->get_relations() ) ) {
320-
$this->set_relations( new Relations( $import_coordinates ) );
319+
if ( is_null( $this->relations ) ) {
320+
$this->relations = new Relations( $import_coordinates );
321321
}
322322

323323
if ( ! empty( $importers ) ) {
@@ -341,8 +341,8 @@ public function import_content( ImportCoordinates $import_coordinates, array $po
341341
* Fires after the import ran.
342342
*
343343
* @param ImportCoordinates $import_coordinates
344-
* @param ImportLogger $logger
345-
* @param Relations $relations
344+
* @param ?ImportLogger $logger
345+
* @param ?Relations $relations
346346
*
347347
* @since TBD
348348
*/
@@ -353,8 +353,8 @@ public function import_content( ImportCoordinates $import_coordinates, array $po
353353
*
354354
* @param array $post_fields
355355
* @param ImportCoordinates $import_coordinates
356-
* @param ImportLogger $logger
357-
* @param Relations $relations
356+
* @param ?ImportLogger $logger
357+
* @param ?Relations $relations
358358
*/
359359
return apply_filters(
360360
'msls_content_import_data_after_import',

includes/ContentImport/ImportLogger.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected function build_nested_array( $path, $what = '' ): array {
128128
);
129129
$data = json_decode( $json, true );
130130

131-
return $data;
131+
return is_array( $data ) ? $data : array();
132132
}
133133

134134
/**
@@ -137,9 +137,7 @@ protected function build_nested_array( $path, $what = '' ): array {
137137
* @return string[]
138138
*/
139139
protected function build_path( string $where ): array {
140-
$where_path = explode( $this->levels_delimiter, $where );
141-
142-
return $where_path;
140+
return explode( $this->levels_delimiter, $where );
143141
}
144142

145143
/**

0 commit comments

Comments
 (0)