Skip to content

Commit d2c74fb

Browse files
committed
Refactor and standardize integer type naming and testing structure
- Renamed multiple integer types (`WeekDayInt`, `NonNegativeInt`, `PositiveInt`, `IntegerBasic`) to align with naming consistency (`IntegerWeekDay`, `IntegerNonNegative`, `IntegerPositive`, `IntegerStandart`). - Introduced alias classes (`PositiveInt`, `NonNegativeInt`, `Id`) to retain backward compatibility and improve extensibility. - Added new tests for aliases to validate functionality. - Updated existing tests, documentation, and examples to use new naming conventions. - Enhanced exception hierarchy for stricter validations (`IntegerTypeException`).
1 parent 7f8c3c8 commit d2c74fb

21 files changed

+302
-109
lines changed

docs/INSTALL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ Create a quick test script (e.g., demo.php):
3131
<?php
3232
require __DIR__ . '/vendor/autoload.php';
3333

34-
use PhpTypedValues\Integer\PositiveInt;
34+
use PhpTypedValues\Integer\IntegerPositive;
3535

36-
echo PositiveInt::fromString('21')->value(); // 21
36+
echo IntegerPositive::fromString('21')->value(); // 21
3737
```
3838

3939
Run it:

docs/USAGE.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ Static usage examples
4141
---------------------
4242

4343
```php
44-
use PhpTypedValues\DateTime\DateTimeAtom;use PhpTypedValues\DateTime\Timestamp\TimestampSeconds;use PhpTypedValues\Float\FloatBasic;use PhpTypedValues\Float\NonNegativeFloat;use PhpTypedValues\Integer\IntegerBasic;use PhpTypedValues\Integer\NonNegativeInt;use PhpTypedValues\Integer\PositiveInt;use PhpTypedValues\Integer\WeekDayInt;use PhpTypedValues\String\NonEmptyStr;use PhpTypedValues\String\StringBasic;
44+
use PhpTypedValues\DateTime\DateTimeAtom;use PhpTypedValues\DateTime\Timestamp\TimestampSeconds;use PhpTypedValues\Float\FloatBasic;use PhpTypedValues\Float\NonNegativeFloat;use PhpTypedValues\Integer\IntegerStandart;use PhpTypedValues\Integer\IntegerNonNegative;use PhpTypedValues\Integer\IntegerPositive;use PhpTypedValues\Integer\IntegerWeekDay;use PhpTypedValues\String\NonEmptyStr;use PhpTypedValues\String\StringBasic;
4545

4646
// Integers
47-
$any = IntegerBasic::fromInt(-10);
48-
$pos = PositiveInt::fromInt(1);
49-
$nn = NonNegativeInt::fromInt(0);
50-
$wd = WeekDayInt::fromInt(7); // 1..7
47+
$any = IntegerStandart::fromInt(-10);
48+
$pos = IntegerPositive::fromInt(1);
49+
$nn = IntegerNonNegative::fromInt(0);
50+
$wd = IntegerWeekDay::fromInt(7); // 1..7
5151

5252
// From string (integers)
53-
$posFromString = PositiveInt::fromString('123');
54-
$wdFromString = WeekDayInt::fromString('5');
53+
$posFromString = IntegerPositive::fromString('123');
54+
$wdFromString = IntegerWeekDay::fromString('5');
5555

5656
// Strings
5757
$greeting = StringBasic::fromString('hello');
@@ -81,16 +81,16 @@ Validation errors (static constructors)
8181
Invalid input throws an exception with a helpful message.
8282

