-
Notifications
You must be signed in to change notification settings - Fork 6
0.6.x gateway improvements #110
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
base: 0.6.x
Are you sure you want to change the base?
Conversation
Refactor RowGateway and TableGateway classes to use PHP 8+ features: - Replace docblock type hints with native property type declarations using union types and nullable types - Add return type declarations to methods (offsetExists(): bool, offsetGet(): mixed, count(): int, etc.) - Use static return type for fluent interface methods - Convert constructor parameters to use union types in RowGateway and TableGateway Improve type safety and code quality: - Replace loose equality (==) with strict equality (===) in primary key comparisons - Simplify initialization checks using null comparisons instead of instanceof checks - Add proper instanceof StatementInterface guards before executing statements - Add lazy initialization to getFeatureSet(), getResultSetPrototype(), and getSql() getters - Add default case to match expression in TableGateway constructor - Update TableGatewayInterface::getTable() to return proper union type Cleanup: - Remove unused imports (is_string) - Remove redundant comments and phpcs ignore directives - Remove unused $alias variable in foreach loop - Fix @todo annotation format Update tests: - Change primaryKeyColumn to array format to match expected type - Remove unnecessary setAccessible(true) calls (not needed in PHP 8.1+) Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
Reverted constructor in TableGateway to allow nullable args and pass existing tests Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
Introduced spread operators instead of call_user_func_array
Aligned return types
Modified existing files to add RowPrototypeInterface Updated tests
Signed-off-by: Simon Mundy <46739456+simon-mundy@users.noreply.github.com>
| /** | ||
| * Exchange the current data for the provided array. | ||
| */ | ||
| public function exchangeArray(array $array): mixed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return type needs to array instead of mixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it doesn't - this could return any number of different objects depending on implementation. See AbstractRowGateway
src/ResultSet/AbstractResultSet.php
Outdated
| * Set the row object prototype | ||
| */ | ||
| abstract public function setRowPrototype(ArrayObject $rowPrototype): ResultSetInterface; | ||
| abstract public function setRowPrototype(ArrayObject|RowPrototypeInterface $rowPrototype): ResultSetInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither the getter nor setter methods are needed as abstract methods here since they are both in the interface.
The return type for the getter needs narrowed to ArrayObject|RowPrototypeInterface since if a custom prototype is not set then a default ArrayObject instance will be created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That creates a problem with PhpDb\ResultSet\HydratingResultSet::getRowPrototype
|
|
||
| /** @phpstan-ignore instanceof.alwaysTrue */ | ||
| if (! $this->featureSet instanceof Feature\FeatureSet) { | ||
| if ($this->featureSet === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still of the mindset that this can be simplified. The entire method body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For discussion - weighing up refactoring vs breaking change
test/unit/TableGateway/Feature/TestAsset/TestGlobalAdapterFeatureSubclass.php
Show resolved
Hide resolved
Added new FeatureInterface
Description
Adds PHP8.2+ modernisation, strong typing and general code cleanup.
Adds new RowPrototypeInterface to solve issues with new ResultSet and RowGateway
Adds 100% code coverage testing
Closes #63