/**
  * @param DocblockInterface $model
  * @return void
  */
 protected function buildDocblock(DocblockInterface $model)
 {
     $this->ensureBlankLine();
     if ($this->config->getGenerateDocblock()) {
         $model->generateDocblock();
     }
     $docblock = $model->getDocblock();
     if (!$docblock->isEmpty() || $this->config->getGenerateEmptyDocblock()) {
         $this->writer->writeln($docblock->toString());
     }
 }
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(['headerComment' => null, 'headerDocblock' => null, 'blankLineAtEnd' => true, 'declareStrictTypes' => false, 'generateScalarTypeHints' => function (Options $options) {
         return $options['declareStrictTypes'];
     }, 'generateReturnTypeHints' => function (Options $options) {
         return $options['declareStrictTypes'];
     }]);
     $resolver->setAllowedTypes('headerComment', ['null', 'string', 'gossi\\docblock\\Docblock']);
     $resolver->setAllowedTypes('headerDocblock', ['null', 'string', 'gossi\\docblock\\Docblock']);
     $resolver->setAllowedTypes('blankLineAtEnd', 'bool');
     $resolver->setAllowedTypes('declareStrictTypes', 'bool');
     $resolver->setNormalizer('headerComment', function (Options $options, $value) {
         return $this->toDocblock($value);
     });
     $resolver->setNormalizer('headerDocblock', function (Options $options, $value) {
         return $this->toDocblock($value);
     });
 }
Esempio n. 3
0
 public function testCodeGeneratorConfigSetters()
 {
     $config = new CodeGeneratorConfig();
     $config->setGenerateDocblock(false);
     $this->assertFalse($config->getGenerateDocblock());
     $this->assertFalse($config->getGenerateEmptyDocblock());
     $config->setGenerateEmptyDocblock(true);
     $this->assertTrue($config->getGenerateDocblock());
     $this->assertTrue($config->getGenerateEmptyDocblock());
     $config->setGenerateEmptyDocblock(false);
     $this->assertTrue($config->getGenerateDocblock());
     $this->assertFalse($config->getGenerateEmptyDocblock());
     $config->setGenerateReturnTypeHints(true);
     $this->assertTrue($config->getGenerateReturnTypeHints());
     $config->setGenerateScalarTypeHints(true);
     $this->assertTrue($config->getGenerateScalarTypeHints());
     $config->setUseStatementSorting(false);
     $this->assertFalse($config->getUseStatementSorting());
     $config->setConstantSorting('abc');
     $this->assertEquals('abc', $config->getConstantSorting());
     $config->setPropertySorting(new ComparableComparator());
     $this->assertTrue($config->getPropertySorting() instanceof Comparator);
     $cmp = function ($a, $b) {
         return strcmp($a, $b);
     };
     $config->setMethodSorting($cmp);
     $this->assertSame($cmp, $config->getMethodSorting());
     $config->setSortingEnabled(false);
     $this->assertFalse($config->isSortingEnabled());
 }
 protected function getAllowedOptionTypes()
 {
     return array_merge(['headerComment' => 'string', 'headerDocblock' => ['null', 'gossi\\docblock\\Docblock'], 'blankLineAtEnd' => 'bool', 'declareStrictTypes' => 'bool'], parent::getAllowedOptionTypes());
 }