Skip to content

1.1.0 - Add conditional sift macros and sift_when helper

Choose a tag to compare

@allanmcarvalho allanmcarvalho released this 04 Sep 14:40
· 9 commits to 1.x since this release

Added

  • Conditional “sift” feature for building arrays/iterables from nested data while conditionally excluding values.

    • New internal singleton ArtisanToolbox\Core\Support\SiftMarker used as a sentinel to mark values for exclusion.
    • New utility ArtisanToolbox\Core\Support\Sifter implementing recursive sift behavior:
      • Filters out SiftMarker instances.
      • Recursively transforms supported nested structures (arrays, Collection, LazyCollection, and other traversables).
      • Provides:
        • Sifter::toArray(iterable)
        • Sifter::collection(Collection $collection)
        • Sifter::lazyCollection(LazyCollection $collection)
  • New Laravel macros registered in CoreServiceProvider::boot():

    • Illuminate\Support\Arr::sift() → returns Sifter::toArray($items)
    • Illuminate\Support\Collection::sift() → returns Sifter::collection($this)
    • Illuminate\Support\LazyCollection::sift() → returns Sifter::lazyCollection($this)
  • New global helper: ArtisanToolbox\Core\sift_when(bool $condition, mixed $value): mixed

    • Added via Composer autoloading of src/helpers.php (autoload.files), making the helper available at Composer autoload time.
    • Behavior:
      • sift_when(false, $value) returns SiftMarker::instance() so the value is removed by sift() when iterables are sifted.
      • sift_when(true, $value) returns $value directly.
      • If $value is a Closure, it is executed only when $condition is true.
  • Tests

    • Added tests/Feature/ArrSiftTest.php covering macro registration, inclusion/exclusion via sift_when, closure short-circuiting, recursive marker discarding across nested supported iterables (including generators), key preservation, and non-mutating/lazy behavior.

Changed

  • PHPStan configuration workflow

    • Updated phpstan.neon.dist to add parameters.configDirectories pointing at config.
    • This allows PHPStan to load additional configuration fragments from config (while keeping the existing paths configuration).
    • Impact: analysis/merging can change if new PHPStan config fragments exist under config.
    • No runtime behavior changes—this is static analysis configuration only.
  • Version constant

    • Bumped Core::VERSION from 1.0.0 to 1.1.0.
  • Documentation / developer workflow

    • Updated README.md and CHANGELOG.md with usage examples for combining Arr::sift() / Collection->sift() / LazyCollection->sift() with sift_when().
    • Updated the core development skills guide (resources/boost/.../SKILL.md) with a step describing conditional array building and key/type preservation.
  • Git ignore updates

    • .gitignore now ignores config/maintainer.php and config/maintainer_secrets.php, which may affect developer workflows that expect those files to be committed.

Compatibility / Migration Notes

  • Potential macro collisions: If other packages define sift macros on Arr, Collection, or LazyCollection, Laravel macro behavior may cause overwrites/overlaps depending on registration order.
  • Composer autoload side effects: Adding src/helpers.php to autoload.files means the helper file is loaded automatically at Composer autoload time; ensure it’s safe for your environment.
  • PHPStan behavior changes: If you add PHPStan fragment files under config, they may alter analysis results due to the new configDirectories setting.
  • Core::VERSION checks: Consumers inspecting the Core::VERSION string will now observe 1.1.0.