Skip to content

Commit 2d75d82

Browse files
committed
get_args reviewed
1 parent ca46e4a commit 2d75d82

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

includes/MslsOptions.php

+35-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* MslsOptions
4+
*
45
* @author Dennis Ploetner <[email protected]>
56
* @since 0.9.8
67
*/
@@ -11,6 +12,7 @@
1112

1213
/**
1314
* General options class
15+
*
1416
* @package Msls
1517
* @property bool $activate_autocomplete
1618
* @property bool output_current_blog
@@ -29,42 +31,49 @@ class MslsOptions extends MslsGetSet {
2931

3032
/**
3133
* Args
34+
*
3235
* @var array
3336
*/
3437
protected $args;
3538

3639
/**
3740
* Name
41+
*
3842
* @var string
3943
*/
4044
protected $name;
4145

4246
/**
4347
* Exists
48+
*
4449
* @var bool
4550
*/
4651
protected $exists = false;
4752

4853
/**
4954
* Separator
55+
*
5056
* @var string
5157
*/
5258
protected $sep = '';
5359

5460
/**
5561
* Autoload
62+
*
5663
* @var string
5764
*/
5865
protected $autoload = 'yes';
5966

6067
/**
6168
* Available languages
69+
*
6270
* @var array
6371
*/
6472
private $available_languages;
6573

6674
/**
6775
* Rewrite with front
76+
*
6877
* @var bool
6978
*/
7079
public $with_front;
@@ -99,23 +108,23 @@ public static function create( $id = 0 ) {
99108
$options = new MslsOptionsPost( get_queried_object_id() );
100109
}
101110

102-
add_filter( 'check_url', [ $options, 'check_for_blog_slug' ], 10, 2 );
111+
add_filter( 'check_url', array( $options, 'check_for_blog_slug' ), 10, 2 );
103112

104113
return $options;
105114
}
106115

107116
/**
108117
* Determines if the current page is the main page (front page, search, 404).
109-
*
110-
* @return boolean
118+
*
119+
* @return boolean
111120
*/
112121
public static function is_main_page() {
113122
return is_front_page() || is_search() || is_404();
114123
}
115124

116125
/**
117126
* Determines if the current page is a category, tag or taxonomy page.
118-
*
127+
*
119128
* @return boolean
120129
*/
121130
public static function is_tax_page() {
@@ -124,7 +133,7 @@ public static function is_tax_page() {
124133

125134
/**
126135
* Determines if the current page is an archive page for a date, author, or any other post type.
127-
*
136+
*
128137
* @return boolean
129138
*/
130139
public static function is_query_page() {
@@ -142,17 +151,18 @@ public function __construct() {
142151

143152
/**
144153
* Gets an element of arg by index
145-
*
146-
* The returned value will either be cast to the type of `$retval` or, if nothing is set at this index, it will be the value of `$retval`.
147154
*
148-
* @param int $idx
149-
* @param mixed $val
155+
* The returned value will either be cast to the type of `$default` or, if nothing is set at this index, it will be the value of `$default`.
156+
*
157+
* @param int $index
158+
* @param mixed $default
150159
*
151160
* @return mixed
152161
*/
153-
public function get_arg( $idx, $val = null ) {
154-
$arg = isset( $this->args[ $idx ] ) ? $this->args[ $idx ] : $val;
155-
settype( $arg, gettype( $val ) );
162+
public function get_arg( int $index, $default = null ) {
163+
$arg = $this->args[ $index ] ?? $default;
164+
165+
settype( $arg, gettype( $default ) );
156166

157167
return $arg;
158168
}
@@ -176,6 +186,7 @@ public function save( $arr ) {
176186

177187
/**
178188
* Delete
189+
*
179190
* @codeCoverageIgnore
180191
*/
181192
public function delete() {
@@ -200,7 +211,10 @@ public function set( $arr ) {
200211
/**
201212
* Mapping for us language code
202213
*/
203-
$map = [ 'us' => 'en_US', 'en' => 'en_US' ];
214+
$map = array(
215+
'us' => 'en_US',
216+
'en' => 'en_US',
217+
);
204218
foreach ( $map as $old => $new ) {
205219
if ( isset( $arr[ $old ] ) ) {
206220
$arr[ $new ] = $arr[ $old ];
@@ -229,7 +243,6 @@ public function get_permalink( $language ) {
229243
* @param string $language
230244
*
231245
* @since 0.9.8
232-
*
233246
*/
234247
$postlink = (string) apply_filters(
235248
'msls_options_get_permalink',
@@ -253,6 +266,7 @@ public function get_postlink( $language ) {
253266

254267
/**
255268
* Get the queried taxonomy
269+
*
256270
* @return string
257271
*/
258272
public function get_tax_query() {
@@ -261,6 +275,7 @@ public function get_tax_query() {
261275

262276
/**
263277
* Get current link
278+
*
264279
* @return string
265280
*/
266281
public function get_current_link() {
@@ -269,6 +284,7 @@ public function get_current_link() {
269284

270285
/**
271286
* Is excluded
287+
*
272288
* @return bool
273289
*/
274290
public function is_excluded() {
@@ -277,6 +293,7 @@ public function is_excluded() {
277293

278294
/**
279295
* Is content
296+
*
280297
* @return bool
281298
*/
282299
public function is_content_filter() {
@@ -285,6 +302,7 @@ public function is_content_filter() {
285302

286303
/**
287304
* Get order
305+
*
288306
* @return string
289307
*/
290308
public function get_order() {
@@ -346,7 +364,6 @@ public function get_flag_url( $language ) {
346364
* @param string $url
347365
*
348366
* @since 0.9.9
349-
*
350367
*/
351368
$url = (string) apply_filters( 'msls_options_get_flag_url', $url );
352369

@@ -359,7 +376,6 @@ public function get_flag_url( $language ) {
359376
* @param string $language
360377
*
361378
* @since 1.0.3
362-
*
363379
*/
364380
$icon = (string) apply_filters( 'msls_options_get_flag_icon', $icon, $language );
365381

@@ -375,9 +391,9 @@ public function get_flag_url( $language ) {
375391
*/
376392
public function get_available_languages() {
377393
if ( empty( $this->available_languages ) ) {
378-
$this->available_languages = [
394+
$this->available_languages = array(
379395
'en_US' => __( 'American English', 'multisite-language-switcher' ),
380-
];
396+
);
381397

382398
foreach ( get_available_languages() as $code ) {
383399
$this->available_languages[ esc_attr( $code ) ] = format_code_lang( $code );
@@ -389,7 +405,6 @@ public function get_available_languages() {
389405
* @param array $available_languages
390406
*
391407
* @since 1.0
392-
*
393408
*/
394409
$this->available_languages = (array) apply_filters(
395410
'msls_options_get_available_languages',
@@ -403,7 +418,7 @@ public function get_available_languages() {
403418
/**
404419
* The 'blog'-slug-problem :/
405420
*
406-
* @param string $url
421+
* @param string $url
407422
* @param MslsOptions $options
408423
*
409424
* @return string
@@ -443,5 +458,4 @@ public static function check_for_blog_slug( $url, $options ) {
443458
public function get_icon_type(): string {
444459
return MslsAdminIcon::TYPE_LABEL === $this->admin_display ? MslsAdminIcon::TYPE_LABEL : MslsAdminIcon::TYPE_FLAG;
445460
}
446-
447461
}

0 commit comments

Comments
 (0)