File tree Expand file tree Collapse file tree 2 files changed +25
-11
lines changed Expand file tree Collapse file tree 2 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -66,27 +66,26 @@ public static function get_types_description(): array {
66
66
* @return MslsLink
67
67
*/
68
68
public static function create ( ?int $ display ): MslsLink {
69
+ $ types = self ::get_types ();
70
+ if ( ! in_array ( $ display , array_keys ( $ types ), true ) ) {
71
+ $ display = 0 ;
72
+ }
73
+
74
+ $ obj = new $ types [ $ display ]();
75
+
69
76
if ( has_filter ( 'msls_link_create ' ) ) {
70
77
/**
71
- * Returns custom MslsLink-Object
72
- *
73
78
* @param int $display
74
79
*
75
80
* @return MslsLink
76
- * @since 0.9.9
77
81
*/
78
- $ obj = apply_filters ( 'msls_link_create ' , $ display );
79
- if ( is_subclass_of ( $ obj , __CLASS__ ) ) {
82
+ $ obj = apply_filters ( 'msls_link_create ' , $ obj , $ display );
83
+ if ( in_array ( __CLASS__ , $ types ) || is_subclass_of ( $ obj , __CLASS__ ) ) {
80
84
return $ obj ;
81
85
}
82
86
}
83
87
84
- $ types = self ::get_types ();
85
- if ( ! in_array ( $ display , array_keys ( $ types ), true ) ) {
86
- $ display = 0 ;
87
- }
88
-
89
- return new $ types [ $ display ]();
88
+ return $ obj ;
90
89
}
91
90
92
91
/**
Original file line number Diff line number Diff line change 3
3
namespace lloc \MslsTests ;
4
4
5
5
use Brain \Monkey \Functions ;
6
+ use Brain \Monkey \Filters ;
7
+ use Hoa \Iterator \Filter ;
6
8
use lloc \Msls \MslsLink ;
7
9
8
10
class TestMslsLink extends MslsUnitTestCase {
9
11
12
+ public function test_create (): void {
13
+ Functions \expect ( 'has_filter ' )->once ()->with ( 'msls_link_create ' )->andReturn ( true );
14
+
15
+ $ obj = new MslsLink ();
16
+ $ display = 0 ;
17
+
18
+ Filters \expectApplied ( 'msls_link_create ' )->once ()->andReturn ( $ obj );
19
+
20
+ $ obj = MslsLink::create ( $ display );
21
+
22
+ $ this ->assertInstanceOf ( MslsLink::class, $ obj );
23
+ }
24
+
10
25
public function test_get_types (): void {
11
26
$ this ->assertCount ( 4 , MslsLink::get_types () );
12
27
}
You can’t perform that action at this time.
0 commit comments