Skip to content

Latest commit

 

History

History
76 lines (64 loc) · 2.81 KB

File metadata and controls

76 lines (64 loc) · 2.81 KB

Implementation Plan

Architecture

All functions are namespaced free functions (no classes). Each function uses auto-currying: when called without the data (last) argument, it returns a Closure. This enables both direct use and piped use with PHP 8.5's |> operator.

Design Decisions

  • Data-last convention: Subject is always the last parameter
  • Auto-currying via func_num_args(): Each function checks if data was provided
  • Re\find()/Re\findAll(): Renamed from match/matchAll because match is reserved in PHP 8.0+
  • Zero dependencies: Only PHP stdlib functions used internally
  • Namespaced functions: PipeUtils\Str, PipeUtils\Arr, PipeUtils\Type, PipeUtils\Re, PipeUtils\Fn
  • Composer files autoloading: Since these are functions, not classes

Implementation Order

Step 1: Composition helpers (Fn namespace) ✅

  • pipe() — Compose multiple functions
  • tap() — Side effects without breaking chain
  • when() — Conditional branching
  • always() — Constant function
  • identity() — Pass-through

Step 2: String utilities (Str namespace) ✅

  • trim() — Trim whitespace/characters
  • upper() — Uppercase
  • lower() — Lowercase
  • replace() — Substring replacement
  • split() — Split by delimiter
  • contains() — Substring check
  • startsWith() — Prefix check
  • slug() — URL-friendly slug
  • truncate() — Truncate with suffix

Step 3: Array utilities (Arr namespace) ✅

  • map() — Map over elements
  • filter() — Filter elements
  • reduce() — Reduce to single value
  • pluck() — Extract property from each element
  • keyBy() — Key array by property
  • groupBy() — Group by property
  • flatten() — Flatten nested arrays
  • unique() — Unique values
  • sort() — Sort with optional comparator

Step 4: Type coercers (Type namespace) ✅

  • toInt() — Convert to int
  • toFloat() — Convert to float
  • toBool() — Convert to bool
  • toString() — Convert to string
  • toArray() — Convert to array

Step 5: Regex utilities (Re namespace) ✅

  • find() — Match pattern (first match)
  • findAll() — Match all occurrences
  • replace() — Regex replace
  • split() — Split by pattern

Step 6: Tests

  • Unit tests for all Fn functions
  • Unit tests for all Str functions
  • Unit tests for all Arr functions
  • Unit tests for all Type functions
  • Unit tests for all Re functions
  • Integration tests for pipe composition
  • Edge case tests (nulls, empty strings, empty arrays)

Step 7: PHPStan level 9

  • Fix all static analysis issues
  • Add generic type annotations where needed

Step 8: Documentation

  • README.md with examples
  • CI workflow