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

PCC-60: Queries to filter content using id or slug. #4

Merged
merged 1 commit into from
May 22, 2024
Merged

Conversation

sonvir249
Copy link
Collaborator

@sonvir249 sonvir249 commented May 22, 2024

Ticket - https://digitalpolygon.atlassian.net/browse/PCC-60

Summary by CodeRabbit

  • New Features

    • Enhanced article retrieval functionality with new methods to fetch articles by ID and slug.
  • Improvements

    • Updated type hinting for parameters and exceptions to improve code clarity and robustness.
  • Minor Changes

    • Added additional options for json_encode in the GraphQL query building process.
    • Minor formatting adjustments for better code readability.

Copy link

coderabbitai bot commented May 22, 2024

Walkthrough

The updates enhance the ContentApi class with new methods for fetching articles by ID and slug. The PccClient class sees improved type hinting for parameters and exceptions, while GraphQLQuery and QueryInterface files have type hint and formatting adjustments. These changes bolster the code's robustness and clarity, facilitating better API interaction and query handling.

Changes

File Path Change Summary
src/api/ContentApi.php Added getArticleById and getArticleBySlug methods for fetching articles by ID and slug.
src/core/PccClient.php Updated type hints for parameters and exceptions in executeQuery and sendRequest methods.
src/query/GraphQLQuery.php Updated type hints for variables property and constructor parameter, enhanced build method.
src/query/QueryInterface.php Added an extra newline after the build() method declaration.

In code we trust, with changes bright,
Articles fetched by ID or slug's light.
Type hints polished, exceptions clear,
Queries built with precision near.
A rabbit's joy in code's delight,
Enhancements made, all set to write!
🐇✨


Note

Free review on us!

