2020-04-09 14:32:40 +00:00
|
|
|
<?php
|
2020-04-16 13:03:15 +00:00
|
|
|
/**
|
|
|
|
* BypassFinalsHack class file.
|
|
|
|
*
|
|
|
|
* @package WooCommerce/Testing
|
|
|
|
*/
|
|
|
|
|
|
|
|
// phpcs:disable Squiz.Commenting.FunctionComment.Missing
|
2020-04-09 14:32:40 +00:00
|
|
|
|
2020-04-13 07:32:19 +00:00
|
|
|
namespace Automattic\WooCommerce\Testing\CodeHacking\Hacks;
|
2020-04-09 14:32:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Code hack to bypass finals.
|
|
|
|
*
|
|
|
|
* Removes all the "final" keywords from class definitions.
|
|
|
|
*/
|
|
|
|
final class BypassFinalsHack extends CodeHack {
|
|
|
|
|
|
|
|
public function hack( $code, $path ) {
|
|
|
|
if ( stripos( $code, 'final' ) !== false ) {
|
|
|
|
$tokens = $this->tokenize( $code );
|
|
|
|
$code = '';
|
|
|
|
foreach ( $tokens as $token ) {
|
|
|
|
$code .= $this->is_token_of_type( $token, T_FINAL ) ? '' : $this->token_to_string( $token );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $code;
|
|
|
|
}
|
|
|
|
}
|
2020-04-16 13:03:15 +00:00
|
|
|
|
|
|
|
// phpcs:enable Squiz.Commenting.FunctionComment.Missing
|