2020-04-09 14:32:40 +00:00
|
|
|
<?php
|
2020-04-16 13:03:15 +00:00
|
|
|
/**
|
|
|
|
* BypassFinalsHack class file.
|
|
|
|
*
|
2020-08-05 16:36:24 +00:00
|
|
|
* @package WooCommerce\Testing
|
2020-04-16 13:03:15 +00:00
|
|
|
*/
|
|
|
|
|
2020-05-18 09:31:59 +00:00
|
|
|
namespace Automattic\WooCommerce\Testing\Tools\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 {
|
|
|
|
|
2020-06-02 08:08:24 +00:00
|
|
|
/**
|
|
|
|
* Hacks code by removing "final" keywords from class definitions.
|
|
|
|
*
|
|
|
|
* @param string $code The code to hack.
|
|
|
|
* @param string $path The path of the file containing the code to hack.
|
|
|
|
* @return string The hacked code.
|
|
|
|
*/
|
2020-04-09 14:32:40 +00:00
|
|
|
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-06-02 08:08:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Revert the hack to its initial state - nothing to do since finals can't be reverted.
|
|
|
|
*/
|
|
|
|
public function reset() {
|
|
|
|
}
|
2020-04-09 14:32:40 +00:00
|
|
|
}
|
2020-04-16 13:03:15 +00:00
|
|
|
|