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

Arraypath Laravel Package

mathiasgrimm/arraypath

Convenient array manipulation for PHP, especially multidimensional arrays. Safely get, set, check existence, add or remove values using simple “a/b/c” paths, avoiding undefined index notices. Optional class alias (A) for cleaner calls and IDE autocomplete.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Simplifies nested array operations: Replaces verbose isset()/array_key_exists() chains with a fluent, path-based API (A::get(), A::set(), etc.), improving readability and maintainability.
    • Consistent API design: Enforces a predictable parameter order ($arrayData, $index, $value, $default), reducing cognitive overhead for developers.
    • Laravel-aligned: Works seamlessly with Laravel’s service container, PHP 5.3+ (Laravel’s minimum), and integrates with Laravel’s data_get()/data_set()-like workflows.
    • IDE-friendly: Class alias (A) enables autocompletion and static analysis (e.g., PHPStorm, Psalm), accelerating development.
    • Lightweight: Minimal abstraction overhead; ideal for utility-focused use cases like config parsing, form requests, or API response handling.
  • Cons:

    • Archived status: Last release in 2016 raises concerns about:
      • PHP 8+ compatibility: Potential issues with strict typing, JIT, or null handling.
      • Security patches: No active maintenance for dependency vulnerabilities (e.g., PHPUnit 4.x).
      • Feature stagnation: No updates for modern PHP/Laravel features (e.g., attributes, enums).
    • Limited scope: Lacks advanced features like:
      • Recursive array traversal (e.g., filtering/mapping).
      • Dynamic path generation (e.g., user.*.address).
      • Laravel-specific integrations (e.g., Eloquent, Collections).
    • No type safety: Returns null for missing keys (unlike Laravel’s data_get() with null defaults).

Integration Feasibility

  • High for:
    • Deeply nested arrays: Ideal for parsing multi-level JSON (e.g., Stripe API responses), configs, or form data.
    • Legacy codebases: Refactoring isset() spaghetti into A::exists()/A::get() calls.
    • Consistent path access: Enforcing a single syntax (e.g., A::get($data, 'user/profile/name')) across teams.
  • Low for:
    • Flat/shallow arrays: Overkill for simple key-value stores.
    • Real-time data: Not optimized for high-frequency operations (e.g., WebSocket payloads).
    • Complex transformations: Lack of methods for recursive operations (e.g., array_walk_recursive).

Technical Risk

  • Deprecation:
    • PHP 8+: Test edge cases like:
      • Mixed arrays with null values.
      • Strict typing collisions (e.g., A::set() with non-array inputs).
      • JIT optimizations (unlikely but possible).
    • Laravel 9+: May conflict with newer PHP features (e.g., union types).
  • Performance:
    • Negligible overhead: Benchmarks show minimal impact vs. native isset() (microseconds per operation).
    • Memory: No significant increase for typical use cases.
  • Alternatives:
    • Laravel-native: data_get()/data_set() (Laravel 5.5+) or Arr:: helpers (Laravel 5.x) for basic cases.
    • Modern PHP: Use array_key_first() (PHP 7.3+), null coalescing (??), or Spatie’s array-to-object for OOP approaches.
    • Custom solution: Roll your own helper if needing custom separators or advanced features.

Key Questions

  1. PHP/Laravel Compatibility:
    • "Does this package work with PHP 8.1+ and Laravel 9.x? If not, what’s the effort to backport fixes?"
    • Test cases: Mixed arrays, null values, and strict typing scenarios.
  2. Feature Gaps:
    • "Do we need A::remove() or custom separators that Laravel’s Arr helpers lack?"
    • If yes, evaluate fork/maintenance effort vs. custom implementation.
  3. Adoption Barriers:
    • "Will teams prefer A::get() over data_get()? How will we enforce consistency?"
    • Propose IDE plugins or static analysis rules (e.g., PHPStan) to mandate usage.
  4. Maintenance Plan:
    • "If adopting, will we fork and update this package, or accept its archived state?"
    • Assign a tech lead to monitor PHP/Laravel compatibility.
  5. Edge Cases:
    • "How does it handle non-string keys (e.g., A::get($data, [0, 'name'])) or circular references?"
    • Document limitations in internal style guides.

Integration Approach

Stack Fit

  • PHP/Laravel: Fully compatible with Laravel’s ecosystem:
    • PHP 5.3+: Meets Laravel’s minimum requirement.
    • Composer: Install via composer require mathiasgrimm/arraypath:^2.0.
    • Service Container: Register the class alias in a Laravel service provider.
  • IDE/Tooling:
    • Supports PSR-4 autoloading and IDE autocompletion (e.g., PHPStorm, VSCode).
    • Class alias (A) enables static analysis (e.g., Psalm, PHPStan).
  • Alternatives:
    • Laravel Collections: Does not natively support Collection instances; cast to array first:
      A::get((array) $request->input(), 'user.name');
      

Migration Path

  1. Pilot Phase (1–2 weeks):

    • Scope: Target a single module with heavy array manipulation (e.g., API response parsing or form validation).
    • Action:
      • Replace one repetitive isset() chain with A::get().
      • Example:
        // Before
        $name = $request->input('user.profile.name', null);
        if ($name === null) {
            return response()->json(['error' => 'Missing name'], 400);
        }
        
        // After
        $name = A::get($request->all(), 'user.profile.name');
        if ($name === null) {
            return response()->json(['error' => 'Missing name'], 400);
        }
        
    • Metrics: Measure code size reduction, readability (via code review), and performance (microbenchmark).
  2. Gradual Rollout (4–6 weeks):

    • Phases:
      • Phase 1: Controllers and Requests (e.g., form data extraction).
      • Phase 2: Services (e.g., config readers, API clients).
      • Phase 3: Legacy codebases (prioritize high-maintenance modules).
    • Tools:
      • Use regex search/replace for nested isset() patterns:
        if\s*\(\s*isset\s*\(\s*\$data\[[^\]]*\]\s*\)\s*\)\s*\{.*?\}
        
      • Replace with A::exists() or A::get().
    • Example Refactor:
      // Before
      if (isset($config['app']['debug']) && $config['app']['debug'] === true) {
          $debug = true;
      } else {
          $debug = false;
      }
      
      // After
      $debug = A::get($config, 'app.debug', false);
      
  3. Alias Registration:

    • Register the class alias in AppServiceProvider::boot():
      public function boot()
      {
          ArrayPath::registerClassAlias('A');
          // Or custom alias: ArrayPath::registerClassAlias('App');
      }
      
    • Ensure the alias is loaded before first use (e.g., via Laravel’s service container).
  4. Testing:

    • Update unit tests to reflect new API calls.
    • Add integration tests for edge cases (e.g., missing paths, custom separators).
    • Example test:
      public function testArrayPathGet()
      {
          $data = ['user' => ['name' => 'John']];
          $this->assertEquals('John', A::get($data, 'user.name'));
          $this->assertNull(A::get($data, 'user.age'));
          $this->assertEquals('default', A::get($data, 'user.age', 'default'));
      }
      

Compatibility

Feature Compatibility Notes
PHP 5.3–7.4 Fully supported (tested in package).
PHP 8.0+ Unverified: May require backports for strict typing or JIT.
Laravel 5.x–8.x Works with all versions (no framework dependencies).
Custom Separators Supported (e.g., A::setSeparator('.')), but enforce consistency across codebase.
Non-String Keys Limited: Paths like `A::get($data, [0, 'name']
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor