You are here

class KeywordPatch in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Doubler/ClassPatch/KeywordPatch.php \Prophecy\Doubler\ClassPatch\KeywordPatch

Remove method functionality from the double which will clash with php keywords.

@author Milan Magudia <milan@magudia.com>

Hierarchy

Expanded class hierarchy of KeywordPatch

File

vendor/phpspec/prophecy/src/Prophecy/Doubler/ClassPatch/KeywordPatch.php, line 21

Namespace

Prophecy\Doubler\ClassPatch
View source
class KeywordPatch implements ClassPatchInterface {

  /**
   * Support any class
   *
   * @param ClassNode $node
   *
   * @return boolean
   */
  public function supports(ClassNode $node) {
    return true;
  }

  /**
   * Remove methods that clash with php keywords
   *
   * @param ClassNode $node
   */
  public function apply(ClassNode $node) {
    $methodNames = array_keys($node
      ->getMethods());
    $methodsToRemove = array_intersect($methodNames, $this
      ->getKeywords());
    foreach ($methodsToRemove as $methodName) {
      $node
        ->removeMethod($methodName);
    }
  }

  /**
   * Returns patch priority, which determines when patch will be applied.
   *
   * @return int Priority number (higher - earlier)
   */
  public function getPriority() {
    return 49;
  }

  /**
   * Returns array of php keywords.
   *
   * @return array
   */
  private function getKeywords() {
    return array(
      '__halt_compiler',
      'abstract',
      'and',
      'array',
      'as',
      'break',
      'callable',
      'case',
      'catch',
      'class',
      'clone',
      'const',
      'continue',
      'declare',
      'default',
      'die',
      'do',
      'echo',
      'else',
      'elseif',
      'empty',
      'enddeclare',
      'endfor',
      'endforeach',
      'endif',
      'endswitch',
      'endwhile',
      'eval',
      'exit',
      'extends',
      'final',
      'finally',
      'for',
      'foreach',
      'function',
      'global',
      'goto',
      'if',
      'implements',
      'include',
      'include_once',
      'instanceof',
      'insteadof',
      'interface',
      'isset',
      'list',
      'namespace',
      'new',
      'or',
      'print',
      'private',
      'protected',
      'public',
      'require',
      'require_once',
      'return',
      'static',
      'switch',
      'throw',
      'trait',
      'try',
      'unset',
      'use',
      'var',
      'while',
      'xor',
      'yield',
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeywordPatch::apply public function Remove methods that clash with php keywords Overrides ClassPatchInterface::apply
KeywordPatch::getKeywords private function Returns array of php keywords.
KeywordPatch::getPriority public function Returns patch priority, which determines when patch will be applied. Overrides ClassPatchInterface::getPriority
KeywordPatch::supports public function Support any class Overrides ClassPatchInterface::supports