Modernize properties with PHP 8.4+ features and tighten visibility - #15
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #15 +/- ##
============================================
- Coverage 96.13% 94.83% -1.31%
+ Complexity 157 144 -13
============================================
Files 13 13
Lines 388 329 -59
============================================
- Hits 373 312 -61
- Misses 15 17 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the collections/mapper API to use public read + restricted write properties (property hooks) instead of getter/setter methods, and updates tests and supporting utilities accordingly.
Changes:
- Replace Collection/Typed/Filtered/Composite getter/setter methods with property access + constructors.
- Update AbstractMapper, CollectionIterator, and the in-memory test mapper to use the new property-based API.
- Simplify Style implementations and adjust PHPCS config to tolerate property hook syntax.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/InMemoryMapper.php | Updates test mapper to use property access (name, condition, more, etc.) and $this->style. |
| tests/Collections/TypedTest.php | Updates tests to assert against new properties (next, children, type, etc.). |
| tests/Collections/FilteredTest.php | Updates tests to use new properties (filters, identifierOnly, etc.). |
| tests/Collections/CompositeTest.php | Updates tests to use new properties (compositions, children, etc.). |
| tests/Collections/CollectionTest.php | Updates tests for property-based API and removes reflection-based assertions tied to removed internals. |
| tests/CollectionIteratorTest.php | Updates iterator-related tests to use children property. |
| tests/AbstractMapperTest.php | Updates tests for collection registration, mapper/style access via properties. |
| src/Styles/Standard.php | Refactors to more concise return expressions. |
| src/Styles/Plural.php | Refactors to more concise return expressions. |
| src/Styles/NorthWind.php | Refactors to more concise return expressions. |
| src/Styles/CakePHP.php | Refactors to more concise return expressions. |
| src/NotPersistable.php | Marks attribute class as readonly. |
| src/Collections/Typed.php | Moves type into constructor + readonly property; updates entity resolution to use name property. |
| src/Collections/Filtered.php | Moves filters into constructor + readonly property; adds computed identifierOnly property. |
| src/Collections/Composite.php | Moves compositions into constructor + readonly property. |
| src/Collections/Collection.php | Major refactor: property hooks, mapper resolution via parent chain, computed more/hasChildren, and tail traversal. |
| src/CollectionIterator.php | Tightens types and switches traversal logic to new properties (more, children, next, name). |
| src/AbstractMapper.php | Switches to property-based API (style, next, etc.), adjusts tracking storage typing, and refactors hydration helper. |
| phpcs.xml.dist | Excludes PHPCS sniffs that can’t parse property hooks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
- Replace trivial getters/setters with asymmetric visibility (public private(set)) on Collection, Filtered, Typed, Composite properties - Add virtual property hooks: Collection::$hasChildren, $more, Filtered::$identifierOnly, AbstractMapper::$style - Use constructor promotion with readonly for Typed::$type, Composite::$compositions, Filtered::$filters - Make NotPersistable a final readonly class - Cache tail node in Collection::$last for O(1) chain stacking - Tighten visibility: AbstractMapper::$collections and tryHydration() to private, Collection::findMapper()/resolveMapper() to private - Remove all trivial getters (getName, getCondition, getNext, getParent, getChildren, isRequired, getFilters, getType, getCompositions), setters (setMapper, setCondition, setParent, setRequired), and boolean methods (hasChildren, hasMore, isIdentifierOnly, getStyle) - Inline single-use variables and convert verbose conditionals to ternaries across Style classes - Exclude PSR2.Classes.PropertyDeclaration from PHPCS (4.0.x cannot parse property hooks) - Update all callers in src and tests to use direct property access
private(set)) on Collection, Filtered, Typed, Composite properties
Filtered::$identifierOnly, AbstractMapper::$style
Composite::$compositions, Filtered::$filters
to private, Collection::findMapper()/resolveMapper() to private
getChildren, isRequired, getFilters, getType, getCompositions),
setters (setMapper, setCondition, setParent, setRequired), and boolean
methods (hasChildren, hasMore, isIdentifierOnly, getStyle)
ternaries across Style classes
parse property hooks)