array validation max item length rename

This commit is contained in:
Yuri Kuznetsov
2023-02-28 10:37:06 +02:00
parent 3392c843e6
commit ed867d1b95
4 changed files with 14 additions and 16 deletions
+5
View File
@@ -6,6 +6,11 @@
<option name="KEEP_RPAREN_AND_LBRACE_ON_ONE_LINE" value="true" /> <option name="KEEP_RPAREN_AND_LBRACE_ON_ONE_LINE" value="true" />
<option name="FORCE_EMPTY_METHODS_IN_ONE_LINE" value="true" /> <option name="FORCE_EMPTY_METHODS_IN_ONE_LINE" value="true" />
</PHPCodeStyleSettings> </PHPCodeStyleSettings>
<codeStyleSettings language="JSON">
<indentOptions>
<option name="INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="PHP"> <codeStyleSettings language="PHP">
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" /> <option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" /> <option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
@@ -38,17 +38,10 @@ use stdClass;
class ArrayType class ArrayType
{ {
private Metadata $metadata; private const DEFAULT_MAX_ITEM_LENGTH = 100;
private Defs $defs; public function __construct(private Metadata $metadata, private Defs $defs)
{}
private const DEFAULT_MAX_LENGTH = 100;
public function __construct(Metadata $metadata, Defs $defs)
{
$this->metadata = $metadata;
$this->defs = $defs;
}
public function checkRequired(Entity $entity, string $field): bool public function checkRequired(Entity $entity, string $field): bool
{ {
@@ -181,9 +174,9 @@ class ArrayType
return false; return false;
} }
public function checkMaxLength(Entity $entity, string $field, ?int $validationValue): bool public function checkMaxItemLength(Entity $entity, string $field, ?int $validationValue): bool
{ {
$maxLength = $validationValue ?? self::DEFAULT_MAX_LENGTH; $maxLength = $validationValue ?? self::DEFAULT_MAX_ITEM_LENGTH;
/** @var string[] $value */ /** @var string[] $value */
$value = $entity->get($field) ?? []; $value = $entity->get($field) ?? [];
@@ -63,7 +63,7 @@
"valid", "valid",
"required", "required",
"maxCount", "maxCount",
"maxLength", "maxItemLength",
"pattern", "pattern",
"noEmptyString" "noEmptyString"
], ],
@@ -71,7 +71,7 @@
"array", "array",
"arrayOfString", "arrayOfString",
"valid", "valid",
"maxLength" "maxItemLength"
], ],
"filter": true, "filter": true,
"notCreatable": false, "notCreatable": false,
@@ -70,7 +70,7 @@
"valid", "valid",
"required", "required",
"maxCount", "maxCount",
"maxLength", "maxItemLength",
"pattern", "pattern",
"noEmptyString" "noEmptyString"
], ],
@@ -78,7 +78,7 @@
"array", "array",
"arrayOfString", "arrayOfString",
"valid", "valid",
"maxLength", "maxItemLength",
"noEmptyString" "noEmptyString"
], ],
"filter": true, "filter": true,