Redesign internal mapping architecture using Strategy pattern.#22
Redesign internal mapping architecture using Strategy pattern.#22gustavofreze wants to merge 1 commit intomainfrom
Conversation
…object unwrapping, and reorganize test suite.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e0b3e65b26
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR refactors the internal mapping implementation to a Strategy-based architecture (builders/extractors/resolvers/strategies/transformers), updates tests and test fixtures to a new Test\\... namespace, and adjusts tooling/config to match the new structure.
Changes:
- Replaced the previous mapper/caster pipeline with
ObjectBuilder,ReflectionExtractor, and aStrategyResolverFactory-driven array mapping flow. - Added a new, more granular PHPUnit test suite (scalars/enums/iterables/collections/value objects/key preservation/constructors).
- Updated dev tooling and configuration (PHPStan ignores, dev autoload namespace, CI workflow).
Reviewed changes
Copilot reviewed 95 out of 95 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ValueObjectMappingTest.php | New tests covering deep value-object unwrapping and JSON output. |
| tests/ScalarMappingTest.php | New tests for scalar/null/empty value preservation in arrays/JSON. |
| tests/PropertyMappingTest.php | New tests for property mapping, defaults, and custom toArray overrides. |
| tests/ObjectMapperTest.php | Removed prior broad object-mapping test suite. |
| tests/Models/Webhook.php | New test fixture for mapping objects without constructors. |
| tests/Models/Uuid.php | New value-object fixture (implements ObjectMapper). |
| tests/Models/UserId.php | New value-object fixture (implements ObjectMapper). |
| tests/Models/Team.php | New fixture for nested collections. |
| tests/Models/Tags.php | New iterable collection fixture for tags. |
| tests/Models/Tag.php | New fixture with default public properties (no constructor). |
| tests/Models/Stores.php | Updated test fixture namespace to Test\\.... |
| tests/Models/Store.php | New fixture representing store element objects. |
| tests/Models/ShippingState.php | Updated test fixture namespace to Test\\.... |
| tests/Models/ShippingCountry.php | Updated test fixture namespace to Test\\.... |
| tests/Models/ShippingAddresses.php | Updated test fixture namespace to Test\\.... |
| tests/Models/ShippingAddress.php | Updated test fixture namespace to Test\\.... |
| tests/Models/Shipping.php | Updated test fixture namespace to Test\\.... |
| tests/Models/Service.php | Updated test fixture namespace to Test\\.... |
| tests/Models/Product.php | Updated test fixture namespace to Test\\.... |
| tests/Models/OrganizationId.php | New value-object fixture. |
| tests/Models/Organization.php | New aggregate fixture used in value-object tests. |
| tests/Models/Order.php | Updated test fixture namespace to Test\\.... |
| tests/Models/Merchant.php | Updated namespace + added strict_types. |
| tests/Models/Members.php | New iterable collection fixture for members. |
| tests/Models/MemberId.php | New value-object fixture. |
| tests/Models/Member.php | New member fixture with multiple nested value objects. |
| tests/Models/ExpirationDate.php | Removed prior date fixture (was used by deleted tests). |
| tests/Models/Employees.php | New iterable collection fixture for employees. |
| tests/Models/Employee.php | New employee fixture with defaulted constructor args. |
| tests/Models/DragonType.php | Updated test fixture namespace to Test\\.... |
| tests/Models/DragonSkills.php | Updated test fixture namespace to Test\\.... |
| tests/Models/Dragon.php | Updated test fixture namespace to Test\\.... |
| tests/Models/DeepValue.php | New deep-nesting value-object fixture for unwrapping tests. |
| tests/Models/Decimal.php | Updated test fixture namespace to Test\\.... |
| tests/Models/Customer.php | Updated test fixture namespace to Test\\.... |
| tests/Models/Currency.php | Updated test fixture namespace to Test\\.... |
| tests/Models/Configuration.php | Updated test fixture namespace to Test\\.... |
| tests/Models/Collection.php | Updated test fixture namespace to Test\\.... |
| tests/Models/Article.php | New fixture combining object + iterable collection mapping. |
| tests/Models/Amount.php | Updated test fixture namespace to Test\\.... |
| tests/KeyPreservationMappingTest.php | New tests for DISCARD/PRESERVE behavior in arrays/JSON. |
| tests/IterableTypeMappingTest.php | New tests for ArrayIterator/Generator/Closure mapping and reconstruction. |
| tests/IterableMapperTest.php | Removed prior broad iterable-mapping test suite. |
| tests/EnumMappingTest.php | New tests for backed/pure enums and invalid enum casts. |
| tests/ConstructorMappingTest.php | New tests for private constructors + no-constructor objects. |
| tests/CollectionMappingTest.php | New tests for nested collections and element defaults. |
| src/ObjectMappability.php | Switched fromIterable() and toArray() to builder/resolver-based flow. |
| src/KeyPreservation.php | Simplified shouldPreserveKeys() via match. |
| src/IterableMappability.php | Switched iterable mapping to resolver-based ArrayMapper. |
| src/Internal/Transformers/ValueObjectUnwrapper.php | New transformer to unwrap nested value objects. |
| src/Internal/Transformers/Transformer.php | New transformer interface. |
| src/Internal/Transformers/EnumTransformer.php | New enum-to-scalar transformer. |
| src/Internal/Transformers/DateTimeTransformer.php | New DateTime-to-ISO8601 transformer. |
| src/Internal/Strategies/ScalarMappingStrategy.php | New scalar mapping strategy. |
| src/Internal/Strategies/MappingStrategy.php | New mapping strategy interface. |
| src/Internal/Strategies/EnumMappingStrategy.php | New enum mapping strategy. |
| src/Internal/Strategies/DateTimeMappingStrategy.php | New DateTime mapping strategy. |
| src/Internal/Strategies/ComplexObjectMappingStrategy.php | New object mapping strategy using reflection + recursive resolution. |
| src/Internal/Strategies/CollectionMappingStrategy.php | New collectible mapping strategy with key preservation. |
| src/Internal/Resolvers/StrategyResolverContainer.php | New container enabling strategies to re-use the resolver. |
| src/Internal/Resolvers/StrategyResolver.php | New priority-based strategy resolver. |
| src/Internal/Mappers/Object/ObjectMapper.php | Removed old object mapper implementation. |
| src/Internal/Mappers/Object/Casters/Reflector.php | Relocated/updated reflector implementation for object instantiation. |
| src/Internal/Mappers/Object/Casters/ObjectMapper.php | New caster-layer object mapper for collection element casting. |
| src/Internal/Mappers/Object/Casters/GeneratorCaster.php | Minor updates (named arg usage). |
| src/Internal/Mappers/Object/Casters/EnumCaster.php | Updated enum casting logic using backed-case reflection. |
| src/Internal/Mappers/Object/Casters/DefaultCaster.php | Minor updates (named arg usage). |
| src/Internal/Mappers/Object/Casters/DateTimeCaster.php | Updated to accept DateTimeInterface inputs and return DateTimeInterface. |
| src/Internal/Mappers/Object/Casters/CollectionCaster.php | Updated collection casting; reuses mapper instance. |
| src/Internal/Mappers/Object/Casters/ClosureCaster.php | New caster for Closure-typed parameters. |
| src/Internal/Mappers/Object/Casters/CasterHandler.php | Updated caster selection logic (closure, enums via enum_exists, etc.). |
| src/Internal/Mappers/Object/Casters/ArrayIteratorCaster.php | Minor updates (named arg usage). |
| src/Internal/Mappers/JsonMapper.php | New flattened JSON mapper. |
| src/Internal/Mappers/Json/JsonMapper.php | Removed previous JSON mapper with “all empty => []” behavior. |
| src/Internal/Mappers/Collection/ValueMapper.php | Removed old collection value mapper. |
| src/Internal/Mappers/Collection/EnumMapper.php | Removed old collection enum mapper. |
| src/Internal/Mappers/Collection/DateTimeMapper.php | Removed old collection DateTime mapper. |
| src/Internal/Mappers/Collection/CollectionMapper.php | Removed old collection mapper. |
| src/Internal/Mappers/Collection/ArrayMapper.php | Removed old reflection-based array mapper. |
| src/Internal/Mappers/ArrayMapper.php | New array mapper delegating to StrategyResolver. |
| src/Internal/Factories/StrategyResolverFactory.php | New factory wiring detectors/transformers/strategies and resolver container. |
| src/Internal/Extractors/ValuePropertyExtractor.php | New “value” property extractor for value-object unwrapping. |
| src/Internal/Extractors/ReflectionExtractor.php | New extractor for object properties and constructor parameters. |
| src/Internal/Extractors/PropertyExtractor.php | New extractor interface. |
| src/Internal/Exceptions/InvalidCast.php | Minor cleanup in exception builder. |
| src/Internal/Detectors/ValueObjectDetector.php | New detector for “single value parameter” value objects. |
| src/Internal/Detectors/TypeDetector.php | New detector interface. |
| src/Internal/Detectors/ScalarDetector.php | New scalar detector. |
| src/Internal/Detectors/EnumDetector.php | New enum detector. |
| src/Internal/Detectors/DateTimeDetector.php | New DateTime detector. |
| src/Internal/Detectors/CollectibleDetector.php | New collectible detector. |
| src/Internal/Builders/ObjectBuilder.php | New reflection-based builder for fromIterable(). |
| phpstan.neon.dist | Updated ignore patterns for PHPStan analysis. |
| composer.json | Updated dev autoload namespace and bumped PHP_CodeSniffer constraint. |
| .github/workflows/ci.yml | Updated CI setup (removed bcmath extension installation). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ObjectBuilder,ReflectionExtractorandStrategyResolverFactory.