Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed data #29

Merged
merged 6 commits into from
Feb 10, 2023
Merged

Typed data #29

merged 6 commits into from
Feb 10, 2023

Conversation

gapple
Copy link
Owner

@gapple gapple commented Dec 30, 2020

New classes make constructing a value to pass to Serializer and working with data from Parser easier.
Tuple types (Item and InnerList) are still accessible by array indexes to be backwards compatible with older code ($item->value === $item[0], $item->parameters === $item[1])

  • Item
  • OuterList
  • InnerList
  • Dictionary
  • Parameters
Serializer::serializeItem(new Item(true));
// ?1
Serializer::serializeItem(new Item('towel', (object) ['panic' => false']));
// "towel";panic=?0

Resolves #19

@gapple gapple added the enhancement New feature or request label Dec 30, 2020
@gapple gapple self-assigned this Dec 30, 2020
@gapple gapple added this to the 0.4.0 milestone Feb 22, 2021
@gapple gapple force-pushed the typed-data branch 2 times, most recently from 59fee87 to 6e882f7 Compare January 11, 2022 07:44
@codecov
Copy link

codecov bot commented Jan 11, 2022

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (da7f48a) compared to base (489626c).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff              @@
##             develop       #29    +/-   ##
============================================
  Coverage     100.00%   100.00%            
- Complexity       103       169    +66     
============================================
  Files              5        11     +6     
  Lines            246       391   +145     
============================================
+ Hits             246       391   +145     
Flag Coverage Δ
phpunit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Dictionary.php 100.00% <100.00%> (ø)
src/InnerList.php 100.00% <100.00%> (ø)
src/Item.php 100.00% <100.00%> (ø)
src/OuterList.php 100.00% <100.00%> (ø)
src/Parameters.php 100.00% <100.00%> (ø)
src/Parser.php 100.00% <100.00%> (ø)
src/Serializer.php 100.00% <100.00%> (ø)
src/TupleTrait.php 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@gapple gapple force-pushed the typed-data branch 7 times, most recently from e9517d0 to 78b38fe Compare January 11, 2022 22:03
src/InnerList.php Outdated Show resolved Hide resolved
src/Parser.php Show resolved Hide resolved
tests/RulesetTest.php Outdated Show resolved Hide resolved
tests/ParseListTest.php Outdated Show resolved Hide resolved
@gapple
Copy link
Owner Author

gapple commented Jan 12, 2022

Some static fromArray() methods would be helpful to convert simple arrays to valid structures for serializing.

  • OuterList::fromArray() - convert an array of scalar values to an array of Items or InnerLists
  • InnerList::fromArray() - convert an array of scalar values to an array of Items
  • Dictionary::fromArray() - convert an associative array to an array of Items. Numeric indexes could throw an exception here, but leave validation of string keys to Serializer
  • Parameters::FromArray() - basically a wrapper for (object) $array, but an exception for numeric indexes could be helpful.

@gapple gapple force-pushed the typed-data branch 6 times, most recently from 4b8c0cb to 917f54b Compare January 15, 2022 09:11
src/Item.php Show resolved Hide resolved
@gapple gapple marked this pull request as ready for review February 9, 2023 08:25
@gapple
Copy link
Owner Author

gapple commented Feb 9, 2023

It's potentially a BC break that Parser:parseItem() and Parser::parseList() methods return objects instead of arrays.

The new classes still allow access in the same way as with the untyped return values (via ArrayAccess, and the OuterList class is iterable), so code making use of them shouldn't need to be changed, unless they pass on the value to somewhere that is typed to expect an array.

@gapple gapple changed the title [WIP] Typed data Typed data Feb 9, 2023
@gapple gapple merged commit da7f48a into develop Feb 10, 2023
@gapple gapple deleted the typed-data branch February 10, 2023 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typed Data
1 participant