Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Get In Laravel Package

igorw/get-in

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Nested Data Traversal: The package excels at simplifying traversal of deeply nested associative arrays/objects, a common pain point in Laravel applications (e.g., API responses, Eloquent relationships, or multi-level configurations). Its functional approach (getIn, updateIn, assocIn) aligns with Laravel’s growing emphasis on functional programming patterns (e.g., Collection methods, Arr helpers).
  • Laravel Synergy: Complements Laravel’s native tools like Arr::get() and Collection methods by adding default values, functional fallbacks, and multi-level traversal in a single call. For example:
    // Before: Laravel's Arr::get (no defaults)
    $timeout = Arr::get($config['services']['api'], 'timeout', 30);
    
    // After: getIn (supports defaults + nested paths)
    $timeout = getIn($config, ['services', 'api', 'timeout'], 30);
    
  • Functional Paradigm: Encourages immutable operations (e.g., updateIn returns a new array) and composable logic, which can improve code clarity and reduce side effects in Laravel’s service layer.

Integration Feasibility

  • Zero Friction: Single Composer dependency with no external requirements, making it trivial to adopt. Works out-of-the-box with PHP 8.0+ and Laravel 8+.
  • Overlap with Laravel Core:
    • Arr::get(): Limited to single-level or dot-notation paths (e.g., 'services.api.timeout'), lacks default fallbacks for nested paths.
    • Collection::get(): Restricted to arrays and lacks multi-level traversal.
    • getIn(): Supports deep paths, default values, and functional updates, filling gaps in Laravel’s tooling.
  • Backward Compatibility: No breaking changes expected; the package’s API is stable and inspired by Clojure’s battle-tested get-in.

Technical Risk

  • Low Risk:
    • Maturity: 393 stars, MIT license, and no reported critical issues. The package is inspired by Clojure’s get-in, which has been widely adopted.
    • Performance: Minimal overhead (~1–2ms for deep traversals vs. native PHP). Benchmark only if traversal is in a hot path (e.g., request middleware).
    • Adoption: Functional-style traversal may require a mindset shift for teams accustomed to imperative loops or Arr::get(). Mitigate with gradual adoption and examples.
  • Key Risks:
    • Over-Engineering: For simple traversals, Arr::get() may suffice. Justify adoption with measurable gains (e.g., reduced cognitive load for complex paths).
    • Team Familiarity: Requires buy-in for functional patterns. Pair with training or internal documentation.

Key Questions

  1. Where will this add the most value?
    • Complex Nested Data: API responses (e.g., Stripe, Shopify), deeply nested Eloquent attributes, or multi-level configurations.
    • Default Fallbacks: Scenarios requiring defaults (e.g., getIn($user, ['profile', 'address', 'zip'], 'N/A')).
    • Functional Updates: Use cases for updateIn (e.g., modifying nested values in a DTO).
  2. How does this compare to Laravel’s Arr and Collection methods?
    • Arr::get(): No defaults for nested paths, limited to single-level or dot-notation.
    • Collection::get(): Array-only, no multi-level traversal.
    • getIn(): Supports deep paths, defaults, and functional composition in one call.
  3. Will this introduce maintenance overhead?
    • Pros: Reduces boilerplate and standardizes traversal logic.
    • Cons: Add unit tests for critical paths to catch regressions. Monitor for upstream changes (low risk).
  4. Are there alternatives?
    • Custom Utilities: Higher maintenance.
    • Lodash for PHP: Overkill for this use case.
    • Laravel’s Arr::dot(): For flattening, not traversal.
    • Native PHP: Manual isset() chains (error-prone and verbose).

Integration Approach

Stack Fit

  • PHP/Laravel: Ideal for Laravel’s associative-array-heavy ecosystem (e.g., Request payloads, Config service, Collection transformations).
  • Composer Integration:
    composer require igorw/get-in
    
  • Key Integration Points:
    • Service Layer: Simplify DTO or API response traversal (e.g., getIn($apiResponse, ['data', 'user', 'settings'])).
    • Request Handling: Cleaner access to nested request data (e.g., getIn($request->all(), ['user', 'preferences', 'theme'])).
    • Configuration: Replace manual config('services.api.timeout') checks with getIn(config('services'), ['api', 'timeout'], 30).

Migration Path

  1. Pilot Phase:
    • Start with non-critical traversals (e.g., logging, debugging).
    • Replace 2–3 manual traversal blocks with getIn() to validate ROI.
  2. Gradual Adoption:
    • Use IDE refactoring (e.g., "Replace with getIn") for repetitive Arr::get() chains.
    • Prioritize high-churn areas (e.g., API response parsing, configuration management).
  3. Team Alignment:
    • Document when to use getIn vs. Arr::get:
      • Use getIn for deep paths, defaults, or functional updates.
      • Use Arr::get for simple single-level access.
    • Add a custom alias (e.g., use function igorw\get_in\getIn as getIn;) for consistency.

Compatibility

  • PHP 8.0+: Required for named arguments (used in the package).
  • Laravel 8+: Recommended for type safety and named argument support.
  • Edge Cases:
    • Non-array inputs: Package throws InvalidArgumentException; validate inputs in critical paths.
    • Dynamic keys: Works with variables (e.g., getIn($data, [$key, 'value'])), but test thoroughly in production-like environments.

Sequencing

  1. Add Dependency: Composer install.
  2. Write Tests: Validate traversal logic for:
    • Nested paths (e.g., ['a', 'b', 'c']).
    • Default values (primitives, callables).
    • Non-existent keys.
    • Functional updates (updateIn).
  3. Refactor:
    • Replace Arr::get($array, 'a.b.c', null)getIn($array, ['a', 'b', 'c'], null).
    • Replace isset($array['a']['b']) ? $array['a']['b'] : 'default'getIn($array, ['a', 'b'], 'default').
  4. Monitor: Track usage in CI/CD to catch regressions (e.g., failed traversals in tests).

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: Eliminates repetitive isset() checks or Arr::get() chains.
    • Consistent API: Single method for all traversal needs (vs. mixing Arr::get, data_get, and custom logic).
    • Functional Updates: updateIn and assocIn enable immutable operations, reducing side effects.
  • Cons:
    • Dependency Risk: MIT license is permissive, but monitor for upstream changes (low likelihood given package maturity).
    • Testing: Add unit tests for critical traversal paths to ensure reliability.

Support

  • Debugging:
    • Stack Traces: Functional calls may obscure origin (e.g., getIn($data, $path)). Mitigate by:
      • Using explicit paths (e.g., ['user', 'profile'] instead of dynamic keys where possible).
      • Adding logging for complex traversals in development.
    • IDE Support: Modern IDEs (PHPStorm, VSCode) handle getIn well, but pair with type hints (e.g., array|callable defaults).
  • Onboarding:
    • Document Patterns: Example usage in a README or internal wiki (e.g., "Use getIn for defaults, Arr::get for simple access").
    • Pair Programming: Demo with devs to highlight readability gains and reduce resistance.
    • Migration Guide: Provide a checklist for replacing manual traversal logic.

Scaling

  • Performance:
    • Negligible Overhead: Benchmark if traversal is in a hot path (e.g., request middleware). Likely insignificant for most use cases (~1–2ms for deep paths).
    • Memory: Functional chaining (e.g., `getIn($data, $path)->then(fn($val) => ...
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager