-
Notifications
You must be signed in to change notification settings - Fork 0
SMAR-26 dependencies improvements #9
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
Conversation
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.
Summary of Changes
Hello @GytisZum, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request focuses on improving the stability and error handling of the smartsupp module by making its interaction with external constants and Smarty template variables more robust. The changes prevent potential runtime errors by gracefully handling cases where expected dependencies or variables might be undefined or missing, leading to a more resilient application.
Highlights
- Enhanced Robustness for Constant Usage: I've added
defined()checks around theself::PRESTASHOP_CLOUDSYNC_CDCconstant insmartsupp.php. This ensures that if the constant is not defined, an empty string is used instead, preventing potential runtime errors and improving the module's resilience. - Safer Smarty Variable Assignment: I've replaced the null coalescing operator (
??) with explicit!== nullchecks when retrieving Smarty template variables (smartsuppVar). This provides a more explicit and robust way to handle cases where the Smarty variable might not be set, ensuring thatarray_merge_recursivealways receives an array. - Conditional Script Rendering in Templates: In
views/templates/admin/cloudsync.tpl, I've wrapped the script tag that loadscloudSyncPathCDCwith a Smarty{if isset($smartsupp.url.cloudSyncPathCDC)}condition. This prevents the rendering of a malformed or empty scriptsrcattribute if thecloudSyncPathCDCvariable is not available in the template context, complementing the PHP changes.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces changes to improve dependency compatibility. However, there are critical issues with the implementation of the defined() checks, which will cause the cloudSyncPathCDC variable to always be an empty string. Additionally, the isset() check in cloudsync.tpl is insufficient and will lead to unnecessary requests. There's also an opportunity to improve maintainability by addressing duplicated code.
| 'cloudSyncPathCDC' => defined('self::PRESTASHOP_CLOUDSYNC_CDC') | ||
| ? self::PRESTASHOP_CLOUDSYNC_CDC | ||
| : '', |
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.
The defined('self::PRESTASHOP_CLOUDSYNC_CDC') check is incorrect and will always evaluate to false. The string 'self::PRESTASHOP_CLOUDSYNC_CDC' is treated as the name of a global constant, which doesn't exist. To check for a class constant, you would need to use defined('Smartsupp::PRESTASHOP_CLOUDSYNC_CDC').
However, since PRESTASHOP_CLOUDSYNC_CDC is a constant defined within this same class, this check is unnecessary. The constant will always be available here.
This change will result in cloudSyncPathCDC always being an empty string, which is a bug. Please revert to the original implementation.
'cloudSyncPathCDC' => self::PRESTASHOP_CLOUDSYNC_CDC| 'cloudSyncPathCDC' => defined('self::PRESTASHOP_CLOUDSYNC_CDC') | ||
| ? self::PRESTASHOP_CLOUDSYNC_CDC | ||
| : '', |
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.
Similar to the previous occurrence, this defined() check is incorrect and will always result in an empty string for cloudSyncPathCDC. The check for the class constant is also redundant as it's defined within this class.
Please revert to using the constant directly.
'cloudSyncPathCDC' => self::PRESTASHOP_CLOUDSYNC_CDC| {if isset($smartsupp.url.cloudSyncPathCDC)} | ||
| <script src="{$smartsupp.url.cloudSyncPathCDC|escape:'htmlall':'UTF-8'}"></script> | ||
| {/if} |
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.
The isset() check is not sufficient here. If cloudSyncPathCDC is set to an empty string (which it will be, due to the issue in smartsupp.php), this condition will be true, and an empty script tag <script src=""></script> will be rendered. This causes the browser to make an unnecessary request to the current page.
To prevent this, you should check for a non-empty string. A simple truthiness check is sufficient and more concise in Smarty.
{if $smartsupp.url.cloudSyncPathCDC}
<script src="{$smartsupp.url.cloudSyncPathCDC|escape:'htmlall':'UTF-8'}"></script>
{/if}
| $smartsuppVar = $this->context->smarty->getTemplateVars('smartsupp'); | ||
| $existing = $smartsuppVar !== null ? $smartsuppVar : []; |
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 description provided.