Esempio n. 1
0
 /**
  * @param \TokenReflection\IReflectionClass $class
  *
  * @return string
  */
 public function writeElement(IReflectionClass $class)
 {
     $classString = $this->formatLine($this->writeAbstract($class) . $this->writeObjectType($class) . ' ' . $this->formatClassName($class->getName()) . ' {');
     if ($this->constantWriter) {
         $constantReflections = $class->getOwnConstantReflections();
         foreach ($class->getConstantReflections() as $otherConstantReflection) {
             /* @var $otherConstantReflection \TokenReflection\ReflectionConstant */
             $otherConstantName = $otherConstantReflection->getName();
             foreach ($constantReflections as $constantReflection) {
                 if ($constantReflection->getName() === $otherConstantName) {
                     // skip constants already defined in our current class
                     continue 2;
                 }
             }
             $constantReflections[] = $otherConstantReflection;
         }
         $classString .= $this->constantWriter->writeElements($constantReflections);
     }
     if ($this->propertyWriter) {
         $classString .= $this->propertyWriter->writeElements($class->getOwnProperties());
         if ($this->docContentWriter) {
             $classString .= $this->docContentWriter->writeProperties($class);
         }
     }
     if ($this->methodWriter) {
         $classString .= $this->methodWriter->writeElements($class->getOwnMethods());
         if ($this->docContentWriter) {
             $classString .= $this->docContentWriter->writeMethods($class);
         }
     }
     $classString .= $this->formatLine('}');
     if ($class->getParentClassName()) {
         $classString .= $this->formatLine($this->writeObjectType($class) . ' ' . $this->formatClassName($class->getName()) . ' extends ' . $this->formatClassName($class->getParentClassName()));
     }
     if ($interfaceNames = $class->getOwnInterfaceNames()) {
         foreach ($interfaceNames as $interfaceName) {
             $classString .= $this->formatLine($this->writeObjectType($class) . ' ' . $this->formatClassName($class->getName()) . ' implements ' . $this->formatClassName($interfaceName));
         }
     }
     return $classString;
 }
 public function testWriteElements()
 {
     $this->assertEquals("    +{static}MY_CONSTANT_NAME = \"somevalue\"\n    +{static}MY_CONSTANT_NAME = \"somevalue\"\n    +{static}MY_CONSTANT_NAME = \"somevalue\"\n", $this->constantWriter->writeElements(array($this->getConstanctMock(), $this->getConstanctMock(), $this->getConstanctMock())));
 }