You are here

class MethodNode in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/Node/MethodNode.php \Prophecy\Doubler\Generator\Node\MethodNode

Method node.

@author Konstantin Kudryashov <ever.zet@gmail.com>

Hierarchy

  • class \Prophecy\Doubler\Generator\Node\MethodNode

Expanded class hierarchy of MethodNode

7 files declare their use of MethodNode
DisableConstructorPatch.php in vendor/phpspec/prophecy/src/Prophecy/Doubler/ClassPatch/DisableConstructorPatch.php
KeywordPatchSpec.php in vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/KeywordPatchSpec.php
MagicCallPatch.php in vendor/phpspec/prophecy/src/Prophecy/Doubler/ClassPatch/MagicCallPatch.php
MagicCallPatchSpec.php in vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/MagicCallPatchSpec.php
ProphecySubjectPatch.php in vendor/phpspec/prophecy/src/Prophecy/Doubler/ClassPatch/ProphecySubjectPatch.php

... See full list

File

vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/Node/MethodNode.php, line 21

Namespace

Prophecy\Doubler\Generator\Node
View source
class MethodNode {
  private $name;
  private $code;
  private $visibility = 'public';
  private $static = false;
  private $returnsReference = false;
  private $returnType;

  /**
   * @var ArgumentNode[]
   */
  private $arguments = array();

  /**
   * @param string $name
   * @param string $code
   */
  public function __construct($name, $code = null) {
    $this->name = $name;
    $this->code = $code;
  }
  public function getVisibility() {
    return $this->visibility;
  }

  /**
   * @param string $visibility
   */
  public function setVisibility($visibility) {
    $visibility = strtolower($visibility);
    if (!in_array($visibility, array(
      'public',
      'private',
      'protected',
    ))) {
      throw new InvalidArgumentException(sprintf('`%s` method visibility is not supported.', $visibility));
    }
    $this->visibility = $visibility;
  }
  public function isStatic() {
    return $this->static;
  }
  public function setStatic($static = true) {
    $this->static = (bool) $static;
  }
  public function returnsReference() {
    return $this->returnsReference;
  }
  public function setReturnsReference() {
    $this->returnsReference = true;
  }
  public function getName() {
    return $this->name;
  }
  public function addArgument(ArgumentNode $argument) {
    $this->arguments[] = $argument;
  }

  /**
   * @return ArgumentNode[]
   */
  public function getArguments() {
    return $this->arguments;
  }
  public function hasReturnType() {
    return null !== $this->returnType;
  }

  /**
   * @param string $type
   */
  public function setReturnType($type = null) {
    switch ($type) {
      case '':
        $this->returnType = null;
        break;
      case 'string':
      case 'float':
      case 'int':
      case 'bool':
      case 'array':
      case 'callable':
        $this->returnType = $type;
        break;
      case 'double':
      case 'real':
        $this->returnType = 'float';
        break;
      case 'boolean':
        $this->returnType = 'bool';
        break;
      case 'integer':
        $this->returnType = 'int';
        break;
      default:
        $this->returnType = '\\' . ltrim($type, '\\');
    }
  }
  public function getReturnType() {
    return $this->returnType;
  }

  /**
   * @param string $code
   */
  public function setCode($code) {
    $this->code = $code;
  }
  public function getCode() {
    if ($this->returnsReference) {
      return "throw new \\Prophecy\\Exception\\Doubler\\ReturnByReferenceException('Returning by reference not supported', get_class(\$this), '{$this->name}');";
    }
    return (string) $this->code;
  }
  public function useParentCode() {
    $this->code = sprintf('return parent::%s(%s);', $this
      ->getName(), implode(', ', array_map(function (ArgumentNode $arg) {
      return '$' . $arg
        ->getName();
    }, $this->arguments)));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MethodNode::$arguments private property
MethodNode::$code private property
MethodNode::$name private property
MethodNode::$returnsReference private property
MethodNode::$returnType private property
MethodNode::$static private property
MethodNode::$visibility private property
MethodNode::addArgument public function
MethodNode::getArguments public function
MethodNode::getCode public function
MethodNode::getName public function
MethodNode::getReturnType public function
MethodNode::getVisibility public function
MethodNode::hasReturnType public function
MethodNode::isStatic public function
MethodNode::returnsReference public function
MethodNode::setCode public function
MethodNode::setReturnsReference public function
MethodNode::setReturnType public function
MethodNode::setStatic public function
MethodNode::setVisibility public function
MethodNode::useParentCode public function
MethodNode::__construct public function