Skip to content

Add getTypes#26

Merged
charjr merged 1 commit intomainfrom
add-get-types-to-interface
Nov 15, 2024
Merged

Add getTypes#26
charjr merged 1 commit intomainfrom
add-get-types-to-interface

Conversation

@charjr
Copy link
Collaborator

@charjr charjr commented Nov 14, 2024

We may need to consider how to make this consistent:

null would imply type has not been specified, thus can be any type.

In 3.1 null is a type, so not specifying type means that null is acceptable.

But in 3.0 null is not a type, nullable is a keyword. So if type is unspecified, but nullable is set to false... null is not acceptable.

if ($this->nullable) {
$result[] = Type::Null;
}
return empty($result) ? null : $result;

Therefore, not specifying type has different meaning, depending on the version.

Proposed Solution

We have getTypes() return all acceptable types.

Advantages

  • We get a version agnostic "this is what it can be"
    • We get a version agnostic "this can|can't be null"

Disadvantages

We cannot rely on getTypes() to tell if it was unspecified.
To know if a type was specified, we would have to look at the property $type.
Thus we would want something like this when using it:

if (isset($schema->type)) {
    $types = $schema->getTypes();
    // do something...
}

@charjr charjr changed the title Add getTypes Add getTypes (MERGE AFTER TEST-MIN-MAX) Nov 14, 2024
@charjr charjr force-pushed the add-get-types-to-interface branch from 2647c83 to 88427b2 Compare November 14, 2024 17:13
@charjr charjr marked this pull request as draft November 14, 2024 18:47
@charjr charjr force-pushed the add-get-types-to-interface branch from 88427b2 to 716e110 Compare November 15, 2024 10:28
Base automatically changed from test-min-max to main November 15, 2024 12:21
@charjr charjr changed the title Add getTypes (MERGE AFTER TEST-MIN-MAX) Add getTypes Nov 15, 2024
@charjr charjr marked this pull request as ready for review November 15, 2024 12:24
@charjr charjr force-pushed the add-get-types-to-interface branch from 716e110 to 0c972a5 Compare November 15, 2024 12:25
@charjr charjr merged commit 96a5e04 into main Nov 15, 2024
@charjr charjr deleted the add-get-types-to-interface branch November 15, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants