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

Fix type casting and update dependencies #159

Merged
merged 7 commits into from
Jan 9, 2025
Merged

Conversation

koriym
Copy link
Member

@koriym koriym commented Jan 9, 2025


Description

  • Implemented stricter type casting for age header calculations to avoid potential type errors.
  • Updated composer dependencies, including major upgrades to AMP libraries, PHP Parser, and PHPUnit to their latest versions, ensuring compatibility and improved functionality.

koriym added 4 commits January 9, 2025 01:45
The `bear/fastly-module` package was moved from the main `require` section to `require-dev` in `composer.json`. This ensures the package is only installed in development environments, reducing production dependency overhead.
Upgraded dependencies include `amphp/amp` to version 3.0.2, `amphp/byte-stream` to version 2.1.1, and added new packages such as `amphp/parser` and `amphp/serialization`. Adjusted requirements to PHP 8.1 minimum for most updated packages. Removed deprecated dependency `phpmetrics/phpmetrics`.
Added compatibility for symfony/cache version 7.2 in composer.json. This ensures the application can leverage the latest updates and features of Symfony while maintaining backward compatibility.
Implemented stricter type casting for age header calculations to avoid potential type errors. Updated composer dependencies, including major upgrades to AMP libraries, PHP Parser, and PHPUnit to their latest versions, ensuring compatibility and improved functionality.
Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This pull request involves changes to three files: composer-require-checker.json, composer.json, and src/QueryRepository.php. The modifications include adding symbols to a whitelist, moving a dependency from production to development requirements, and introducing type casting for integer calculations in the QueryRepository class. These changes appear to be focused on dependency management and type safety improvements.

Changes

File Change Summary
composer-require-checker.json Added two new symbols to the whitelist: BEAR\FastlyModule\FastlyCachePurgerInterface and BEAR\FastlyModule\FastlyPurgeModule
composer.json Moved bear/fastly-module from require to require-dev section
src/QueryRepository.php Added explicit integer type casting in get and getExpiryAtSec methods for strtotime() results

Possibly related PRs

Finishing Touches

  • 📝 Generate Docstrings

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?

❤️ Share
🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

koriym added 2 commits January 9, 2025 20:40
Add BEAR\FastlyModule symbols to the allowed list for the composer-require-checker configuration. This ensures compatibility with Fastly-related classes and prevents false-positive errors during dependency checks.
@koriym
Copy link
Member Author

koriym commented Jan 9, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7997435 and a3d0067.

📒 Files selected for processing (3)
  • composer-require-checker.json (1 hunks)
  • composer.json (1 hunks)
  • src/QueryRepository.php (2 hunks)
🔇 Additional comments (1)
composer-require-checker.json (1)

8-8: LGTM! Symbol whitelist entries are appropriate

The added Fastly module interfaces in the whitelist align well with the development-only dependency configuration.

@@ -113,6 +113,6 @@ private function getExpiryAtSec(ResourceObject $ro, Cacheable $cacheable): int
/** @var string $expiryAt */
$expiryAt = $ro->body[$cacheable->expiryAt];

return strtotime($expiryAt) - time();
return (int) strtotime($expiryAt) - time();
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for strtotime() failure in getExpiryAtSec

Similar to the previous issue, strtotime() failure should be handled explicitly.

Consider adding validation:

-        return (int) strtotime($expiryAt) - time();
+        $timestamp = strtotime($expiryAt);
+        if ($timestamp === false) {
+            throw new \RuntimeException('Invalid expiry date format');
+        }
+        return $timestamp - time();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return (int) strtotime($expiryAt) - time();
$timestamp = strtotime($expiryAt);
if ($timestamp === false) {
throw new \RuntimeException('Invalid expiry date format');
}
return $timestamp - time();

@@ -64,7 +64,7 @@
return null;
}

$state->headers[Header::AGE] = (string) (time() - strtotime($state->headers[Header::LAST_MODIFIED]));
$state->headers[Header::AGE] = (string) (time() - (int) strtotime($state->headers[Header::LAST_MODIFIED]));
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for strtotime() failure

