@@ -18,4 +18,102 @@ public function testList(array $b): void
1818 }
1919 assertType ('list{0: string, 1: string, 2?: string, 3?: string} ' , $ b );
2020 }
21+
22+ /**
23+ * @param list{0: string, 1: string, 2?: string, 3?: string} $b
24+ */
25+ public function testUnset0 (array $ b ): void
26+ {
27+ assertType ('true ' , array_is_list ($ b ));
28+ unset($ b [0 ]);
29+ assertType ('false ' , array_is_list ($ b ));
30+ $ b [] = 'foo ' ;
31+ assertType ('false ' , array_is_list ($ b ));
32+ }
33+
34+ /**
35+ * @param list{0: string, 1: string, 2?: string, 3?: string} $b
36+ */
37+ public function testUnset1 (array $ b ): void
38+ {
39+ assertType ('true ' , array_is_list ($ b ));
40+ unset($ b [1 ]);
41+ assertType ('bool ' , array_is_list ($ b ));
42+ $ b [] = 'foo ' ;
43+ assertType ('false ' , array_is_list ($ b ));
44+ }
45+
46+ /**
47+ * @param list{0: string, 1: string, 2?: string, 3?: string} $b
48+ */
49+ public function testUnset2 (array $ b ): void
50+ {
51+ assertType ('true ' , array_is_list ($ b ));
52+ unset($ b [2 ]);
53+ assertType ('bool ' , array_is_list ($ b ));
54+ $ b [] = 'foo ' ;
55+ assertType ('false ' , array_is_list ($ b ));
56+ }
57+
58+ /**
59+ * @param list{0: string, 1: string, 2?: string, 3?: string} $b
60+ */
61+ public function testUnset3 (array $ b ): void
62+ {
63+ assertType ('true ' , array_is_list ($ b ));
64+ unset($ b [3 ]);
65+ assertType ('true ' , array_is_list ($ b ));
66+ $ b [] = 'foo ' ;
67+ assertType ('false ' , array_is_list ($ b ));
68+ }
69+
70+ public function placeholderToEditor (string $ html ): void
71+ {
72+ $ result = preg_replace_callback (
73+ '~\[image \\sid="( \\d+)"(?: \\shref="([^"]*)")?(?: \\sclass="([^"]*)")?\]~ ' ,
74+ function (array $ matches ): string {
75+ $ id = (int ) $ matches [1 ];
76+
77+ assertType ('list{0: non-falsy-string, 1: numeric-string, 2?: string, 3?: string} ' , $ matches );
78+
79+ $ replacement = sprintf (
80+ '<img src="%s"%s/> ' ,
81+ $ id ,
82+ array_key_exists (3 , $ matches ) ? sprintf (' class="%s" ' , $ matches [3 ]) : '' ,
83+ );
84+
85+ assertType ('list{0: non-falsy-string, 1: numeric-string, 2?: string, 3?: string} ' , $ matches );
86+
87+ return array_key_exists (2 , $ matches ) && $ matches [2 ] !== ''
88+ ? sprintf ('<a href="%s">%s</a> ' , $ matches [2 ], $ replacement )
89+ : $ replacement ;
90+ },
91+ $ html ,
92+ );
93+ }
94+
95+ public function placeholderToEditor2 (string $ html ): void
96+ {
97+ $ result = preg_replace_callback (
98+ '~\[image \\sid="( \\d+)?"(?: \\shref="([^"]*)")?(?: \\sclass="([^"]*)")?\]~ ' ,
99+ function (array $ matches ): string {
100+ $ id = (int ) $ matches [0 ];
101+
102+ assertType ('list{0: non-falsy-string, 1?: \'\'|numeric-string, 2?: string, 3?: string} ' , $ matches );
103+
104+ $ replacement = sprintf (
105+ '<img src="%s"%s/> ' ,
106+ $ id ,
107+ array_key_exists (2 , $ matches ) ? sprintf (' class="%s" ' , $ matches [2 ]) : '' ,
108+ );
109+
110+ assertType ('list{0: non-falsy-string, 1?: \'\'|numeric-string, 2?: string, 3?: string} ' , $ matches );
111+
112+ return array_key_exists (1 , $ matches ) && $ matches [1 ] !== ''
113+ ? sprintf ('<a href="%s">%s</a> ' , $ matches [1 ], $ replacement )
114+ : $ replacement ;
115+ },
116+ $ html ,
117+ );
118+ }
21119}
0 commit comments