public function testNoModifiers()
 {
     $node = new ClassMethod('foo', array('type' => 0));
     $this->assertTrue($node->isPublic());
     $this->assertFalse($node->isProtected());
     $this->assertFalse($node->isPrivate());
     $this->assertFalse($node->isAbstract());
     $this->assertFalse($node->isFinal());
     $this->assertFalse($node->isStatic());
 }
Esempio n. 2
0
 public function testAccessors()
 {
     $class_method = new ClassMethod('basicMethod');
     $this->assertEquals('basicMethod', $class_method->getMethod());
     $this->assertEquals([], $class_method->getArgs());
     $class_method->setMethod('methodWithArgs');
     $class_method->setArgs(['arg_1' => 'val_1']);
     $this->assertEquals('methodWithArgs', $class_method->getMethod());
     $this->assertEquals(['arg_1' => 'val_1'], $class_method->getArgs());
 }
 /**
  * Checks that implicit public modifier detection for method is working
  *
  * @dataProvider implicitPublicModifiers
  *
  * @param integer $modifier Node type modifier
  */
 public function testImplicitPublic($modifier)
 {
     $node = new ClassMethod('foo', array('type' => constant('PhpParser\\Node\\Stmt\\Class_::MODIFIER_' . strtoupper($modifier))));
     $this->assertTrue($node->isPublic(), 'Node should be implicitly public');
 }
Esempio n. 4
0
 /**
  * Transform class/interface name to FQN format
  * @todo WHY WHY :'(
  *
  * @param string $className
  * @return string
  */
 public function getFullName($className)
 {
     $namespace = isset($this->currentMethod) && $this->currentMethod instanceof FunctionDefinition ? $this->currentMethod->getNamespace() : $this->classDefinition->getNamespace();
     return Utils::getFullName($className, $namespace, $this->aliasManager);
 }
Esempio n. 5
0
 /**
  * Builds a class definition from reflection
  *
  * @param \ReflectionClass $class
  */
 public static function buildFromReflection(\ReflectionClass $class)
 {
     $classDefinition = new ClassDefinition($class->getNamespaceName(), $class->getName());
     $methods = $class->getMethods();
     if (count($methods) > 0) {
         foreach ($methods as $method) {
             $parameters = array();
             foreach ($method->getParameters() as $row) {
                 $parameters[] = array('type' => 'parameter', 'name' => $row->getName(), 'const' => 0, 'data-type' => 'variable', 'mandatory' => !$row->isOptional());
             }
             $classMethod = new ClassMethod($classDefinition, array(), $method->getName(), new ClassMethodParameters($parameters));
             $classMethod->setIsStatic($method->isStatic());
             $classMethod->setIsInternal(true);
             $classDefinition->addMethod($classMethod);
         }
     }
     $constants = $class->getConstants();
     if (count($constants) > 0) {
         foreach ($constants as $constantName => $constantValue) {
             $type = self::_convertPhpConstantType(gettype($constantValue));
             $classConstant = new ClassConstant($constantName, array('value' => $constantValue, 'type' => $type), null);
             $classDefinition->addConstant($classConstant);
         }
     }
     $classDefinition->setIsInternal(true);
     return $classDefinition;
 }
Esempio n. 6
0
{
    public function hello()
    {
        echo "hello" . PHP_EOL;
    }
    public abstract function say($something);
}
class ClassMethod
{
    use AbstractMethod;
    public function say($something)
    {
        echo $something . PHP_EOL;
    }
}
$cm = new ClassMethod();
$cm->hello();
$cm->say("hello");
// properties
trait Prop
{
    public $var = 10;
    static $sta = 20;
}
class CProp
{
    use Prop;
}
$prop = new CProp();
echo $prop->var . PHP_EOL;
echo CProp::$sta . PHP_EOL;