public function generateCode($source, $target, $constructor = false)
 {
     $classAnalyzer = new ClassAnalyzer();
     $classAnalyzer->setFile($source);
     $parent = Object::make($classAnalyzer->getClassName());
     $targetClassName = $this->getClassName($target);
     $file = File::make($target);
     $object = Object::make($targetClassName);
     $object->extend($parent);
     $file->addFullyQualifiedName(new FullyQualifiedName($classAnalyzer->getFullClassName()));
     if ($constructor) {
         $constructor = $classAnalyzer->getConstructor();
         $method = Method::make('__construct');
         foreach ($constructor as $parameter) {
             $type = $parameter[0];
             if ($type === null) {
                 $type = 'null';
             }
             $method->addArgument(new Argument($type, $parameter[1]));
             $method->setBody('parent::__construct()');
         }
         $object->addMethod($method);
     }
     $file->setStructure($object);
     $prettyPrinter = Build::prettyPrinter();
     $generatedCode = $prettyPrinter->generateCode($file);
     return $generatedCode;
 }
Exemple #2
0
 public function testGetFunctionParametersInDifferentFormat()
 {
     $analyzer = new ClassAnalyzer();
     $analyzer->setCode($this->getCodeExampleTwo());
     $this->assertArraySubset(array(), $analyzer->getFunctionParameters('bar'));
     $this->assertArraySubset(array(array(null, 'world')), $analyzer->getFunctionParameters('hello'));
 }