Skip to content

Commit 02edb19

Browse files
committed
PHPDoc's @var support (instead of @type).
1 parent 46f2539 commit 02edb19

File tree

5 files changed

+8
-2
lines changed

5 files changed

+8
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ debug: false
6161
# Generate interfaces and use Doctrine's Resolve Target Entity feature
6262
useInterface: false
6363

64+
# Use PSR-5's @type annotation instead of @var in the PHPDoc.
65+
useType: false
66+
6467
# Use Doctrine's ArrayCollection instead of standard arrays
6568
useDoctrineCollection: true
6669

src/SchemaOrgModel/AnnotationGenerator/PhpDocAnnotationGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public function generateFieldAnnotations($className, $fieldName)
6161

6262
$annotations = $this->formatDoc($field['resource']->get('rdfs:comment'), true);
6363
$annotations[0] = sprintf(
64-
'@type %s $%s %s',
64+
'@%s %s $%s %s',
65+
$this->config['useType'] ? 'type' : 'var',
6566
$this->toPhpType($field),
6667
$fieldName,
6768
$annotations[0]

src/SchemaOrgModel/TypesGeneratorConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function getConfigTreeBuilder()
4747
->end()
4848
->booleanNode('debug')->defaultFalse()->info('Debug mode')->end()
4949
->booleanNode('useInterface')->defaultFalse()->info('Generate interfaces and use Doctrine\'s Resolve Target Entity feature')->end()
50+
->booleanNode('useType')->defaultFalse()->info('Use PSR-5\'s @type annotation instead of @var in the PHPDoc.')->end()
5051
->booleanNode('useDoctrineCollection')->defaultTrue()->info('Use Doctrine\'s ArrayCollection instead of standard arrays')->end()
5152
->booleanNode('checkIsGoodRelations')->defaultFalse()->info('Emit a warning if a property is not derived from GoodRelations')->end()
5253
->scalarNode('header')->defaultFalse()->info('A license or any text to use as header of generated files')->example('// (c) Kévin Dunglas <[email protected]>')->end()

tests/config/address-book.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespaces:
2-
entity: "AppBundle\Entity"
2+
entity: "Dunglas\AddressBookBundle\Entity"
33
types:
44
Thing:
55
properties:

tests/config/ecommerce.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespaces:
1717
interface: "Dunglas\EcommerceBundle\Model"
1818
author: "Kévin Dunglas <[email protected]>"
1919
debug: true
20+
useType: true
2021
useInterface: true
2122
checkIsGoodRelations: true
2223
types:

0 commit comments

Comments
 (0)