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

[PLA-2080] Check for empty values #112

Merged
merged 1 commit into from
Nov 17, 2024
Merged

Conversation

enjinabner
Copy link
Contributor

@enjinabner enjinabner commented Nov 15, 2024

PR Type

bug_fix


Description

  • Fixed a potential crash in the getProbabilities method by allowing the code parameter to be nullable and adding a check for empty values.
  • Ensured that an empty array is returned when code is empty, preventing further processing and potential errors.

Changes walkthrough 📝

Relevant files
Bug fix
ClaimProbabilities.php
Fix crash by handling empty code in getProbabilities         

src/Support/ClaimProbabilities.php

  • Modified getProbabilities method to accept nullable string.
  • Added a check for empty code to return an empty array.
  • +2/-2     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Cache Handling
    Ensure that the cache handling logic correctly manages null or empty 'code' values, especially in terms of cache key generation and data retrieval.

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add a check for null or non-string values to prevent type errors

    Consider adding a check for null or non-string values for code before using it in
    getCacheKey to prevent potential type errors.

    src/Support/ClaimProbabilities.php [55-57]

    -return empty($code) ? [] : Cache::get(
    +return (is_null($code) || !is_string($code)) ? [] : Cache::get(
         static::getCacheKey($code),
         static::getProbabilitiesFromDB($code)
     );
    Suggestion importance[1-10]: 7

    Why: The suggestion improves robustness by ensuring that the code variable is not null or a non-string before it is used, which is critical given the method now accepts nullable strings. This prevents potential runtime errors and aligns with the change in the method signature to accept nullable types.

    7

    @enjinabner enjinabner merged commit dcd6953 into master Nov 17, 2024
    7 checks passed
    @enjinabner enjinabner deleted the feature/pla-2080/fix-crash branch November 17, 2024 23:57
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Development

    Successfully merging this pull request may close these issues.

    2 participants