Beispiel #1
0
 /**
  * @param \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject $classObject
  * @param bool $skipStatements
  * @return \PhpParser\Node\Stmt\Class_
  */
 public function buildClassNode($classObject, $skipStatements = false)
 {
     $factory = new \PhpParser\BuilderFactory();
     $classNodeBuilder = $factory->class($classObject->getName());
     if ($classObject->getParentClassName()) {
         $classNodeBuilder->extend(self::buildNodeFromName($classObject->getParentClassName()));
     }
     $interfaceNames = $classObject->getInterfaceNames();
     if (count($interfaceNames) > 0) {
         call_user_func_array(array($classNodeBuilder, 'implement'), $interfaceNames);
     }
     if (!$skipStatements) {
         $stmts = array();
         $properties = array();
         $methods = array();
         foreach ($classObject->getUseTraitStatement() as $statement) {
             $stmts[] = $statement;
         }
         foreach ($classObject->getMethods() as $method) {
             $methods[$method->getName()] = $this->buildMethodNode($method);
         }
         foreach ($classObject->getProperties() as $property) {
             $properties[$property->getName()] = $this->buildPropertyNode($property);
         }
         $constants = $classObject->getConstants();
         if (is_array($constants)) {
             foreach ($constants as $name => $value) {
                 $stmts[] = self::buildClassConstantNode($name, $value);
             }
         }
         foreach ($properties as $property) {
             $stmts[] = $property;
         }
         foreach ($methods as $method) {
             $stmts[] = $method;
         }
         $classNodeBuilder->addStmts($stmts);
     }
     $classNode = $classNodeBuilder->getNode();
     $classNode->type = $classObject->getModifiers();
     $this->addCommentAttributes($classObject, $classNode);
     return $classNode;
 }
 /**
  * compares the number of methods found by parsing with those
  * retrieved from the reflection class
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\ClassObject\ClassObject $classObject
  * @param \TYPO3\CMS\Extbase\Reflection\ClassReflection $classReflection
  * @return void
  */
 public function ParserFindsAllConstants($classObject, $classReflection)
 {
     $reflectionConstantCount = count($classReflection->getConstants());
     if ($classReflection->getParentClass()) {
         $reflectionConstantCount -= count($classReflection->getParentClass()->getConstants());
     }
     $classObjectConstantCount = count($classObject->getConstants());
     $this->assertEquals($reflectionConstantCount, $classObjectConstantCount, 'Not all Constants were found: ' . $classObject->getName() . serialize($classReflection->getConstants()));
 }