-
Notifications
You must be signed in to change notification settings - Fork 5
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
Bind SQL invokable object to the provider #30
Conversation
@coderabbitai reviw |
@koriym, I will review the changes in the pull request. Actions performedReview triggered.
|
WalkthroughThe updates primarily focus on enhancing SQL query management within a PHP project. Key changes include replacing scheduled triggers in CI workflows, updating PHP version configurations, adding new dependencies, and introducing several new classes and interfaces for SQL query handling. These modifications streamline SQL injection using annotations, improve test coverage, and ensure compatibility with recent PHP versions. Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant Client
participant TodoRepository
participant SqlFinder
participant Database
Client->>TodoRepository: Create Todo
TodoRepository->>SqlFinder: Find SQL (todo_insert)
SqlFinder->>Database: Execute SQL
Database-->>TodoRepository: Return Result
TodoRepository-->>Client: Return Confirmation
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 2
Outside diff range and nitpick comments (1)
src/SqlQueryModule.php (1)
42-42
: Binding ofSqlDir
to an instance inconfigure
method.Consider documenting the use of the deprecated
AliasQuery
class to clarify its necessity and planned replacement.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
vendor-bin/tools/composer.lock
is excluded by!**/*.lock
Files selected for processing (21)
- .github/workflows/continuous-integration.yml (1 hunks)
- .github/workflows/static-analysis.yml (2 hunks)
- composer.json (1 hunks)
- src/Annotation/Sql.php (1 hunks)
- src/Exception/SqlFileNotFoundException.php (1 hunks)
- src/Exception/SqlNotAnnotatedException.php (1 hunks)
- src/InvokeInterface.php (1 hunks)
- src/RowInterfaceProvider.php (1 hunks)
- src/RowListInterface.php (1 hunks)
- src/RowListInterfaceProvider.php (1 hunks)
- src/SqlDir.php (1 hunks)
- src/SqlFinder.php (1 hunks)
- src/SqlQueryModule.php (1 hunks)
- src/SqlQueryProviderModule.php (1 hunks)
- src/SqlQueryRowList.php (1 hunks)
- tests/Fake/FakeTodoProviderSqlNotAnnotated.php (1 hunks)
- tests/Fake/FakeTodoProviderSqlNotFound.php (1 hunks)
- tests/Fake/FakeTodoRepository.php (1 hunks)
- tests/Fake/FakeTodoRepositoryAttr.php (1 hunks)
- tests/SqlQueryProviderModuleTest.php (1 hunks)
- vendor-bin/tools/composer.json (1 hunks)
Files skipped from review due to trivial changes (6)
- .github/workflows/continuous-integration.yml
- .github/workflows/static-analysis.yml
- src/Exception/SqlFileNotFoundException.php
- src/Exception/SqlNotAnnotatedException.php
- src/SqlDir.php
- vendor-bin/tools/composer.json
Additional comments not posted (18)
src/RowListInterface.php (1)
7-7
: Interface extension toInvokeInterface
aligns well with the PR's objectives.tests/Fake/FakeTodoProviderSqlNotAnnotated.php (1)
7-15
: The test class is well-implemented and aligns with the changes in the main codebase.src/InvokeInterface.php (1)
7-15
: The extension ofQueryInterface
and the implementation of__invoke
method are well-documented and align with the PR's objectives.tests/Fake/FakeTodoProviderSqlNotFound.php (1)
7-20
: The use of an intentionally invalid SQL annotation for testing error handling is a good practice.tests/Fake/FakeTodoRepositoryAttr.php (1)
11-15
: Constructor implementation and attribute usage are correct and follow PHP 8 best practices.src/Annotation/Sql.php (1)
10-24
: Annotation setup and constructor implementation are correctly defined and follow best practices for interoperability with Doctrine's system.tests/Fake/FakeTodoRepository.php (1)
11-34
: Use of annotations and constructor setup are correctly implemented for SQL injection and dependency injection in a test environment.src/RowInterfaceProvider.php (1)
22-35
: Constructor andget
method implementations are robust, correctly handling dependency injection and dynamic SQL resolution.src/RowListInterfaceProvider.php (2)
22-30
: Constructor correctly initializes class properties with injected dependencies.
32-35
: Methodget
correctly provides an instance ofSqlQueryRowList
using dynamic SQL retrieval.src/SqlFinder.php (1)
28-34
: Constructor correctly initializes class properties with injected dependencies.src/SqlQueryRowList.php (1)
57-57
: Verify the necessity of usingstrtolower
on the query string, as it might lead to unexpected behavior.composer.json (2)
20-20
: Dependencykoriym/param-reader
added.Verification successful
The
koriym/param-reader
dependency is integrated and used in the following files:
src/SqlFinder.php
src/SqlQueryProviderModule.php
The usage of
ParamReader
andParamReaderInterface
in these files confirms the integration of the dependency.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the integration of `koriym/param-reader` in the codebase. # Test: Search for usage of `koriym/param-reader` classes. Expect: At least one occurrence. rg --type php 'ParamReader'Length of output: 548
22-22
: Dependencynikic/php-parser
added.tests/SqlQueryProviderModuleTest.php (4)
49-54
: Test methodtestProviderInject
looks good.
59-64
: Test methodtestProviderInjectAttr
effectively tests attribute-based SQL annotations.
77-82
: Test methodtestSqlFileNotFoundException
effectively handles SQL file not found scenarios.
84-89
: Test methodtestSqlNotAnnotated
effectively handles scenarios where SQL is not annotated.
Changed the binding scope of RowInterface, RowListInterface, and InvokeInterface classes in SqlQueryProviderModule to "Singleton". This update ensures that these classes will have only one instance throughout the application, enhancing performance and reducing resource usage.
The workflows for coding standards, continuous integration, and static analysis have been consolidated and refactored to use external workflow templates managed by Ray-di. This results in sleeker configuration files and ensures uniformity across different projects.
Removed unnecessary typecasting in SqlFinder file. Now, the $param variable is directly used in the sprintf function, improving the efficiency of the code.
The "use" statement for the InvalidArgumentException was added, allowing for a direct name reference instead of a full path, increasing code readability. The code was also refactored to use array destructuring syntax and to remove unnecessary quotes inside method calls which provides less redundancy and improves code consistency.
The phpstan version in the composer.json file has been updated from "^0.12" to "^1.11". This upgrade provides newer features and fixes for static analysis of the code.
This commit involves the removal of the checkMissingIterableValueType option from the phpstan.neon file. This option was preventing the analysis of missing iterable value types, but it has been deemed no longer necessary.
This commit involves the removal of the checkMissingIterableValueType option from the phpstan.neon file. This option was preventing the analysis of missing iterable value types, but it has been deemed no longer necessary.
This commit includes updating the Doctrine coding standard requirement from version 8.2 to 11.1 in composer.json. This change is part of the regular dependency update process to keep the code up-to-date and maintain system compatibility.
The scrutinizer configuration has been updated to support the latest PHP version of 8.2. Specifically, the build environment for PHP was adjusted and some unused tools were removed for simplicity.
The copyright year in the MIT License file has been updated to extend until 2024, reflecting the current duration of the copyright held by Akihito Koriyama.
An annotation has been added to suppress warnings generated by PHPMD's BooleanArgumentFlag rule for the constructor method in the "Query" class. This indicates that the method's design requires a boolean parameter, and false positives on this rule should be ignored.
7c9bc6b
to
2f557f6
Compare
The readonly attributes were removed from the FakeTodoRepositoryAttr class signature. This change ensures greater flexibility and adaptability of the class members.
The PHPUnit version specified under the "require-dev" section of the composer.json file was increased from "^9.5" to "^9.6.19". This ensures that the project uses the updated PHPUnit version during development.
A small typographical error in the @SuppressWarnings annotation in the Query class has been corrected. The corrected version now properly references the PHPMD (PHP Mess Detector) standard for suppressing boolean argument flag inspections.
@coderabbitai review |
Actions performedReview triggered.
|
@coderabbitai review |
Actions performedReview triggered.
|
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.
Actionable comments posted: 0
Outside diff range and nitpick comments (1)
src/WebQueryModule.php (1)
Line range hint
56-86
: Consider refactoring to reduce duplication in binding logic.private function configureWebQuery(string $name, string $method, string $uri): void { $prefixedName = 'wq-' . $name; $interfaces = [QueryInterface::class, RowInterface::class, RowListInterface::class]; foreach ($interfaces as $interface) { $this ->bind($interface) ->annotatedWith($name) ->toConstructor( WebQuery::class, [ 'method' => $prefixedName . '-method', 'uri' => $prefixedName . '-uri', ], ); } $this->bind()->annotatedWith($prefixedName . '-method')->toInstance($method); $this->bind()->annotatedWith($prefixedName . '-uri')->toInstance($uri); }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (30)
- .github/workflows/coding-standards.yml (1 hunks)
- .github/workflows/continuous-integration.yml (1 hunks)
- .github/workflows/static-analysis.yml (1 hunks)
- .scrutinizer.yml (1 hunks)
- LICENSE (1 hunks)
- composer.json (1 hunks)
- phpstan.neon (1 hunks)
- src-deprecated/SqlAliasInterceptor.php (3 hunks)
- src/Annotation/Query.php (1 hunks)
- src/Iso8601FormatModule.php (1 hunks)
- src/Iso8601Interceptor.php (1 hunks)
- src/PhpQueryModule.php (2 hunks)
- src/QueryInterceptor.php (3 hunks)
- src/RowInterfaceProvider.php (1 hunks)
- src/RowListInterfaceProvider.php (1 hunks)
- src/SqlFinder.php (1 hunks)
- src/SqlQueryModule.php (2 hunks)
- src/SqlQueryProviderModule.php (1 hunks)
- src/SqlQueryRow.php (1 hunks)
- src/SqlQueryRowList.php (2 hunks)
- src/WebQuery.php (1 hunks)
- src/WebQueryModule.php (6 hunks)
- tests/Fake/FakeTodoRepositoryAttr.php (1 hunks)
- tests/Iso8601FormatModuleTest.php (1 hunks)
- tests/Iso8601InterceptorTest.php (3 hunks)
- tests/SqlQueryModuleTest.php (1 hunks)
- tests/SqlQueryProviderModuleTest.php (1 hunks)
- tests/SqlQueryTest.php (3 hunks)
- tests/WebQueryModuleTest.php (2 hunks)
- vendor-bin/tools/composer.json (1 hunks)
Files skipped from review due to trivial changes (7)
- LICENSE
- phpstan.neon
- src/Annotation/Query.php
- src/Iso8601Interceptor.php
- src/QueryInterceptor.php
- tests/Iso8601FormatModuleTest.php
- tests/SqlQueryModuleTest.php
Files skipped from review as they are similar to previous changes (10)
- .github/workflows/static-analysis.yml
- composer.json
- src/RowInterfaceProvider.php
- src/SqlFinder.php
- src/SqlQueryModule.php
- src/SqlQueryProviderModule.php
- src/SqlQueryRowList.php
- tests/Fake/FakeTodoRepositoryAttr.php
- tests/SqlQueryProviderModuleTest.php
- vendor-bin/tools/composer.json
Additional comments not posted (21)
.github/workflows/coding-standards.yml (1)
9-12
: Updated workflow to use shared coding standards workflow and specified PHP 8.3..github/workflows/continuous-integration.yml (1)
9-14
: Updated CI workflow to use shared CI workflow, specified PHP version range, set PHP 8.3 as current stable, and defined a specific script to run.src/SqlQueryRow.php (1)
28-28
: Updated__invoke
method to handle multiple queries and ensure the result is iterable.src/Iso8601FormatModule.php (2)
14-18
: Constructor now accepts an array of datetime columns. This change aligns with the PR's objective to handle date-time configurations.
24-31
: Theconfigure
method correctly binds datetime columns and sets up interceptors. This setup ensures that date-time values are handled appropriately across SQL queries.src/RowListInterfaceProvider.php (2)
23-31
: Constructor correctly initializes dependencies. This standard dependency injection pattern is well-implemented here.
33-36
: Theget
method correctly provides an instance ofSqlQueryRowList
, ensuring proper dependency handling.src/PhpQueryModule.php (2)
18-22
: Constructor now accepts an iterable of configurations. This change supports dynamic configuration of query bindings.
35-35
: ThebindQuery
method correctly checks for class existence and interface implementation before binding. This ensures that only valid query handlers are bound.src/WebQuery.php (1)
35-36
: The__invoke
method's documentation has been updated to specify the return type asiterable<mixed>
. This enhances type clarity and aligns with modern PHP practices.tests/WebQueryModuleTest.php (2)
34-35
: Assertions correctly validate the structure and content of the result.
11-12
: Use ofassert
andis_array
functions are appropriate for the intended test validations.tests/Iso8601InterceptorTest.php (2)
29-31
: Assertions correctly validate the structure and content of the result, ensuring the date-time format is ISO8601.
55-55
: Use ofassert
function is appropriate for the intended test validations.tests/SqlQueryTest.php (3)
37-39
: Assertions correctly validate the structure and content of the result, ensuring the SQL query execution is as expected.
11-13
: Use ofassert
andis_array
functions are appropriate for the intended test validations.
61-65
: Assertions correctly validate the structure and content of the result, ensuring the multiple SQL query execution is as expected.src-deprecated/SqlAliasInterceptor.php (1)
37-37
: The method correctly handles the templating of SQL queries and appropriately throws an exception if the URL parsing fails.Also applies to: 80-80
src/WebQueryModule.php (3)
29-29
: Constructor correctly initializes properties and calls the parent constructor.
36-36
: Functionconfigure
correctly sets up the client and web queries based on the configuration.
101-101
: FunctionconfigureClient
correctly sets up the Guzzle client with appropriate configuration and scope.
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.
確認しました。問題ないと思います。
確かにこれなら大量のSQLファイルがあったとしても、開発時のファイル読み込みコストを削減できそうで👍です。
Closes #29
Summary by CodeRabbit
New Features
Improvements
Tests
Chores