public function create(ClassType $classType)
 {
     $source = $this->sourceFactory->create($classType);
     //Adds EntityRepository as parent.
     $source->addParent(ClassType::create('NullDev\\Theater\\DoctrineOrm\\EntityRepository'));
     return $source;
 }
 public function create(ClassType $classType)
 {
     $source = $this->sourceFactory->create($classType);
     //Adds ElasticSearchRepository as parent.
     $source->addParent(ClassType::create('Broadway\\ReadModel\\ElasticSearch\\ElasticSearchRepository'));
     return $source;
 }
 public function create(ClassType $classType, array $parameters)
 {
     $source = $this->sourceFactory->create($classType);
     //Adds Projector as parent.
     $source->addParent(ClassType::create('Broadway\\ReadModel\\Projector'));
     $source->addConstructorMethod($this->definitionFactory->createConstructorMethod($parameters));
     return $source;
 }
 public function create(ClassType $classType, ClassType $modelClassType)
 {
     $source = $this->sourceFactory->create($classType);
     $source->addParent(ClassType::create('Broadway\\EventSourcing\\EventSourcingRepository'));
     $source->addImport(ClassType::create('Broadway\\EventSourcing\\AggregateFactory\\PublicConstructorAggregateFactory'));
     $source->addImport(ClassType::create('Broadway\\EventHandling\\EventBusInterface'));
     $source->addImport(ClassType::create('Broadway\\EventStore\\EventStoreInterface'));
     //Add aggregate root id as property.
     //Add constructor which calls parent constructor method.
     $source->addMethod($this->definitionFactory->createBroadwayModelRepositoryConstructorMethod($modelClassType));
     return $source;
 }
 public function create(ClassType $classType, Parameter $parameter)
 {
     $source = $this->sourceFactory->create($classType);
     $source->addParent(ClassType::create('Broadway\\EventSourcing\\EventSourcedAggregateRoot'));
     //Add aggregate root id as property.
     $source->addProperty($parameter);
     $source->addImport($parameter->getClassType());
     //Add static create() method.
     $source->addMethod($this->definitionFactory->createBroadwayModelCreateMethod($classType, [$parameter]));
     //Add aggregate root id getter.
     $source->addMethod($this->definitionFactory->createBroadwayModelAggregateRootIdGetterMethod($parameter));
     return $source;
 }
 public function create(ClassType $classType)
 {
     $source = $this->sourceFactory->create($classType);
     $param = $this->definitionFactory->createParameter('id', new StringType());
     //Add constructor method.
     $source->addConstructorMethod($this->definitionFactory->createConstructorMethod([$param]));
     //Add __toString() method.
     $source->addMethod($this->definitionFactory->createToStringMethod($param));
     //Add static create() method.
     $source->addMethod($this->definitionFactory->createUuidCreateMethod($classType));
     //Add Ramsey\Uuid\Uuid to imports.
     $source->addImport(ClassType::create('Ramsey\\Uuid\\Uuid'));
     return $source;
 }
 /**
  * @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;
 }
 protected function provideBroadwayDoctrineOrmReadProjector() : ImprovedClassSource
 {
     $classType = new ClassType('ProductReadProjector', 'MyShop\\ReadModel\\Product');
     $parameters = [new Parameter('repository', ClassType::create('MyShop\\ReadModel\\Product\\ProductReadRepository')), new Parameter('factory', ClassType::create('MyShop\\ReadModel\\Product\\ProductReadFactory'))];
     $factory = new DoctrineOrm\ReadProjectorSourceFactory(new ClassSourceFactory(), new DefinitionFactory());
     return $factory->create($classType, $parameters);
 }