Code Duplication    Length = 52-55 lines in 2 locations

includes/tidy/Balancer.php 2 locations

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