<commit_before><?php

namespace TwinDigital\WPTools;

/**
 * Class Filter
 */
class Filter {

  /**
   * Remove active filter from $wp_filter
   * @param string $hook   Hook on which the original filter was applied.
   * @param string $class  Classname.
   * @param string $method Method.
   *
   * @todo Create tests.
   *
   * @SuppressWarnings(PHPMD.Superglobals) Don't worry, I know what I'm doing.
   * @return void
   */
  public static function remove(string $hook, string $class, string $method) {
    $filters = [];
    if (array_key_exists($hook, $GLOBALS['wp_filter']) === true) {
      $filters = $GLOBALS['wp_filter'][$hook];
    }
    if (empty($filters) === true) {
      return;
    }

    foreach ($filters as $priority => $filter) {
      foreach ($filter as $function) {
        if (is_array($function) === true
            && is_a($function['function'][0], $class) === true
            && $method === $function['function'][1]
        ) {
          remove_filter(
            $hook,
            [
              $function['function'][0],
              $method,
            ],
            $priority
          );
        }
      }
    }
  }
}<commit_msg>Simplify and add boolean return<commit_after><?php

namespace TwinDigital\WPTools;

/**
 * Class Filter
 */
class Filter {

  /**
   * Remove active filter from $wp_filter
   *
   * @param string $hook   Hook on which the original filter was applied.
   * @param string $class  Classname.
   * @param string $method Method.
   *
   * @SuppressWarnings(PHPMD.Superglobals) Don't worry, I know what I'm doing.
   * @return boolean
   */
  public static function remove(string $hook, string $class, string $method): bool {
    if (array_key_exists($hook, $GLOBALS['wp_filter']) === true) {
      $filters = $GLOBALS['wp_filter'][$hook];
    } else {
      return false;
    }
    $return = false;
    foreach ($filters as $priority => $filter) {
      foreach ($filter as $function) {
        if (is_array($function) === true
            && is_a($function['function'][0], $class) === true
            && $method === $function['function'][1]
        ) {
          $return = remove_filter(
            $hook,
            [
              $function['function'][0],
              $method,
            ],
            $priority
          );
        }
      }
    }

    return $return;
  }
}
{'fraction_non_alphanumeric': 0.14547001276052743, 'fraction_numerical': 0.002552105487026797, 'mean_word_length': 2.094736842105263, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1513611', 'n_tokens_mistral': 702, 'n_tokens_neox': 698, 'n_words': 177}