Skip to content

Commit f87b9b4

Browse files
committed
Update docs with correct nullable information.
Fix bug #14
1 parent 4582fa7 commit f87b9b4

File tree

9 files changed

+40
-23
lines changed

9 files changed

+40
-23
lines changed

docs/source/complexTypes/array.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Generated interface:
2424

2525
.. code-block:: php
2626
27-
public function setExample(?array $example): self;
27+
public function setExample(array $example): self;
28+
// As the property is not required it may be initialized with null. Consequently the return value is nullable
2829
public function getExample(): ?array;
2930
3031
Possible exceptions:
@@ -117,17 +118,17 @@ In this case the model generator will generate two classes: **Family** and **Mem
117118
.. code-block:: php
118119
119120
// class Family
120-
public function setMembers(?array $members): self;
121+
public function setMembers(array $members): self;
121122
public function getMembers(): ?array;
122123
123124
// class Member
124125
public function setName(string $name): self;
125126
public function getName(): string;
126127
127-
public function setAge(?int $age): self;
128+
public function setAge(int $age): self;
128129
public function getAge(): ?int;
129130
130-
The *getMembers* function of the class *Family* is typehinted with *@returns Member[]*. Consequently auto completion is available when developing something like:
131+
The *getMembers* function of the class *Family* is type hinted with *@returns Member[]*. Consequently auto completion is available when developing something like:
131132

132133
.. code-block:: php
133134
@@ -138,6 +139,10 @@ The *getMembers* function of the class *Family* is typehinted with *@returns Mem
138139
$member->getName();
139140
}
140141
142+
.. hint::
143+
144+
Arrays with item validation don't accept elements which contain `null`. If your array needs to accept `null` entries you have to add null to the type of your items explicitly (eg. "type": ["object", "null"]).
145+
141146
Tuples
142147
------
143148

docs/source/complexTypes/multiType.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Generated interface (doesn't contain type hints as multiple types are allowed):
1919

2020
.. code-block:: php
2121
22+
// $example will be type-annotated with `float|string`
2223
public function setExample($example): self;
24+
// $example will be type-annotated with `float|string|null` (as the property isn't required)
2325
public function getExample();
2426
2527
Possible exceptions:
@@ -60,6 +62,7 @@ For each type given in the allowed types array additional validators may be adde
6062
}
6163
}
6264
65+
The property example will be type hinted with `float|string|string[]|null`.
6366
The validators are applied if the given input matches the corresponding type.
6467
For example if an array **["Hello", 123, "Goodbye"]** is given the validation will fail as numbers aren't allowed in arrays:
6568

docs/source/complexTypes/object.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ Generated interface:
3232
.. code-block:: php
3333
3434
// class Person
35-
public function setName(?string $name): self;
35+
public function setName(string $name): self;
36+
// As the property is not required it may be initialized with null. Consequently the return value is nullable
3637
public function getName(): ?string;
37-
public function setCar(?Car $name): self;
38+
public function setCar(Car $name): self;
3839
public function getCar(): ?Car;
3940
4041
// class Car
41-
public function setModel(?string $name): self;
42+
public function setModel(string $name): self;
4243
public function getModel(): ?string;
43-
public function setPs(?int $name): self;
44+
public function setPs(int $name): self;
4445
public function getPs(): ?int;
4546
4647
Possible exceptions:
@@ -102,9 +103,9 @@ Generated interface:
102103

103104
.. code-block:: php
104105
105-
public function setUnderscorePropertyMinus(?string $name): self;
106+
public function setUnderscorePropertyMinus(string $name): self;
106107
public function getUnderscorePropertyMinus(): ?string;
107-
public function setCapsAndSpace100(?string $name): self;
108+
public function setCapsAndSpace100(string $name): self;
108109
public function getCapsAndSpace100(): ?string;
109110
110111
If the name normalization results in an empty attribute name (eg. '__ -- __') an exception will be thrown.
@@ -283,14 +284,14 @@ Generated interface:
283284

