ecommit/scalar-values
Tiny PHP utility to validate and filter arrays of scalar values. Check whether an array contains only scalars (string/int/float/bool/null), or remove non-scalar items at the root level and return the cleaned array.
is_array()/is_scalar() functions may suffice for most cases, reducing the need for this package unless stricter type enforcement is required.null, resources, or custom objects) may not align with edge cases in Laravel’s type system. Risk: Undetected non-scalar values (e.g., DateTime objects) could slip through if not explicitly excluded.filterScalarValues() may introduce minor CPU overhead due to recursive checks. Mitigation: Benchmark in high-throughput contexts (e.g., bulk API requests).false/true handling).collect() + filter() or validator rules (e.g., array rule with * type) may offer similar functionality without external dependencies.Validator::make()->validate()) or collect() methods cover 90% of use cases? If so, is this package solving a specific pain point (e.g., nested array sanitization)?null, false, true, objects, resources, or custom scalar-like types (e.g., Stringable) handled? Does the package’s definition of "scalar" match Laravel’s expectations?filterScalarValues().collect() pipeline achieve the same result without external code?$filtered = collect($array)->filter(fn ($item) => is_scalar($item))->values()->all();
ScalarValues::containsOnlyScalarValues() in authorize() or rules() to reject non-scalar inputs early.public function handle($request, Closure $next) {
$data = ScalarValues::filterScalarValues($request->all());
$request->merge($data);
return $next($request);
}
getAttributes() or setAttributes() to ensure scalar values before storage.is_scalar() checks for discrepancies.containsOnlyScalarValues().filterScalarValues() in data pipelines to reduce noise in logs/validation errors.containsOnlyScalarValues() in Form Requests or API middleware first to catch malformed inputs early.filterScalarValues() in Eloquent observers, queue jobs, or migration scripts to clean data before storage/processing.null values) to ensure alignment with expectations.composer update.collect()").false or filtered array). Ensure downstream code handles false gracefully.filterScalarValues() (linear scan).collect()->flatten().| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Non-scalar values slip through | Corrupted data storage/processing | Combine with Laravel validation rules. |
| Package breaks in future PHP version | Integration failure | Pin PHP version in composer.json. |
Edge case (e.g., DateTime) misclassified |
False positives/negatives | Add pre-processing (e.g., !is_object($item)). |
| Performance degradation in hot paths | Slow API responses | Profile and optimize or replace with collect(). |
collect() for transformations").// Use ScalarValues for: "Reject arrays with objects/arrays."
// Use collect() for: "Flatten and filter non-scalar values."
How can I help you explore Laravel packages today?