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-2023] Refactor constant #279

Merged
merged 5 commits into from
Oct 25, 2024
Merged

Conversation

enjinabner
Copy link
Contributor

@enjinabner enjinabner commented Oct 22, 2024

PR Type

enhancement, tests


Description

  • Introduced a constant URL_ENCODED_KEY in Laravel\Attribute to replace the hardcoded hex key.
  • Updated SyncMetadata command to use the new constant instead of a hardcoded value.
  • Modified model events in Attribute to utilize the constant for better maintainability.
  • Updated test cases in GetTokenTest to use the constant, ensuring consistency across the codebase.

Changes walkthrough 📝

Relevant files
Enhancement
SyncMetadata.php
Use constant for URL encoded key in SyncMetadata                 

src/Commands/SyncMetadata.php

  • Added import for LaravelAttribute.
  • Replaced hardcoded hex key with LaravelAttribute::URL_ENCODED_KEY.
  • +2/-1     
    Attribute.php
    Introduce constant for URL encoded key in Attribute           

    src/Models/Laravel/Attribute.php

  • Introduced constant URL_ENCODED_KEY.
  • Replaced hardcoded hex key with the new constant in model events.
  • +3/-2     
    Tests
    GetTokenTest.php
    Update tests to use constant for URL encoded key                 

    tests/Feature/GraphQL/Queries/GetTokenTest.php

  • Added import for LaravelAttribute.
  • Replaced hardcoded hex key with LaravelAttribute::URL_ENCODED_KEY in
    tests.
  • +3/-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 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ No major issues detected

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use strict comparison for type safety in model event hooks

    Verify that the equality check against static::URL_ENCODED_KEY in the model's event
    hooks uses a strict comparison (===) to ensure type safety.

    src/Models/Laravel/Attribute.php [48-49]

    -if ($model->key == static::URL_ENCODED_KEY) {
    +if ($model->key === static::URL_ENCODED_KEY) {
         SyncMetadata::dispatch($model->id);
     }
    Suggestion importance[1-10]: 8

    Why: The suggestion to use strict comparison (===) enhances type safety, which is a best practice in PHP to prevent unexpected type coercion, thereby improving code robustness.

    8

    src/Models/Laravel/Attribute.php Outdated Show resolved Hide resolved
    @enjinabner enjinabner merged commit 8a6638a into master Oct 25, 2024
    7 checks passed
    @enjinabner enjinabner deleted the feature/pla-2023/refactor-constant branch October 25, 2024 00:49
    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.

    3 participants