Skip to content

Commit e2096ba

Browse files
committed
Expand API documentation for float-typed value classes and aliases
- Enhanced documentation for `FloatStandard`, `FloatNonNegative`, and `FloatPositive` with detailed descriptions, examples, and usage scenarios. - Introduced and documented aliases, including `Double`, `FloatType`, `Positive`, and `NonNegative`, with updated examples highlighting their usage and purpose. - Improved clarity around factory methods, validation behaviors, and formatting helpers across float type definitions.
1 parent d11699e commit e2096ba

File tree

7 files changed

+67
-8
lines changed

7 files changed

+67
-8
lines changed

src/Float/Alias/Double.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
use PhpTypedValues\Float\FloatStandard;
88

99
/**
10+
* Alias for the generic float-typed value ("double").
11+
*
12+
* Provides the same behavior as FloatStandard while offering a commonly used
13+
* synonym name "Double".
14+
*
15+
* Example
16+
* - $v = Double::fromString('2.5');
17+
* $v->toString(); // "2.5"
18+
* - $v = Double::fromFloat(0.75);
19+
* (string) $v; // "0.75"
20+
*
1021
* @psalm-immutable
1122
*/
1223
readonly class Double extends FloatStandard

src/Float/Alias/FloatType.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
use PhpTypedValues\Float\FloatStandard;
88

99
/**
10+
* Alias for the generic float-typed value.
11+
*
12+
* Provides the same behavior as FloatStandard while offering a more descriptive
13+
* name for APIs that prefer "FloatType".
14+
*
15+
* Example
16+
* - $v = FloatType::fromString('1.25');
17+
* $v->toString(); // "1.25"
18+
*
1019
* @psalm-immutable
1120
*/
1221
readonly class FloatType extends FloatStandard

src/Float/Alias/NonNegative.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@
77
use PhpTypedValues\Float\FloatNonNegative;
88

99
/**
10-
* Alias of Non-negative float (>= 0.0).
10+
* Alias for non‑negative float-typed value (>= 0.0).
1111
*
12-
* Example "0.0"
12+
* Provides the same behavior as FloatNonNegative while exposing a concise
13+
* name suitable for APIs that prefer "NonNegative".
14+
*
15+
* Example
16+
* - $v = NonNegative::fromString('0.0');
17+
* $v->value(); // 0.0
18+
* - $v = NonNegative::fromFloat(10.25);
19+
* (string) $v; // "10.25"
1320
*
1421
* @psalm-immutable
1522
*/

src/Float/Alias/Positive.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
use PhpTypedValues\Float\FloatPositive;
88

99
/**
10+
* Alias for positive float-typed value (> 0.0).
11+
*
12+
* Provides the same behavior as FloatPositive while exposing a concise name
13+
* suitable for APIs that prefer "Positive".
14+
*
15+
* Example
16+
* - $v = Positive::fromString('0.1');
17+
* $v->value(); // 0.1
18+
* - $v = Positive::fromFloat(2.5);
19+
* (string) $v; // "2.5"
20+
*
1021
* @psalm-immutable
1122
*/
1223
readonly class Positive extends FloatPositive

src/Float/FloatNonNegative.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212
use function sprintf;
1313

1414
/**
15-
* Non-negative float (>= 0.0).
15+
* Nonnegative float-typed value (>= 0.0).
1616
*
17-
* Example "0.0"
17+
* Guarantees the wrapped float is zero or positive. Offers factories from
18+
* validated string and native float, plus standard string formatting.
19+
*
20+
* Example
21+
* - $v = FloatNonNegative::fromString('0.0');
22+
* $v->value(); // 0.0
23+
* - $v = FloatNonNegative::fromFloat(10.25);
24+
* (string) $v; // "10.25"
1825
*
1926
* @psalm-immutable
2027
*/

src/Float/FloatPositive.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212
use function sprintf;
1313

1414
/**
15-
* Positive float (> 0.0).
15+
* Positive float-typed value (> 0.0).
1616
*
17-
* Example "0.1"
17+
* Ensures the wrapped float is strictly greater than zero. Provides factories
18+
* from validated string and native float and convenient formatting helpers.
19+
*
20+
* Example
21+
* - $v = FloatPositive::fromString('0.1');
22+
* $v->value(); // 0.1
23+
* - $v = FloatPositive::fromFloat(2.5);
24+
* (string) $v; // "2.5"
1825
*
1926
* @psalm-immutable
2027
*/

src/Float/FloatStandard.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010
use PhpTypedValues\Undefined\Alias\Undefined;
1111

1212
/**
13-
* Represents any PHP float (double).
13+
* Generic float-typed value.
1414
*
15-
* Example "3.14"
15+
* Wraps any PHP float (double) and provides factories from native float or
16+
* validated string, along with convenient string formatting.
17+
*
18+
* Example
19+
* - $v = FloatStandard::fromString('3.14');
20+
* $v->value(); // 3.14 (float)
21+
* - $v = FloatStandard::fromFloat(0.5);
22+
* (string) $v; // "0.5"
1623
*
1724
* @psalm-immutable
1825
*/

0 commit comments

Comments
 (0)