8383
```php
84-
use PhpTypedValues\Integer\PositiveInt;
85-
use PhpTypedValues\Integer\WeekDayInt;
84+
use PhpTypedValues\Integer\IntegerPositive;
85+
use PhpTypedValues\Integer\IntegerWeekDay;
8686
use PhpTypedValues\String\NonEmptyStr;
8787
use PhpTypedValues\Float\NonNegativeFloat;
8888
use PhpTypedValues\DateTime\DateTimeAtom;
8989

90-
PositiveInt::fromInt(0); // throws: must be > 0
91-
PositiveInt::fromString('12.3'); // throws: String has no valid integer
90+
IntegerPositive::fromInt(0); // throws: must be > 0
91+
IntegerPositive::fromString('12.3'); // throws: String has no valid integer
9292

93-
WeekDayInt::fromInt(0); // throws: Value must be between 1 and 7
93+
IntegerWeekDay::fromInt(0); // throws: Value must be between 1 and 7
9494

9595
NonEmptyStr::fromString(''); // throws: Value must be a non-empty string
9696

@@ -110,9 +110,9 @@ declare(strict_types=1);
110110

111111
namespace App\Domain;
112112

113-
use PhpTypedValues\Integer\PositiveInt;
113+
use PhpTypedValues\Integer\IntegerPositive;
114114

115-
final class UserId extends PositiveInt {}
115+
final class UserId extends IntegerPositive {}
116116

117117
// Usage
118118
$userId = UserId::fromInt(42);
@@ -190,15 +190,15 @@ declare(strict_types=1);
190190

191191
namespace App\Domain;
192192

193-
use PhpTypedValues\Integer\PositiveInt;
193+
use PhpTypedValues\Integer\IntegerPositive;
194194
use PhpTypedValues\String\NonEmptyStr;
195195
use PhpTypedValues\Float\NonNegativeFloat;
196196
use PhpTypedValues\DateTime\DateTimeAtom;
197197

198198
final class Profile
199199
{
200200
public function __construct(
201-
public readonly PositiveInt $id,
201+
public readonly IntegerPositive $id,
202202
public readonly NonEmptyStr $firstName,
203203
public readonly NonEmptyStr $lastName,
204204
public readonly ?NonEmptyStr $middleName, // nullable field
@@ -216,7 +216,7 @@ final class Profile
216216
int|float|string|null $heightM
217217
): self {
218218
return new self(
219-
PositiveInt::fromInt($id),
219+
IntegerPositive::fromInt($id),
220220
NonEmptyStr::fromString($firstName),
221221
NonEmptyStr::fromString($lastName),
222222
$middleName !== null ? NonEmptyStr::fromString($middleName) : null,
@@ -237,7 +237,7 @@ $p1 = Profile::fromScalars(
237237
);
238238

239239
$p2 = new Profile(
240-
id: PositiveInt::fromInt(202),
240+
id: IntegerPositive::fromInt(202),
241241
firstName: NonEmptyStr::fromString('Bob'),
242242
lastName: NonEmptyStr::fromString('Johnson'),
243243
middleName: NonEmptyStr::fromString('A.'),

src/Code/Exception/ReasonableRangeDateTimeTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
namespace PhpTypedValues\Code\Exception;
66

7-
class ReasonableRangeDateTimeTypeException extends TypeException
7+
class ReasonableRangeDateTimeTypeException extends DateTimeTypeException
88
{
99
}

src/Integer/Alias/Id.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpTypedValues\Integer\Alias;
6+
7+
use PhpTypedValues\Integer\IntegerPositive;
8+
9+
/**
10+
* @psalm-immutable
11+
*/
12+
readonly class Id extends IntegerPositive
13+
{
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpTypedValues\Integer\Alias;
6+
7+
use PhpTypedValues\Integer\IntegerNonNegative;
8+
9+
/**
10+
* @psalm-immutable
11+
*/
12+
readonly class NonNegativeInt extends IntegerNonNegative
13+
{
14+
}

src/Integer/Alias/PositiveInt.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpTypedValues\Integer\Alias;
6+
7+
use PhpTypedValues\Integer\IntegerPositive;
8+
9+
/**
10+
* @psalm-immutable
11+
*/
12+
readonly class PositiveInt extends IntegerPositive
13+
{
14+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* @psalm-immutable
1414
*/
15-
readonly class NonNegativeInt extends IntType
15+
readonly class IntegerNonNegative extends IntType
1616
{
1717
/** @var non-negative-int */
1818
protected int $value;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* @psalm-immutable
1414
*/
15-
readonly class PositiveInt extends IntType
15+
readonly class IntegerPositive extends IntType
1616
{
1717
/** @var positive-int */
1818
protected int $value;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* @psalm-immutable
1212
*/
13-
readonly class IntegerBasic extends IntType
13+
readonly class IntegerStandart extends IntType
1414
{
1515
protected int $value;
1616

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* @psalm-immutable
1414
*/
15-
readonly class WeekDayInt extends IntType
15+
readonly class IntegerWeekDay extends IntType
1616
{
1717
/** @var int<1, 7> */
1818
protected int $value;

0 commit comments

Comments
 (0)