Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
66 | class AssetsTest extends TestCase { |
||
67 | use \Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; |
||
68 | |||
69 | /** |
||
70 | * Test setup. |
||
71 | * |
||
72 | * @before |
||
73 | */ |
||
74 | public function set_up() { |
||
80 | |||
81 | /** |
||
82 | * Run after every test. |
||
83 | * |
||
84 | * @after |
||
85 | */ |
||
86 | public function tear_down() { |
||
90 | |||
91 | /** |
||
92 | * Test get_file_url_for_environment |
||
93 | * |
||
94 | * @author ebinnion goldsounds |
||
95 | * @dataProvider get_file_url_for_environment_data_provider |
||
96 | * |
||
97 | * @param string $min_path minified path. |
||
98 | * @param string $non_min_path non-minified path. |
||
99 | * @param bool $is_script_debug Is SCRIPT_DEBUG enabled. |
||
100 | * @param string $expected Expected result. |
||
101 | * @param string $not_expected Non expected result. |
||
102 | */ |
||
103 | View Code Duplication | public function test_get_file_url_for_environment( $min_path, $non_min_path, $is_script_debug, $expected, $not_expected ) { |
|
111 | |||
112 | /** |
||
113 | * Test that get_file_url_for_environment returns a full URL when given a full URL |
||
114 | * |
||
115 | * @author jeherve |
||
116 | * @dataProvider get_file_url_for_environment_full_urls_data_provider |
||
117 | * |
||
118 | * @param string $url Full URL we want to enqueue. |
||
119 | */ |
||
120 | public function test_get_file_url_for_environment_full_url( $url ) { |
||
125 | |||
126 | /** |
||
127 | * Test that get_file_url_for_environment returns a full package asset url when package path is provided. |
||
128 | * |
||
129 | * @param string $min_path minified path. |
||
130 | * @param string $non_min_path non-minified path. |
||
131 | * @param string $package_path Package path. |
||
132 | * @param bool $is_script_debug Is SCRIPT_DEBUG enabled. |
||
133 | * @param string $expected Expected result. |
||
134 | * @param string $not_expected Non expected result. |
||
135 | * |
||
136 | * @author davidlonjon |
||
137 | * @dataProvider get_file_url_for_environment_package_path_data_provider |
||
138 | */ |
||
139 | View Code Duplication | public function test_get_file_url_for_environment_package_path( $min_path, $non_min_path, $package_path, $is_script_debug, $expected, $not_expected ) { |
|
146 | |||
147 | /** |
||
148 | * Tests ability for a filter to map specific URLs. |
||
149 | * |
||
150 | * @author kraftbj |
||
151 | * @see p58i-8nS-p2 |
||
152 | */ |
||
153 | public function test_get_file_url_for_environment_with_filter() { |
||
160 | |||
161 | /** |
||
162 | * Possible values for test_get_file_url_for_environment. |
||
163 | */ |
||
164 | public function get_file_url_for_environment_data_provider() { |
||
182 | |||
183 | /** |
||
184 | * Possible values for test_get_file_url_for_environment. |
||
185 | */ |
||
186 | public function get_file_url_for_environment_full_urls_data_provider() { |
||
192 | |||
193 | /** |
||
194 | * Possible values for test_get_file_url_for_environment. |
||
195 | */ |
||
196 | public function get_file_url_for_environment_package_path_data_provider() { |
||
221 | |||
222 | /** |
||
223 | * Test that enqueue_async_script calls adds the script_loader_tag filter |
||
224 | */ |
||
225 | public function test_enqueue_async_script_adds_script_loader_tag_filter() { |
||
230 | |||
231 | /** |
||
232 | * Test that enqueue_async_script calls wp_enqueue_script |
||
233 | */ |
||
234 | public function test_enqueue_async_script_calls_wp_enqueue_script() { |
||
241 | } |
||
242 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: