Code Duplication    Length = 36-36 lines in 2 locations

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

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

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.