Data definition with simple types #10

Merged
c.fahner merged 16 commits from issues/1 into main 2026-08-08 10:24:24 +02:00
Owner

Resolves #1.

Adds Entity, Schema and related classes.

Resolves #1. Adds Entity, Schema and related classes.
c.fahner added this to the v0.1 milestone 2026-08-03 21:01:41 +02:00
README.md Outdated
@ -3,0 +22,4 @@
#### Basic entity
TODO
Author
Owner

Needs an example

Needs an example
c.fahner marked this conversation as resolved
src/Entity.php Outdated
@ -0,0 +9,4 @@
* When implementing this interface the constructor must have a parameter called `id` of the type {@see Entity\Id}.
* Further configuration of the ID requires adding the {@see Schema\IdOptions} attribute.
*
* Fields are declared as parameters to the constructor of the entity.
Author
Owner

"as parameters of the constructor"

"as parameters **of** the constructor"
c.fahner marked this conversation as resolved
src/Entity.php Outdated
@ -0,0 +12,4 @@
* Fields are declared as parameters to the constructor of the entity.
* These parameters are later used to reconstruct an entity from a database record.
* Parameters can be excluded using the {@see Schema\Exclude} attribute.
* The {@see Schema\FieldName} attribute specifies the field name if the parameter name should not be used.
Author
Owner

"The FieldName attribute can be used to set the field name and prevent defaulting to the parameter name."

"The FieldName attribute can be used to set the field name and prevent defaulting to the parameter name."
Author
Owner

Went with "The {@see Schema\FieldName} attribute overrides the default field name (the parameter name)."

Went with "The {@see Schema\FieldName} attribute overrides the default field name (the parameter name)."
c.fahner marked this conversation as resolved
src/Schema.php Outdated
@ -0,0 +11,4 @@
/**
* Definition of an {@see Entity}'s structure and its relationships to other entities.
*
* Use the {@see Schema\Exclude} attribute to exclude a field.
Author
Owner

Make an actual markdown list of the described attributes.

Make an actual markdown list of the described attributes.
c.fahner marked this conversation as resolved
src/Schema.php Outdated
@ -0,0 +36,4 @@
/**
* Creates a schema from the constructor parameters of a given class.
*
* If the given class implements {@see Entity\Identifiable} it is required to declared an `$id`
Author
Owner

"required to declared an"

"required to declare~~d~~ an"
c.fahner marked this conversation as resolved
src/Schema.php Outdated
@ -0,0 +26,4 @@
/**
* The entity's regular fields.
*
* Does not contain the `id` field if the entity implements {@see Entity\Identifiable}.
Author
Owner

Move this explanation to fromConstructorParameters()

Move this explanation to `fromConstructorParameters()`
c.fahner marked this conversation as resolved
@ -0,0 +60,4 @@
throw Schema\DefinitionException::forMissingIdField();
}
$object->__construct($idOptions ?? new Schema\IdOptions(Schema\IdGenerator::None), $fields);
Author
Owner

Move $idOptions ?? new ... to separate line: $idOptions ??= ...

Move `$idOptions ?? new ...` to separate line: `$idOptions ??= ...`
c.fahner marked this conversation as resolved
@ -0,0 +57,4 @@
/** @return array{ type: Type, nullable: bool } */
private static function extractTypeInfo(ReflectionParameter $parameter): array {
$type = $parameter->getType();
if ($type === null) {
Author
Owner
if (!($type instanceof ReflectionNamedType)) {
    throw $type === null
        ? DefinitionException::forMissingFieldType($parameter->name)
        : DefinitionException::forUnsupportedFieldType($parameter->name, $type);
}
```php if (!($type instanceof ReflectionNamedType)) { throw $type === null ? DefinitionException::forMissingFieldType($parameter->name) : DefinitionException::forUnsupportedFieldType($parameter->name, $type); } ```
c.fahner marked this conversation as resolved
@ -0,0 +5,4 @@
use Attribute;
/**
* Allows specifying a different name for a field than the one implied by parameter or property.
Author
Owner

"Contains the preferred field name."

"Contains the preferred field name."
c.fahner marked this conversation as resolved
@ -0,0 +15,4 @@
final class IdOptionsTest extends TestCase {
public function test___construct_shouldNotThrow(): void {
$sut = new IdOptions(IdGenerator::UniqueIdentifier);
Author
Owner

Arrange: $generator = ...
Act: $result = new($generator)
Assert: $generator === $result->generator

Arrange: `$generator = ...` Act: `$result = new($generator)` Assert: `$generator === $result->generator`
c.fahner marked this conversation as resolved
@ -0,0 +39,4 @@
$this->assertFalse(isset($resultFields['id']));
}
public function test_fromConstructorParameters_shouldIgnoreExcludeAttributeAndSetDefaultGenerator_whenExcludeAttributeIsApplied(): void {
Author
Owner

_whenExcludeAttributeIsAppliedToId()

`_whenExcludeAttributeIsAppliedToId()`
c.fahner marked this conversation as resolved
c.fahner added spent time 2026-08-05 15:45:15 +02:00
50 minutes
Adds a data definition example
Removes "motivation" section to just mention distinguishing features in the intro
Adds a warning to the PHPDoc
Minor documentation changes
* Some documentation changes
* Moved a null coalesce assignment to a separate line
Made an if-elseif construction more readable (singe if + ternary)
c.fahner stopped working 2026-08-08 10:24:24 +02:00
8 minutes 17 seconds
c.fahner deleted branch issues/1 2026-08-08 10:24:24 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Total time spent: 58 minutes 17 seconds
c.fahner
58 minutes 17 seconds
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
slendium/ocd!10
No description provided.