CodeRabbit is offering free reviews until Mon May 27 2024 to showcase some of the refinements we've made.

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 52a3d74 and 1c48a4f.
Files selected for processing (4)
  • src/api/ContentApi.php (2 hunks)
  • src/core/PccClient.php (3 hunks)
  • src/query/GraphQLQuery.php (3 hunks)
  • src/query/QueryInterface.php (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/query/QueryInterface.php
Additional comments not posted (8)
src/query/GraphQLQuery.php (4)

20-22: Type hinting corrected to use fully qualified namespace for \ArrayObject. Good practice to avoid namespace conflicts.


24-24: Constructor now correctly expects a \ArrayObject for $variables, aligning with the property type hint change.


62-62: setVariables method now correctly expects a \ArrayObject, consistent with other changes in the file.


30-37: Enhanced JSON encoding options in build method to produce cleaner JSON outputs. Verify the JSON output in different environments to ensure compatibility.

src/core/PccClient.php (1)

35-43: Type hinting and exception handling in executeQuery method improved for clarity and robustness.

Verification successful

The PccClientException is thrown in the sendRequest method of PccClient.php, and this method is called by executeQuery. Ensure that executeQuery handles the exception correctly.

  • PccClient.php:
    • sendRequest method: Throws PccClientException.
    • executeQuery method: Calls sendRequest.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the specific exception handling works as expected.

# Test: Trigger exceptions in different scenarios and ensure they are caught and handled correctly.
echo "Manually test exception handling by simulating various error conditions."

Length of output: 154



Script:

#!/bin/bash
# Search for where PccClientException is thrown in the codebase
rg 'throw new \PccPhpSdk\Exception\PccClientException' --context 5

Length of output: 204



Script:

#!/bin/bash
# Corrected search for where PccClientException is thrown in the codebase
rg 'throw new PccPhpSdk\\Exception\\PccClientException' --context 5

Length of output: 69



Script:

#!/bin/bash
# Search for the definition of PccClientException in the codebase
rg 'class PccClientException' --context 5

Length of output: 433



Script:

#!/bin/bash
# Search for instances where PccClientException is used in the codebase
rg 'PccClientException' --context 5

Length of output: 4965

src/api/ContentApi.php (3)

17-18: Exception documentation in getAllArticles method updated to specify PccClientException. Good for clarity and consistency.


73-102: getArticleBySlug method correctly implemented with clear GraphQL query structure. Verify the execution of this query to ensure it retrieves the correct data.

Verification successful

The getArticleBySlug method in ContentApi.php is correctly implemented. The GraphQLQuery class and the executeQuery method in PccClient are properly defined and handle the query execution as expected. The build method in GraphQLQuery constructs the query correctly, and the sendRequest method in PccClient sends the request and processes the response appropriately.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct execution of GraphQL queries for article retrieval by slug.

# Test: Execute the query with known slugs and compare the results with expected data.
echo "Manually verify the GraphQL query execution by testing with known article slugs."

Length of output: 170



Script:

#!/bin/bash
# Find the implementation of the GraphQLQuery class
ast-grep --lang php --pattern 'class GraphQLQuery { $$$ }'

# Find the implementation of the executeQuery method in the pccClient class
ast-grep --lang php --pattern 'class $_ { $$$ public function executeQuery($_) { $$$ } $$$ }'

Length of output: 370



Script:

#!/bin/bash
# Find the implementation of the GraphQLQuery class
rg 'class GraphQLQuery' --files-with-matches

# Find the implementation of the executeQuery method in the pccClient class
rg 'function executeQuery' --files-with-matches

Length of output: 146



Script:

#!/bin/bash
# Display the implementation of the GraphQLQuery class
rg 'class GraphQLQuery' -A 20 src/query/GraphQLQuery.php

# Display the implementation of the executeQuery method in the PccClient class
rg 'function executeQuery' -A 20 src/core/PccClient.php

Length of output: 1106



Script:

#!/bin/bash
# Display the implementation of the build method in the GraphQLQuery class
rg 'function build' -A 20 src/query/GraphQLQuery.php

# Display the complete implementation of the sendRequest method in the PccClient class
rg 'function sendRequest' -A 40 src/core/PccClient.php

Length of output: 1499


41-64: getArticleById method correctly implemented with clear GraphQL query structure. Verify the execution of this query to ensure it retrieves the correct data.

Verification successful

The getArticleById method is correctly implemented, and the GraphQL query execution is properly handled by the executeQuery and sendRequest methods in PccClient.php. The response handling and error management are also appropriately managed.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct execution of GraphQL queries for article retrieval by ID.

# Test: Execute the query with known IDs and compare the results with expected data.
echo "Manually verify the GraphQL query execution by testing with known article IDs."

Length of output: 166



Script:

#!/bin/bash
# Search for the GraphQL client usage in the repository to verify how the query is executed.
# This will help us understand if the `getArticleById` method is correctly implemented.

# Find all PHP files that might contain the GraphQL client usage.
fd -e php

# Search for the GraphQL client instantiation and method calls in the PHP files.
rg 'GraphQLClient' --type php

# Search for the execution of GraphQL queries in the PHP files.
rg 'executeQuery' --type php

Length of output: 684



Script:

#!/bin/bash
# Extract and review the implementation of the `executeQuery` method in `PccClient.php`.

# Search for the `executeQuery` method implementation in `PccClient.php`.
ast-grep --lang php --pattern 'public function executeQuery(QueryInterface $query): mixed { $$$ }' src/core/PccClient.php

Length of output: 230



Script:

#!/bin/bash
# Search for and extract the implementation of the `executeQuery` method in `PccClient.php`.

# Search for the `executeQuery` method definition in `PccClient.php`.
rg 'public function executeQuery' src/core/PccClient.php -A 20

Length of output: 669



Script:

#!/bin/bash
# Extract and review the complete implementation of the `sendRequest` method in `PccClient.php`.

# Search for the complete `sendRequest` method implementation in `PccClient.php`.
rg 'public function sendRequest' src/core/PccClient.php -A 30

Length of output: 872

Comment on lines +57 to +68
*
* @throws \PccPhpSdk\Exception\PccClientException
*/
public function sendRequest(bool|string $body): mixed {
$client = new Client();
$headers = $this->getHeaders();
$request = new Request('POST', $this->getUrl(), $headers, $body);
try {
$response = $client->sendAsync($request)->wait();
} catch (\Exception $e) {
throw new PccClientException($e->getMessage(), $e->getCode(), null, $e);
}
catch (\Exception $e) {
throw new PccClientException($e->getMessage(), $request, NULL, $e);
Copy link

@coderabbitai coderabbitai bot May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception handling in sendRequest method refined to throw PccClientException, allowing for more specific error handling. Consider adding tests to cover these exception scenarios.

Would you like me to help by adding some specific tests for this exception handling?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai not needed now.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonvir249, understood! If you need any further assistance in the future, feel free to reach out. Happy coding!

@purushotamrai purushotamrai merged commit e45cac0 into main May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants