Skip to content

Commit 51fbb73

Browse files
committed
Enhanced PHPDoc. Removed @type support.
1 parent 8ee9f87 commit 51fbb73

File tree

5 files changed

+40
-70
lines changed

5 files changed

+40
-70
lines changed

doc/configuration.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,6 @@ rdfa:
189189

190190
*Support for other namespaces than `http://schema.org` is planned for future versions but not currently available.*
191191

192-
## Enabling PSR-5 PHPDoc support
193-
194-
Set the `useType` option to `true` and the generator will use the `@type` annotation (defined in ([PSR-5](https://github.com/php-fig/fig-standards/pull/169))
195-
instead of the traditional `@var`.
196-
197-
*The current status of PSR-5 is draft and is still subject to major modifications.*
198-
199192
## Checking GoodRelation compatibility
200193

201194
If the `checkIsGoodRelations` option is set to `true`, the generator will emit a warning if an encountered property is not
@@ -246,9 +239,6 @@ generateId: true
246239
# Generate interfaces and use Doctrine's Resolve Target Entity feature
247240
useInterface: false
248241
249-
# Use PSR-5's @type annotation instead of @var in the PHPDoc
250-
useType: false
251-
252242
# Use Doctrine's ArrayCollection instead of standard arrays
253243
useDoctrineCollection: true
254244

doc/getting-started.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -134,61 +134,61 @@ use Symfony\Component\Validator\Constraints as Assert;
134134
class Person extends Thing
135135
{
136136
/**
137-
* @var integer $id
137+
* @var integer
138138
* @ORM\Column(type="integer")
139139
* @ORM\Id
140140
* @ORM\GeneratedValue(strategy="AUTO")
141141
*/
142142
private $id;
143143
/**
144-
* @var string $additionalName An additional name for a Person, can be used for a middle name.
144+
* @var string An additional name for a Person, can be used for a middle name.
145145
* @Assert\Type(type="string")
146146
* @ORM\Column(nullable=true)
147147
*/
148148
private $additionalName;
149149
/**
150-
* @var PostalAddress $address Physical address of the item.
150+
* @var PostalAddress Physical address of the item.
151151
* @ORM\ManyToOne(targetEntity="PostalAddress")
152152
*/
153153
private $address;
154154
/**
155-
* @var \DateTime $birthDate Date of birth.
155+
* @var \DateTime Date of birth.
156156
* @Assert\Date
157157
* @ORM\Column(type="date", nullable=true)
158158
*/
159159
private $birthDate;
160160
/**
161-
* @var string $email Email address.
161+
* @var string Email address.
162162
* @Assert\Email
163163
* @ORM\Column(nullable=true)
164164
*/
165165
private $email;
166166
/**
167-
* @var string $familyName Family name. In the U.S., the last name of an Person. This can be used along with givenName instead of the name property.
167+
* @var string Family name. In the U.S., the last name of an Person. This can be used along with givenName instead of the name property.
168168
* @Assert\Type(type="string")
169169
* @ORM\Column(nullable=true)
170170
*/
171171
private $familyName;
172172
/**
173-
* @var string $gender Gender of the person.
173+
* @var string Gender of the person.
174174
* @Assert\Type(type="string")
175175
* @ORM\Column(nullable=true)
176176
*/
177177
private $gender;
178178
/**
179-
* @var string $givenName Given name. In the U.S., the first name of a Person. This can be used along with familyName instead of the name property.
179+
* @var string Given name. In the U.S., the first name of a Person. This can be used along with familyName instead of the name property.
180180
* @Assert\Type(type="string")
181181
* @ORM\Column(nullable=true)
182182
*/
183183
private $givenName;
184184
/**
185-
* @var string $jobTitle The job title of the person (for example, Financial Manager).
185+
* @var string The job title of the person (for example, Financial Manager).
186186
* @Assert\Type(type="string")
187187
* @ORM\Column(nullable=true)
188188
*/
189189
private $jobTitle;
190190
/**
191-
* @var string $telephone The telephone number.
191+
* @var string The telephone number.
192192
* @Assert\Type(type="string")
193193
* @ORM\Column(nullable=true)
194194
*/
@@ -448,32 +448,32 @@ use Symfony\Component\Validator\Constraints as Assert;
448448
class PostalAddress
449449
{
450450
/**
451-
* @var integer $id
451+
* @var integer
452452
* @ORM\Column(type="integer")
453453
* @ORM\Id
454454
* @ORM\GeneratedValue(strategy="AUTO")
455455
*/
456456
private $id;
457457
/**
458-
* @var string $addressCountry The country. For example, USA. You can also provide the two-letter [ISO 3166-1 alpha-2 country code](http://en.wikipedia.org/wiki/ISO_3166-1).
458+
* @var string The country. For example, USA. You can also provide the two-letter [ISO 3166-1 alpha-2 country code](http://en.wikipedia.org/wiki/ISO_3166-1).
459459
* @Assert\Type(type="string")
460460
* @ORM\Column(nullable=true)
461461
*/
462462
private $addressCountry;
463463
/**
464-
* @var string $addressLocality The locality. For example, Mountain View.
464+
* @var string The locality. For example, Mountain View.
465465
* @Assert\Type(type="string")
466466
* @ORM\Column(nullable=true)
467467
*/
468468
private $addressLocality;
469469
/**
470-
* @var string $addressRegion The region. For example, CA.
470+
* @var string The region. For example, CA.
471471
* @Assert\Type(type="string")
472472
* @ORM\Column(nullable=true)
473473
*/
474474
private $addressRegion;
475475
/**
476-
* @var string $postalCode The postal code. For example, 94043.
476+
* @var string The postal code. For example, 94043.
477477
* @Assert\Type(type="string")
478478
* @ORM\Column(nullable=true)
479479
*/
@@ -485,7 +485,7 @@ class PostalAddress
485485
*/
486486
private $postOfficeBoxNumber;
487487
/**
488-
* @var string $streetAddress The street address. For example, 1600 Amphitheatre Pkwy.
488+
* @var string The street address. For example, 1600 Amphitheatre Pkwy.
489489
* @Assert\Type(type="string")
490490
* @ORM\Column(nullable=true)
491491
*/
@@ -690,19 +690,19 @@ use MyCLabs\Enum\Enum;
690690
class OfferItemCondition extends Enum
691691
{
692692
/**
693-
* @type string DamagedCondition
693+
* @var string DamagedCondition
694694
*/
695695
const DAMAGED_CONDITION = 'http://schema.org/DamagedCondition';
696696
/**
697-
* @type string NewCondition
697+
* @var string NewCondition
698698
*/
699699
const NEW_CONDITION = 'http://schema.org/NewCondition';
700700
/**
701-
* @type string RefurbishedCondition
701+
* @var string RefurbishedCondition
702702
*/
703703
const REFURBISHED_CONDITION = 'http://schema.org/RefurbishedCondition';
704704
/**
705-
* @type string UsedCondition
705+
* @var string UsedCondition
706706
*/
707707
const USED_CONDITION = 'http://schema.org/UsedCondition';
708708
}

src/SchemaOrgModel/AnnotationGenerator/PhpDocAnnotationGenerator.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,10 @@ public function generateConstantAnnotations($className, $constantName)
4242
$resource = $this->classes[$className]['constants'][$constantName]['resource'];
4343

4444
$annotations = $this->formatDoc($resource->get('rdfs:comment'), true);
45-
if ($this->config['useType']) {
46-
$annotations[0] = sprintf(
47-
'@type %s %s',
48-
'string',
49-
$constantName,
50-
$annotations[0]
51-
);
52-
}
45+
$annotations[0] = sprintf(
46+
'@var string %s',
47+
$annotations[0]
48+
);
5349

5450
return $annotations;
5551
}
@@ -64,10 +60,8 @@ public function generateFieldAnnotations($className, $fieldName)
6460

6561
$annotations = $this->formatDoc($comment, true);
6662
$annotations[0] = sprintf(
67-
'@%s %s $%s %s',
68-
$this->config['useType'] ? 'type' : 'var',
63+
'@var %s %s',
6964
$this->toPhpType($field),
70-
$fieldName,
7165
$annotations[0]
7266
);
7367

src/SchemaOrgModel/TypesGeneratorConfiguration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function getConfigTreeBuilder()
4848
->booleanNode('debug')->defaultFalse()->info('Debug mode')->end()
4949
->booleanNode('generateId')->defaultTrue()->info('Automatically add an id field to entities')->end()
5050
->booleanNode('useInterface')->defaultFalse()->info('Generate interfaces and use Doctrine\'s Resolve Target Entity feature')->end()
51-
->booleanNode('useType')->defaultFalse()->info('Use PSR-5\'s @type annotation instead of @var in the PHPDoc')->end()
5251
->booleanNode('useDoctrineCollection')->defaultTrue()->info('Use Doctrine\'s ArrayCollection instead of standard arrays')->end()
5352
->booleanNode('checkIsGoodRelations')->defaultFalse()->info('Emit a warning if a property is not derived from GoodRelations')->end()
5453
->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/ecommerce.yml

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,34 @@ namespaces:
1717
interface: "Dunglas\EcommerceBundle\Model"
1818
author: "Kévin Dunglas <[email protected]>"
1919
debug: true
20-
useType: true
2120
useInterface: true
2221
checkIsGoodRelations: true
2322
types:
2423
Thing:
2524
properties:
2625
name: ~
2726
description: ~
28-
# image: ~
27+
image: ~
28+
additionalType: ~
2929
Product:
3030
properties:
31+
sku:
32+
cardinality: "(0..1)"
33+
url: ~
3134
brand: ~
32-
color: ~
33-
depth: ~
35+
productId: ~
36+
releaseDate: ~
37+
offers: ~
38+
itemCondition: ~
3439
gtin13: ~
3540
gtin14: ~
3641
gtin8: ~
37-
height: ~
38-
itemCondition: ~
3942
mpn: ~
40-
offers: ~
41-
productId: ~
42-
releaseDate: ~
43-
sku:
44-
cardinality: "(0..1)"
45-
weight: ~
46-
width: ~
43+
color: ~
44+
depth: { range: "Text" }
45+
height: { range: "Text" }
46+
weight: { range: "Text" }
47+
width: { range: "Text" }
4748
Brand:
4849
parent: "Thing"
4950
properties:
@@ -52,18 +53,13 @@ types:
5253
parent: Thing
5354
properties:
5455
caption: ~
55-
QuantitativeValue:
56-
properties:
57-
unitCode: ~
58-
value: ~
5956
ProductModel:
6057
properties:
6158
isVariantOf: ~
6259
Offer:
6360
parent: Thing
6461
properties:
6562
acceptedPaymentMethod: ~
66-
# addOn: ~
6763
availability: ~
6864
availabilityStarts: ~
6965
availabilityEnds: ~
@@ -72,22 +68,13 @@ types:
7268
deliveryLeadTime: ~
7369
inventoryLevel: ~
7470
itemCondition: ~
75-
priceSpecification: ~
76-
PriceSpecification:
77-
parent: false
78-
properties:
79-
eligibleQuantity: ~
80-
eligibleTransactionVolume: ~
8171
price: ~
72+
priceCurrency: ~
8273
validFrom: ~
8374
validThrough: ~
84-
valueAddedTaxIncluded: ~
8575
DeliveryChargeSpecification: ~
8676
PaymentChargeSpecification: ~
8777
OfferItemCondition: ~
8878
PaymentMethod: ~
8979
ItemAvailability: ~
9080
DeliveryMethod: ~
91-
# WarrantyPromise: ~
92-
# WarrantyScope:
93-
# parent: false

0 commit comments

Comments
 (0)