mock_class = $mock_class; $rc = new ReflectionClass( $mock_class ); $static_methods = $rc->getMethods( ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_STATIC ); $this->mocked_methods = array_map( function( $item ) { return $item->getName(); }, $static_methods ); } public function hack( $code, $path ) { $tokens = $this->tokenize( $code ); $code = ''; $previous_token_is_non_global_function_qualifier = false; foreach ( $tokens as $token ) { $token_type = $this->token_type_of( $token ); if ( T_WHITESPACE === $token_type ) { $code .= $this->token_to_string( $token ); } elseif ( T_STRING === $token_type && ! $previous_token_is_non_global_function_qualifier && in_array( $token[1], $this->mocked_methods, true ) ) { $code .= "{$this->mock_class}::{$token[1]}"; } else { $code .= $this->token_to_string( $token ); $previous_token_is_non_global_function_qualifier = in_array( $token_type, self::$non_global_function_tokens, true ); } } return $code; } } // phpcs:enable Squiz.Commenting.FunctionComment.Missing