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

[2.x] Refactor NavItem class #1599

Merged
merged 35 commits into from
Mar 1, 2024

Conversation

caendesilva
Copy link
Member

@caendesilva caendesilva commented Feb 29, 2024

Major/breaking changes:

  • Rename dropdown method to forGroup
  • Merge fromRoute method into forRoute
  • The destination value is now always null for parents with children

@caendesilva
Copy link
Member Author

ChatGPT feedback prior to this PR:

The provided PHP class NavItem appears well-structured and follows certain coding standards. However, here are some suggestions for improvement:

  1. Documentation:

    • The class includes comments, which is good. However, consider providing more detailed explanations for some methods, especially complex ones or those with specific use cases.
    • Document the class properties, especially their purpose and expected values.
  2. Type Hinting:

    • The type hinting is well-done with declare(strict_types=1) and type hints for parameters and return values. Make sure to continue this practice in any new methods or modifications.
  3. Use of Static Methods:

    • The class utilizes static methods effectively for creating instances. Consider making the normalizeGroupKey and makeIdentifier methods static as they do not rely on instance-specific data.
  4. Consistency:

    • Ensure consistency in method naming. For instance, some methods use getLink(), while others use getDestination()->getLink(). You might want to standardize this for clarity.
  5. Error Handling:

    • Ensure proper error handling, especially in the constructor when trying to obtain a route. If Routes::get($destination) returns null, there should be a mechanism to handle such cases.
  6. Default Values:

    • Consider using default values for optional parameters in methods instead of setting them to null. This can improve code readability.
  7. Use of Magic Methods:

    • The __toString method is utilized well to resolve a link to the navigation item. Ensure it gracefully handles cases where the destination is null (in case of dropdowns).
  8. Complexity:

    • The getPriority method appears a bit complex. Consider breaking it down into smaller, more understandable methods or adding comments to explain its logic.
  9. Consistent Method Order:

    • Maintain a consistent order of methods within the class. Currently, it starts with the constructor, followed by static methods. Ensure this order is intentional and aligns with readability.
  10. Testing:

    • If not already in place, consider adding unit tests to ensure the correctness of the class functionality, especially for methods with complex logic.
  11. Visibility of Properties:

    • Consider adjusting the visibility of properties based on whether they need to be accessed outside the class. As a best practice, use private visibility and provide getter methods if necessary.
  12. Code Formatting:

    • Ensure consistent code formatting (indentation, spacing) throughout the class.

By addressing these suggestions, the class can be further improved in terms of readability, maintainability, and overall robustness.

Copy link

codecov bot commented Feb 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.95%. Comparing base (5405db0) to head (418db00).

Additional details and impacted files
@@                         Coverage Diff                         @@
##             improved-navigation-internals    #1599      +/-   ##
===================================================================
- Coverage                            99.95%   99.95%   -0.01%     
+ Complexity                            1777     1775       -2     
===================================================================
  Files                                  183      183              
  Lines                                 4803     4801       -2     
===================================================================
- Hits                                  4801     4799       -2     
  Misses                                   2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

We don't need two methods that do almost the same thing. I'm going to merge them, keeping the name of the other one to match the other similar helpers.
@caendesilva caendesilva force-pushed the refactor-navitem-class branch 2 times, most recently from 7fde2d6 to efbe0b1 Compare February 29, 2024 18:50
@caendesilva caendesilva marked this pull request as ready for review March 1, 2024 12:02
@caendesilva caendesilva merged commit 3d4f837 into improved-navigation-internals Mar 1, 2024
7 checks passed
@caendesilva caendesilva deleted the refactor-navitem-class branch March 1, 2024 12:42
@caendesilva caendesilva mentioned this pull request Jun 27, 2024
74 tasks
@caendesilva caendesilva added this to the v2 milestone Jul 9, 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.

1 participant