284285
.. code-block:: php
285286
286-
// class Family, arrays typehinted in docblocks with Family_Person[]
287-
public function setMembers(?array $members): self;
287+
// class Family, arrays type hinted in docblocks with Family_Person[]
288+
public function setMembers(array $members): self;
288289
public function getMembers(): ?array;
289290
290-
// class Person, arrays typehinted in docblocks with Family_Person[]
291-
public function setName(?string $name): self;
291+
// class Person, arrays type hinted in docblocks with Family_Person[]
292+
public function setName(string $name): self;
292293
public function getName(): ?string;
293-
public function setChildren(?array $name): self;
294+
public function setChildren(array $name): self;
294295
public function getChildren(): ?array;
295296
296297
Property Names
@@ -448,10 +449,11 @@ Generated interface:
448449
449450
// class CreditCardOwner
450451
// base properties
451-
public function setCreditCard(?int $creditCard): self;
452+
public function setCreditCard(int $creditCard): self;
452453
public function getCreditCard(): ?int;
453454
454455
// inherited properties
456+
// the inherited properties will not be type hinted as they may contain any value if credit_card isn't present.
455457
public function setBillingAddress($billingAddress): self;
456458
public function getBillingAddress();
457459
public function setDateOfBirth($dateOfBirth): self;

docs/source/generic/required.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Required values
22
===============
33

4-
By default the values of a schema are not required. In this case the input is valid if the property is not provided. Additionally an explicit `null` value is also valid. If the value isn't provided an optionally defined default value is used.
4+
By default the values of a schema are not required. In this case the input is valid if the property is not provided. If the value isn't provided an optionally defined default value is used.
55

66
.. code-block:: json
77
@@ -21,7 +21,8 @@ Generated interface:
2121

2222
.. code-block:: php
2323
24-
public function setExample(?string $example): self;
24+
public function setExample(string $example): self;
25+
// As the property is not required it may be initialized with null. Consequently the return value is nullable
2526
public function getExample(): ?string;
2627
2728
Behaviour with different inputs:
@@ -35,6 +36,7 @@ Behaviour with different inputs:
3536
// property example explicitly set to null.
3637
// allowed as the property isn't required.
3738
// Works only if implicitNull is enabled. Otherwise an exception will be thrown.
39+
// If implicitNull is enabled the signature of setExample will also change to accept null.
3840
$example = new Example(['example' => null]);
3941
$example->getExample(); // returns NULL
4042

docs/source/gettingStarted.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ By default the properties are strictly checked against their defined types. Cons
161161

162162
By setting the implicit null option to true all of your object properties which aren't required will implicitly accept null. All properties which are required and don't explicitly allow null in the type definition will still reject null.
163163

164+
If the implicit null option is enabled the interface of your classes may change. If you have disabled immutability the type hints of your optional property setters will be nullable (eg. a string property will be type hinted with `?string`).
165+
164166
.. code-block:: php
165167
166168
setImplicitNull(bool $allowImplicitNull);

docs/source/types/boolean.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Generated interface:
1919

2020
.. code-block:: php
2121
22-
public function setExample(?bool $example): self;
22+
public function setExample(bool $example): self;
23+
// As the property is not required it may be initialized with null. Consequently the return value is nullable
2324
public function getExample(): ?bool;
2425
2526
Possible exceptions:

docs/source/types/number.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ Generated interface:
2222

2323
.. code-block:: php
2424
25-
public function setExample1(?int $example): self;
25+
public function setExample1(int $example): self;
26+
// As the property is not required it may be initialized with null. Consequently the return value is nullable
2627
public function getExample1(): ?int;
2728
28-
public function setExample2(?float $example): self;
29+
public function setExample2(float $example): self;
2930
public function getExample2(): ?float;
3031
3132
Possible exceptions:

docs/source/types/string.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Generated interface:
1919

2020
.. code-block:: php
2121
22-
public function setExample(?string $example): self;
22+
public function setExample(string $example): self;
23+
// As the property is not required it may be initialized with null. Consequently the return value is nullable
2324
public function getExample(): ?string;
2425
2526
Possible exceptions:

src/SchemaProvider/RecursiveDirectoryProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(string $sourceDirectory)
3434
throw new FileSystemException("Source directory '$sourceDirectory' doesn't exist");
3535
}
3636

37-
$this->sourceDirectory = $sourceDirectory;
37+
$this->sourceDirectory = rtrim($sourceDirectory, "\\/");
3838
}
3939

4040
/**

0 commit comments

Comments
 (0)