/**
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function generate(ImprovedClassSource $improvedClassSource)
 {
     $specClassType = ClassType::create('spec\\' . $improvedClassSource->getClassType()->getFullName() . 'Spec');
     $specSource = $this->factory->create($specClassType);
     foreach ($improvedClassSource->getImports() as $import) {
         if (false === $import instanceof TraitType) {
             $specSource->addImport($import);
         }
     }
     $specSource->addImport($improvedClassSource->getClassType());
     $specSource->addImport(ClassType::create('Prophecy\\Argument'));
     $specSource->addParent(ClassType::create('PhpSpec\\ObjectBehavior'));
     $initializable = [$improvedClassSource->getClassType()];
     if ($improvedClassSource->hasParent()) {
         $initializable[] = $improvedClassSource->getParent();
     }
     foreach ($improvedClassSource->getInterfaces() as $interface) {
         $initializable[] = $interface;
     }
     $lets = $improvedClassSource->getConstructorParameters();
     foreach ($improvedClassSource->getConstructorParameters() as $methodParameter) {
         if ($methodParameter->hasClass()) {
             $specSource->addImport($methodParameter->getClassType());
         }
     }
     //@TODO:
     foreach ($improvedClassSource->getMethods() as $method) {
         if ($method instanceof RepositoryConstructorMethod) {
             $lets[] = new Parameter('eventStore', InterfaceType::create('Broadway\\EventStore\\EventStoreInterface'));
             $lets[] = new Parameter('eventBus', InterfaceType::create('Broadway\\EventHandling\\EventBusInterface'));
             $lets[] = new Parameter('eventStreamDecorators', new ArrayType());
         }
     }
     $specSource->addMethod(new LetMethod($lets));
     $specSource->addMethod(new InitializableMethod($initializable));
     $skip = false;
     if (true === $improvedClassSource->hasParent()) {
         if ($improvedClassSource->getParent()->getFullName() === 'Broadway\\EventSourcing\\EventSourcingRepository') {
             $skip = true;
         }
     }
     if (false === $skip) {
         $specSource->addMethod(new ExposeConstructorArgumentsAsGettersMethod($lets));
     }
     return $specSource;
 }
 public function generate(ImprovedClassSource $classSource)
 {
     //Building class.
     $classCode = $this->builderFactory->class($classSource->getName());
     //Add parent to class.
     if ($classSource->hasParent()) {
         $classCode->extend($classSource->getParentName());
     }
     //Add interfaces
     foreach ($classSource->getInterfaces() as $interface) {
         $classCode->implement($interface->getName());
     }
     //Add traits
     foreach ($classSource->getTraits() as $trait) {
         $classCode->addStmt($this->createTrait($trait));
     }
     foreach ($classSource->getProperties() as $property) {
         $classCode->addStmt($this->createClassProperty($property));
     }
     return $classCode;
 }