Code Duplication    Length = 36-36 lines in 2 locations

projects/plugins/jetpack/_inc/lib/class.jetpack-password-checker.php 1 location

@@ 176-211 (lines=36) @@
173
	 * @param Boolean $required_only whether to run only required tests.
174
	 * @return array test results.
175
	 */
176
	protected function run_tests( $tests, $required_only = false ) {
177
178
		$results = array(
179
			'passed' => array(),
180
			'failed' => array(),
181
		);
182
183
		foreach ( $tests as $test_type => $section_tests ) {
184
			foreach ( $section_tests as $test_name => $test_data ) {
185
186
				// Skip non-required tests if required_only param is set.
187
				if ( $required_only && ! $test_data['required'] ) {
188
					continue;
189
				}
190
191
				$test_function = 'test_' . $test_type;
192
193
				$result = call_user_func( array( $this, $test_function ), $test_data );
194
195
				if ( $result ) {
196
					$results['passed'][] = array( 'test_name' => $test_name );
197
				} else {
198
					$results['failed'][] = array(
199
						'test_name'   => $test_name,
200
						'explanation' => $test_data['error'],
201
					);
202
203
					if ( isset( $test_data['fail_immediately'] ) ) {
204
						return $results;
205
					}
206
				}
207
			}
208
		}
209
210
		return $results;
211
	}
212
213
	/**
214
	 * Returns a list of tests that need to be run on password strings.

projects/packages/password-checker/src/class-password-checker.php 1 location

@@ 184-219 (lines=36) @@
181
	 * @param Boolean $required_only whether to run only required tests.
182
	 * @return array test results.
183
	 */
184
	protected function run_tests( $tests, $required_only = false ) {
185
186
		$results = array(
187
			'passed' => array(),
188
			'failed' => array(),
189
		);
190
191
		foreach ( $tests as $test_type => $section_tests ) {
192
			foreach ( $section_tests as $test_name => $test_data ) {
193
194
				// Skip non-required tests if required_only param is set.
195
				if ( $required_only && ! $test_data['required'] ) {
196
					continue;
197
				}
198
199
				$test_function = 'test_' . $test_type;
200
201
				$result = call_user_func( array( $this, $test_function ), $test_data );
202
203
				if ( $result ) {
204
					$results['passed'][] = array( 'test_name' => $test_name );
205
				} else {
206
					$results['failed'][] = array(
207
						'test_name'   => $test_name,
208
						'explanation' => $test_data['error'],
209
					);
210
211
					if ( isset( $test_data['fail_immediately'] ) ) {
212
						return $results;
213
					}
214
				}
215
			}
216
		}
217
218
		return $results;
219
	}
220
221
	/**
222
	 * Returns a list of tests that need to be run on password strings.