Skip to content

Commit

Permalink
Enhanced PHPDoc. Removed @type support.
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Dec 28, 2014
1 parent 8ee9f87 commit 51fbb73
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 70 deletions.
10 changes: 0 additions & 10 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,6 @@ rdfa:

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

## Enabling PSR-5 PHPDoc support

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))
instead of the traditional `@var`.

*The current status of PSR-5 is draft and is still subject to major modifications.*

## Checking GoodRelation compatibility

If the `checkIsGoodRelations` option is set to `true`, the generator will emit a warning if an encountered property is not
Expand Down Expand Up @@ -246,9 +239,6 @@ generateId: true
# Generate interfaces and use Doctrine's Resolve Target Entity feature
useInterface: false
# Use PSR-5's @type annotation instead of @var in the PHPDoc
useType: false
# Use Doctrine's ArrayCollection instead of standard arrays
useDoctrineCollection: true
Expand Down
40 changes: 20 additions & 20 deletions doc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,61 +134,61 @@ use Symfony\Component\Validator\Constraints as Assert;
class Person extends Thing
{
/**
* @var integer $id
* @var integer
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string $additionalName An additional name for a Person, can be used for a middle name.
* @var string An additional name for a Person, can be used for a middle name.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $additionalName;
/**
* @var PostalAddress $address Physical address of the item.
* @var PostalAddress Physical address of the item.
* @ORM\ManyToOne(targetEntity="PostalAddress")
*/
private $address;
/**
* @var \DateTime $birthDate Date of birth.
* @var \DateTime Date of birth.
* @Assert\Date
* @ORM\Column(type="date", nullable=true)
*/
private $birthDate;
/**
* @var string $email Email address.
* @var string Email address.
* @Assert\Email
* @ORM\Column(nullable=true)
*/
private $email;
/**
* @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.
* @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.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $familyName;
/**
* @var string $gender Gender of the person.
* @var string Gender of the person.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $gender;
/**
* @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.
* @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.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $givenName;
/**
* @var string $jobTitle The job title of the person (for example, Financial Manager).
* @var string The job title of the person (for example, Financial Manager).
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $jobTitle;
/**
* @var string $telephone The telephone number.
* @var string The telephone number.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
Expand Down Expand Up @@ -448,32 +448,32 @@ use Symfony\Component\Validator\Constraints as Assert;
class PostalAddress
{
/**
* @var integer $id
* @var integer
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @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).
* @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).
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $addressCountry;
/**
* @var string $addressLocality The locality. For example, Mountain View.
* @var string The locality. For example, Mountain View.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $addressLocality;
/**
* @var string $addressRegion The region. For example, CA.
* @var string The region. For example, CA.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
private $addressRegion;
/**
* @var string $postalCode The postal code. For example, 94043.
* @var string The postal code. For example, 94043.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
Expand All @@ -485,7 +485,7 @@ class PostalAddress
*/
private $postOfficeBoxNumber;
/**
* @var string $streetAddress The street address. For example, 1600 Amphitheatre Pkwy.
* @var string The street address. For example, 1600 Amphitheatre Pkwy.
* @Assert\Type(type="string")
* @ORM\Column(nullable=true)
*/
Expand Down Expand Up @@ -690,19 +690,19 @@ use MyCLabs\Enum\Enum;
class OfferItemCondition extends Enum
{
/**
* @type string DamagedCondition
* @var string DamagedCondition
*/
const DAMAGED_CONDITION = 'http://schema.org/DamagedCondition';
/**
* @type string NewCondition
* @var string NewCondition
*/
const NEW_CONDITION = 'http://schema.org/NewCondition';
/**
* @type string RefurbishedCondition
* @var string RefurbishedCondition
*/
const REFURBISHED_CONDITION = 'http://schema.org/RefurbishedCondition';
/**
* @type string UsedCondition
* @var string UsedCondition
*/
const USED_CONDITION = 'http://schema.org/UsedCondition';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,10 @@ public function generateConstantAnnotations($className, $constantName)
$resource = $this->classes[$className]['constants'][$constantName]['resource'];

$annotations = $this->formatDoc($resource->get('rdfs:comment'), true);
if ($this->config['useType']) {
$annotations[0] = sprintf(
'@type %s %s',
'string',
$constantName,
$annotations[0]
);
}
$annotations[0] = sprintf(
'@var string %s',
$annotations[0]
);

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

$annotations = $this->formatDoc($comment, true);
$annotations[0] = sprintf(
'@%s %s $%s %s',
$this->config['useType'] ? 'type' : 'var',
'@var %s %s',
$this->toPhpType($field),
$fieldName,
$annotations[0]
);

Expand Down
1 change: 0 additions & 1 deletion src/SchemaOrgModel/TypesGeneratorConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function getConfigTreeBuilder()
->booleanNode('debug')->defaultFalse()->info('Debug mode')->end()
->booleanNode('generateId')->defaultTrue()->info('Automatically add an id field to entities')->end()
->booleanNode('useInterface')->defaultFalse()->info('Generate interfaces and use Doctrine\'s Resolve Target Entity feature')->end()
->booleanNode('useType')->defaultFalse()->info('Use PSR-5\'s @type annotation instead of @var in the PHPDoc')->end()
->booleanNode('useDoctrineCollection')->defaultTrue()->info('Use Doctrine\'s ArrayCollection instead of standard arrays')->end()
->booleanNode('checkIsGoodRelations')->defaultFalse()->info('Emit a warning if a property is not derived from GoodRelations')->end()
->scalarNode('header')->defaultFalse()->info('A license or any text to use as header of generated files')->example('// (c) Kévin Dunglas <[email protected]>')->end()
Expand Down
43 changes: 15 additions & 28 deletions tests/config/ecommerce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,34 @@ namespaces:
interface: "Dunglas\EcommerceBundle\Model"
author: "Kévin Dunglas <[email protected]>"
debug: true
useType: true
useInterface: true
checkIsGoodRelations: true
types:
Thing:
properties:
name: ~
description: ~
# image: ~
image: ~
additionalType: ~
Product:
properties:
sku:
cardinality: "(0..1)"
url: ~
brand: ~
color: ~
depth: ~
productId: ~
releaseDate: ~
offers: ~
itemCondition: ~
gtin13: ~
gtin14: ~
gtin8: ~
height: ~
itemCondition: ~
mpn: ~
offers: ~
productId: ~
releaseDate: ~
sku:
cardinality: "(0..1)"
weight: ~
width: ~
color: ~
depth: { range: "Text" }
height: { range: "Text" }
weight: { range: "Text" }
width: { range: "Text" }
Brand:
parent: "Thing"
properties:
Expand All @@ -52,18 +53,13 @@ types:
parent: Thing
properties:
caption: ~
QuantitativeValue:
properties:
unitCode: ~
value: ~
ProductModel:
properties:
isVariantOf: ~
Offer:
parent: Thing
properties:
acceptedPaymentMethod: ~
# addOn: ~
availability: ~
availabilityStarts: ~
availabilityEnds: ~
Expand All @@ -72,22 +68,13 @@ types:
deliveryLeadTime: ~
inventoryLevel: ~
itemCondition: ~
priceSpecification: ~
PriceSpecification:
parent: false
properties:
eligibleQuantity: ~
eligibleTransactionVolume: ~
price: ~
priceCurrency: ~
validFrom: ~
validThrough: ~
valueAddedTaxIncluded: ~
DeliveryChargeSpecification: ~
PaymentChargeSpecification: ~
OfferItemCondition: ~
PaymentMethod: ~
ItemAvailability: ~
DeliveryMethod: ~
# WarrantyPromise: ~
# WarrantyScope:
# parent: false

0 comments on commit 51fbb73

Please sign in to comment.