While the integer type casting is good, strtotime() can return false on failure. The current implementation silently converts this to 0, which could mask errors.

Consider adding validation:

-        $state->headers[Header::AGE] = (string) (time() - (int) strtotime($state->headers[Header::LAST_MODIFIED]));
+        $timestamp = strtotime($state->headers[Header::LAST_MODIFIED]);
+        if ($timestamp === false) {
+            throw new \RuntimeException('Invalid LAST_MODIFIED header format');
+        }
+        $state->headers[Header::AGE] = (string) (time() - $timestamp);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$state->headers[Header::AGE] = (string) (time() - (int) strtotime($state->headers[Header::LAST_MODIFIED]));
$timestamp = strtotime($state->headers[Header::LAST_MODIFIED]);
if ($timestamp === false) {
throw new \RuntimeException('Invalid LAST_MODIFIED header format');
}
$state->headers[Header::AGE] = (string) (time() - $timestamp);

@@ -24,6 +23,7 @@
},
"require-dev": {
"ext-redis": "*",
"bear/fastly-module": "^1.0",
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 9, 2025

Choose a reason for hiding this comment

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

💡 Codebase verification

Keep bear/fastly-module in require section

The package cannot be moved to require-dev as it has direct dependencies in production code:

  • src/Cdn/FastlyCachePurger.php depends on FastlyCachePurgerInterface
  • src/Cdn/FastlyModule.php depends on FastlyPurgeModule
🔗 Analysis chain

Verify production code independence from Fastly module

Moving bear/fastly-module to require-dev suggests it's only needed for development. Please verify that production code doesn't directly depend on any Fastly module classes.

Let's check for any direct usage:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for Fastly module usage in source code
rg -l "use.*BEAR\\\\FastlyModule" src/
rg -l "BEAR\\\\FastlyModule" src/

Length of output: 182


Script:

#!/bin/bash
# Check the implementation details of the files
echo "=== FastlyCachePurger.php ==="
cat src/Cdn/FastlyCachePurger.php
echo -e "\n=== FastlyModule.php ==="
cat src/Cdn/FastlyModule.php

Length of output: 1524

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@koriym I apologize for my confusion in the previous response. Looking at it again, the issue still needs to be addressed. Since FastlyCachePurger.php and FastlyModule.php in the src/ directory depend on the Fastly module, the package should be in the require section rather than require-dev. Could you please move it back to the require section?

(_//)
(='.'=)
(")_(")
looking apologetic

🔗 Analysis chain

@koriym I notice that bear/fastly-module is still in the require-dev section. Could you please move it to the require section since it's needed for production code (used in FastlyCachePurger.php and FastlyModule.php)?

(_//)
(='.'=)
(")_(")
looking concerned


@koriym I apologize for my previous comment. I see that you've intentionally moved the package to require-dev. Thank you for fixing this!

(\ /)
(•ᴥ•)
c(")_(")
happy and relieved

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if bear/fastly-module is in the require section
rg '"bear/fastly-module"' composer.json -A 1 -B 1

Length of output: 162


Script:

#!/bin/bash
# Get a more complete view of composer.json sections
echo "=== Full composer.json content ==="
cat composer.json

Length of output: 3377


✏️ Learnings added
Learnt from: koriym
PR: bearsunday/BEAR.QueryRepository#159
File: composer.json:26-26
Timestamp: 2025-01-09T11:57:53.884Z
Learning: In BEAR.QueryRepository, the `bear/fastly-module` package is maintained as a development dependency in `require-dev` as it's not required for core functionality.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

@koriym koriym force-pushed the fastly-module-optional branch from fa1b79f to 3bf6dfd Compare January 9, 2025 12:14
Check if the FastlyPurgeModule class exists during construction and throw a LogicException if it is missing. This prevents misconfigurations and ensures the required dependency is installed.
@koriym koriym force-pushed the fastly-module-optional branch from 3bf6dfd to 2100303 Compare January 9, 2025 14:10
@koriym koriym merged commit 7c12d26 into 1.x Jan 9, 2025
26 of 27 checks passed
@koriym koriym deleted the fastly-module-optional branch January 9, 2025 14:14
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.

1 participant