-
-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
General code health improvements #920
base: main
Are you sure you want to change the base?
Conversation
The []= syntax has superior performance compared to the function call.
The class gets auto-casted to string since its a string concatenation. Explicit casting is unnecessary in a non-strict context.
How do we feel about being very explicit with if (!is_object($value)) {
return true;
}
if ($property->type->kind->isDataCollectable()) {
return true; // Transform everything to data objects
}
// ---
$class = new ReflectionClass($className);
if (empty($class->getDocComment())) {
return self::$cache[$className] = null;
}
if (! $this->isIterable($class)) {
return self::$cache[$className] = null;
}
$type = $this->getCollectionReturnType($class);
if ($type === null || $type['valueType'] === null) {
return self::$cache[$className] = null;
}
// ---
if ($property->type->isNullable || $property->type->isOptional) {
return false;
}
if ($property->type->kind->isDataCollectable() && $rules->hasType(Present::class)) {
return false;
}
if ($rules->hasType(BooleanType::class)) {
return false;
}
if ($rules->hasType(Nullable::class)) {
return false;
}
if ($rules->hasType(RequiringRule::class)) {
return false;
} |
new \Spatie\LaravelData\Support\Validation\ValidationRuleFactory()->create("accepted_if:test,false")->__toString(); Original parser output:
Modified parser output:
|
For the failed test, I can either do this: $collection = array_map(
fn ($value) => $this->transformationClosure($nestedContext)($value),
is_array($items) ? $items : $items->all()
); Or I can revert the entire change to a foreach loop. Which one is preferred? Edit: I went with my proposal. |
No description provided.