Skip to content

Commit d2097f3

Browse files
committed
Unsafe use of new static solved
1 parent 8badd97 commit d2097f3

File tree

8 files changed

+36
-37
lines changed

8 files changed

+36
-37
lines changed

MultisiteLanguageSwitcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function msls_options(): \lloc\Msls\MslsOptions {
158158
* @return \lloc\Msls\MslsOutput
159159
*/
160160
function msls_output(): \lloc\Msls\MslsOutput {
161-
echo \lloc\Msls\MslsOutput::create();
161+
return \lloc\Msls\MslsOutput::create();
162162
}
163163

164164
/**

includes/Map/HrefLang.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66

77
/**
88
* Class HrefLang
9+
*
910
* @package lloc\Msls\Map
1011
*/
1112
class HrefLang {
1213

1314
/**
14-
* @var array
15+
* @var array<string, <array<string>>>
1516
*/
16-
protected $map = [];
17+
protected $map = array();
1718

1819
/**
1920
* @param MslsBlogCollection $blogs
2021
*/
2122
public function __construct( MslsBlogCollection $blogs ) {
22-
$map = [];
23+
$map = array();
2324
foreach ( $blogs->get_objects() as $blog ) {
2425
$map[ $blog->get_alpha2() ][] = $blog->get_language();
2526
}
@@ -65,5 +66,4 @@ public function get( string $language ): string {
6566
*/
6667
return (string) apply_filters( 'msls_head_hreflang', $language );
6768
}
68-
69-
}
69+
}

includes/MslsAdmin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* @package Msls
2626
*/
27-
class MslsAdmin extends MslsMain {
27+
final class MslsAdmin extends MslsMain {
2828

2929
public const MAX_REFERENCE_USERS = 100;
3030

@@ -34,7 +34,7 @@ class MslsAdmin extends MslsMain {
3434
public static function init(): void {
3535
$obj = MslsRegistry::get_object( __CLASS__ );
3636
if ( ! $obj ) {
37-
$obj = new static( msls_options(), msls_blog_collection() );
37+
$obj = new self( msls_options(), msls_blog_collection() );
3838

3939
MslsRegistry::set_object( __CLASS__, $obj );
4040

includes/MslsCustomColumn.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ class MslsCustomColumn extends MslsMain {
1616
public static function init(): void {
1717
$options = msls_options();
1818
$collection = msls_blog_collection();
19-
$obj = new static( $options, $collection );
2019

21-
if ( ! $options->is_excluded() ) {
22-
$post_type = MslsPostType::instance()->get_request();
20+
( new static( $options, $collection ) )->add_hooks();
21+
}
2322

24-
if ( ! empty( $post_type ) ) {
25-
add_filter( "manage_{$post_type}_posts_columns", array( $obj, 'th' ) );
26-
add_action( "manage_{$post_type}_posts_custom_column", array( $obj, 'td' ), 10, 2 );
27-
add_action( 'trashed_post', array( $obj, 'delete' ) );
28-
}
23+
protected function add_hooks(): void {
24+
if ( $this->options->is_excluded() ) {
25+
return;
26+
}
27+
28+
$post_type = MslsPostType::instance()->get_request();
29+
30+
if ( ! empty( $post_type ) ) {
31+
add_filter( "manage_{$post_type}_posts_columns", array( $this, 'th' ) );
32+
add_action( "manage_{$post_type}_posts_custom_column", array( $this, 'td' ), 10, 2 );
33+
add_action( 'trashed_post', array( $this, 'delete' ) );
2934
}
3035
}
3136

includes/MslsCustomColumnTaxonomy.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,19 @@
88
*
99
* @package Msls
1010
*/
11-
class MslsCustomColumnTaxonomy extends MslsCustomColumn {
11+
final class MslsCustomColumnTaxonomy extends MslsCustomColumn {
1212

13-
/**
14-
* @codeCoverageIgnore
15-
*/
16-
public static function init(): void {
17-
$options = msls_options();
18-
$collection = msls_blog_collection();
19-
$obj = new static( $options, $collection );
13+
protected function add_hooks(): void {
14+
if ( $this->options->is_excluded() ) {
15+
return;
16+
}
2017

21-
if ( ! $options->is_excluded() ) {
22-
$taxonomy = MslsTaxonomy::instance()->get_request();
18+
$taxonomy = MslsTaxonomy::instance()->get_request();
2319

24-
if ( ! empty( $taxonomy ) ) {
25-
add_filter( "manage_edit-{$taxonomy}_columns", array( $obj, 'th' ) );
26-
add_action( "manage_{$taxonomy}_custom_column", array( $obj, 'column_default' ), - 100, 3 );
27-
add_action( "delete_{$taxonomy}", array( $obj, 'delete' ) );
28-
}
20+
if ( ! empty( $taxonomy ) ) {
21+
add_filter( "manage_edit-{$taxonomy}_columns", array( $this, 'th' ) );
22+
add_action( "manage_{$taxonomy}_custom_column", array( $this, 'column_default' ), - 100, 3 );
23+
add_action( "delete_{$taxonomy}", array( $this, 'delete' ) );
2924
}
3025
}
3126

includes/MslsCustomFilter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
namespace lloc\Msls;
44

55
use lloc\Msls\Component\Input\Select;
6-
use lloc\Msls\Component\InputInterface;
76
use lloc\Msls\Query\TranslatedPostIdQuery;
87

98
/**
109
* Adding custom filter to posts/pages table.
1110
*
1211
* @package Msls
1312
*/
14-
class MslsCustomFilter extends MslsMain {
13+
final class MslsCustomFilter extends MslsMain {
1514

1615
/**
1716
* @codeCoverageIgnore
1817
*/
1918
public static function init(): void {
2019
$options = msls_options();
2120
$collection = msls_blog_collection();
22-
$obj = new static( $options, $collection );
21+
$obj = new self( $options, $collection );
2322

2423
if ( ! $options->is_excluded() ) {
2524
$post_type = MslsPostType::instance()->get_request();

includes/MslsMain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MslsMain {
3131
* @param MslsOptions $options
3232
* @param MslsBlogCollection $collection
3333
*/
34-
public function __construct( MslsOptions $options, MslsBlogCollection $collection ) {
34+
final public function __construct( MslsOptions $options, MslsBlogCollection $collection ) {
3535
$this->options = $options;
3636
$this->collection = $collection;
3737
}

includes/MslsMetaBox.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @package Msls
1212
*/
13-
class MslsMetaBox extends MslsMain {
13+
final class MslsMetaBox extends MslsMain {
1414

1515
/**
1616
* Suggest
@@ -94,7 +94,7 @@ public static function get_suggested_fields( MslsJson $json, array $args ): Msls
9494
*/
9595
public static function init(): void {
9696
$options = msls_options();
97-
$obj = new static( $options, msls_blog_collection() );
97+
$obj = new self( $options, msls_blog_collection() );
9898

9999
if ( ! $options->is_excluded() ) {
100100
add_action( 'add_meta_boxes', array( $obj, 'add' ) );

0 commit comments

Comments
 (0)