Skip to content

Commit a02aaa8

Browse files
committed
PHPStan errors addressed
1 parent afa24ea commit a02aaa8

File tree

6 files changed

+34
-41
lines changed

6 files changed

+34
-41
lines changed

includes/Component/Input/Select.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
class Select implements InputInterface {
88

9+
const RENDER_FILTER = 'msls_input_select_name';
10+
911
/**
1012
* @var string
1113
*/
@@ -34,7 +36,7 @@ public function __construct( string $key, array $arr, ?string $selected = null )
3436
* @return string
3537
*/
3638
public function render(): string {
37-
$name = apply_filters( 'msls_input_select_name', 'msls[' . $this->key . ']' );
39+
$name = apply_filters( self::RENDER_FILTER, 'msls[' . $this->key . ']' );
3840

3941
return sprintf( '<select id="%1$s" name="%2$s">%3$s</select>', $this->key, esc_attr( $name ), $this->options->render() );
4042
}

includes/Component/InputInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
/**
66
* Interface Input
7+
*
78
* @package lloc\Msls\Component
89
*/
910
interface InputInterface {
1011

12+
const INPUT_PREFIX = 'msls_input_';
13+
1114
/**
1215
* @return string
1316
*/
1417
public function render(): string;
15-
16-
}
18+
}

includes/MslsCustomFilter.php

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

55
use lloc\Msls\Component\Input\Select;
6+
use lloc\Msls\Component\InputInterface;
67
use lloc\Msls\Query\TranslatedPostIdQuery;
78

89
/**
@@ -26,7 +27,7 @@ public static function init(): void {
2627
add_action( 'restrict_manage_posts', array( $obj, 'add_filter' ) );
2728
add_filter( 'parse_query', array( $obj, 'execute_filter' ) );
2829
add_filter(
29-
'msls_input_select_name',
30+
Select::RENDER_FILTER,
3031
function () {
3132
return MslsFields::FIELD_MSLS_FILTER;
3233
}

includes/MslsLanguageArray.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111
class MslsLanguageArray {
1212

1313
/**
14-
* Generic container
15-
*
16-
* @var array
14+
* @var array<string, int>
1715
*/
18-
protected $arr;
16+
protected array $arr;
1917

2018
/**
2119
* Constructor
2220
*
23-
* @param array $arr
21+
* @param array<string, mixed> $arr
2422
*/
2523
public function __construct( array $arr = array() ) {
2624
foreach ( $arr as $key => $value ) {
@@ -64,10 +62,11 @@ public function get_val( $key ) {
6462
*
6563
* @param string $key
6664
*
67-
* @return array
65+
* @return array<string, int>
6866
*/
69-
public function get_arr( $key = '' ) {
67+
public function get_arr( string $key = '' ): array {
7068
$arr = $this->arr;
69+
7170
if ( isset( $arr[ $key ] ) ) {
7271
unset( $arr[ $key ] );
7372
}

includes/MslsMain.php

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace lloc\Msls;
44

5+
use lloc\Msls\Component\InputInterface;
6+
57
/**
68
* Abstraction for the hook classes
79
*
@@ -61,9 +63,9 @@ public function debugger( $message ): void {
6163
*
6264
* @param int $object_id
6365
*
64-
* @return array
66+
* @return array<string, int>
6567
*/
66-
public function get_input_array( $object_id ) {
68+
public function get_input_array( $object_id ): array {
6769
$arr = array();
6870

6971
$current_blog = $this->collection->get_current_blog();
@@ -76,30 +78,16 @@ public function get_input_array( $object_id ) {
7678
return $arr;
7779
}
7880

79-
foreach ( $input_post as $k => $v ) {
80-
list ( $key, $value ) = $this->get_input_value( $k, $v );
81-
if ( $value ) {
82-
$arr[ $key ] = $value;
81+
$offset = strlen( InputInterface::INPUT_PREFIX );
82+
foreach ( $input_post as $key => $value ) {
83+
if ( false === strpos( $key, InputInterface::INPUT_PREFIX ) || empty( $value ) ) {
84+
continue;
8385
}
84-
}
85-
86-
return $arr;
87-
}
8886

89-
/**
90-
* Prepare input key/value-pair
91-
*
92-
* @param $key
93-
* @param $value
94-
*
95-
* @return array
96-
*/
97-
protected function get_input_value( $key, $value ) {
98-
if ( false === strpos( $key, 'msls_input_' ) || empty( $value ) ) {
99-
return array( '', 0 );
87+
$arr[ substr( $key, $offset ) ] = intval( $value );
10088
}
10189

102-
return array( substr( $key, 11 ), intval( $value ) );
90+
return $arr;
10391
}
10492

10593
/**
@@ -137,21 +125,21 @@ public function delete( $object_id ): void {
137125
* Save
138126
*
139127
* @param int $object_id
140-
* @param string $class
128+
* @param string $class_name
141129
*
142130
* @codeCoverageIgnore
143131
*/
144-
protected function save( $object_id, $class ): void {
132+
protected function save( $object_id, $class_name ): void {
145133
if ( has_action( 'msls_main_save' ) ) {
146134
/**
147135
* Calls completely customized save-routine
148136
*
149137
* @param int $object_id
150-
* @param string Classname
138+
* @param string $class_name
151139
*
152140
* @since 0.9.9
153141
*/
154-
do_action( 'msls_main_save', $object_id, $class );
142+
do_action( 'msls_main_save', $object_id, $class_name );
155143

156144
return;
157145
}
@@ -164,7 +152,7 @@ protected function save( $object_id, $class ): void {
164152

165153
$language = $this->collection->get_current_blog()->get_language();
166154
$msla = new MslsLanguageArray( $this->get_input_array( $object_id ) );
167-
$options = new $class( $object_id );
155+
$options = new $class_name( $object_id );
168156
$temp = $options->get_arr();
169157

170158
if ( 0 != $msla->get_val( $language ) ) {
@@ -180,10 +168,10 @@ protected function save( $object_id, $class ): void {
180168
$larr_id = $msla->get_val( $language );
181169

182170
if ( 0 != $larr_id ) {
183-
$options = new $class( $larr_id );
171+
$options = new $class_name( $larr_id );
184172
$options->save( $msla->get_arr( $language ) );
185173
} elseif ( isset( $temp[ $language ] ) ) {
186-
$options = new $class( $temp[ $language ] );
174+
$options = new $class_name( $temp[ $language ] );
187175
$options->delete();
188176
}
189177

includes/MslsMetaBox.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace lloc\Msls;
44

5+
use lloc\Msls\Component\InputInterface;
56
use lloc\Msls\ContentImport\MetaBox as ContentImportMetaBox;
67

78
/**
@@ -186,7 +187,7 @@ public function render_select(): void {
186187
$args = array(
187188
'post_type' => $type,
188189
'selected' => $mydata->$language,
189-
'name' => 'msls_input_' . $language,
190+
'name' => InputInterface::INPUT_PREFIX . $language,
190191
'show_option_none' => ' ',
191192
'option_none_value' => 0,
192193
'sort_column' => 'menu_order, post_title',

0 commit comments

Comments
 (0)