Code Duplication    Length = 52-55 lines in 2 locations

includes/tidy/Balancer.php 2 locations

@@ 3197-3248 (lines=52) @@
3194
		$this->switchMode( 'inTableMode' );
3195
		return true;
3196
	}
3197
	private function inTableBodyMode( $token, $value, $attribs = null, $selfClose = false ) {
3198
		if ( $token === 'tag' ) {
3199
			switch ( $value ) {
3200
			case 'tr':
3201
				$this->stack->clearToContext( BalanceSets::$tableBodyContextSet );
3202
				$this->stack->insertHTMLElement( $value, $attribs );
3203
				$this->switchMode( 'inRowMode' );
3204
				return true;
3205
			case 'th':
3206
			case 'td':
3207
				$this->inTableBodyMode( 'tag', 'tr', [] );
3208
				$this->insertToken( $token, $value, $attribs, $selfClose );
3209
				return true;
3210
			case 'caption':
3211
			case 'col':
3212
			case 'colgroup':
3213
			case 'tbody':
3214
			case 'tfoot':
3215
			case 'thead':
3216
				if ( $this->endSection() ) {
3217
					$this->insertToken( $token, $value, $attribs, $selfClose );
3218
				}
3219
				return true;
3220
			}
3221
		} elseif ( $token === 'endtag' ) {
3222
			switch ( $value ) {
3223
			case 'table':
3224
				if ( $this->endSection() ) {
3225
					$this->insertToken( $token, $value, $attribs, $selfClose );
3226
				}
3227
				return true;
3228
			case 'tbody':
3229
			case 'tfoot':
3230
			case 'thead':
3231
				if ( $this->stack->inTableScope( $value ) ) {
3232
					$this->endSection();
3233
				}
3234
				return true;
3235
			// OMITTED: <body>
3236
			case 'caption':
3237
			case 'col':
3238
			case 'colgroup':
3239
			// OMITTED: <html>
3240
			case 'td':
3241
			case 'th':
3242
			case 'tr':
3243
				return true; // Ignore the token.
3244
			}
3245
		}
3246
		// Anything else:
3247
		return $this->inTableMode( $token, $value, $attribs, $selfClose );
3248
	}
3249
3250
	// Helper function for inRowMode
3251
	private function endRow() {
@@ 3260-3314 (lines=55) @@
3257
		$this->switchMode( 'inTableBodyMode' );
3258
		return true;
3259
	}
3260
	private function inRowMode( $token, $value, $attribs = null, $selfClose = false ) {
3261
		if ( $token === 'tag' ) {
3262
			switch ( $value ) {
3263
			case 'th':
3264
			case 'td':
3265
				$this->stack->clearToContext( BalanceSets::$tableRowContextSet );
3266
				$this->stack->insertHTMLElement( $value, $attribs );
3267
				$this->switchMode( 'inCellMode' );
3268
				$this->afe->insertMarker();
3269
				return true;
3270
			case 'caption':
3271
			case 'col':
3272
			case 'colgroup':
3273
			case 'tbody':
3274
			case 'tfoot':
3275
			case 'thead':
3276
			case 'tr':
3277
				if ( $this->endRow() ) {
3278
					$this->insertToken( $token, $value, $attribs, $selfClose );
3279
				}
3280
				return true;
3281
			}
3282
		} elseif ( $token === 'endtag' ) {
3283
			switch ( $value ) {
3284
			case 'tr':
3285
				$this->endRow();
3286
				return true;
3287
			case 'table':
3288
				if ( $this->endRow() ) {
3289
					$this->insertToken( $token, $value, $attribs, $selfClose );
3290
				}
3291
				return true;
3292
			case 'tbody':
3293
			case 'tfoot':
3294
			case 'thead':
3295
				if (
3296
					$this->stack->inTableScope( $value ) &&
3297
					$this->endRow()
3298
				) {
3299
					$this->insertToken( $token, $value, $attribs, $selfClose );
3300
				}
3301
				return true;
3302
			// OMITTED: <body>
3303
			case 'caption':
3304
			case 'col':
3305
			case 'colgroup':
3306
			// OMITTED: <html>
3307
			case 'td':
3308
			case 'th':
3309
				return true; // Ignore the token.
3310
			}
3311
		}
3312
		// Anything else:
3313
		return $this->inTableMode( $token, $value, $attribs, $selfClose );
3314
	}
3315
3316
	// Helper for inCellMode
3317
	private function endCell() {