Skip to content

Commit

Permalink
Use arg names from rule constants in definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Jan 1, 2025
1 parent e9631c9 commit e014ee2
Show file tree
Hide file tree
Showing 28 changed files with 36 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Rules/ArrayEnumRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
final class ArrayEnumRule implements Rule
{

private const
public const
Cases = 'cases',
UseKeys = 'useKeys',
AllowUnknown = 'allowUnknown';
Expand Down
6 changes: 3 additions & 3 deletions src/Rules/ArrayEnumValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public function getType(): string
public function getArgs(): array
{
return [
'cases' => $this->cases,
'useKeys' => $this->useKeys,
'allowUnknown' => $this->allowUnknown,
ArrayEnumRule::Cases => $this->cases,
ArrayEnumRule::UseKeys => $this->useKeys,
ArrayEnumRule::AllowUnknown => $this->allowUnknown,
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/ArrayOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getType(): string
public function getArgs(): array
{
$args = parent::getArgs();
$args['key'] = $this->key;
$args[ArrayOfRule::KeyRule] = $this->key;

return $args;
}
Expand Down
1 change: 0 additions & 1 deletion src/Rules/ArrayOfRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
final class ArrayOfRule extends MultiValueRule
{

/** @internal */
public const KeyRule = 'key';

public function resolveArgs(array $args, ArgsFieldContext $context): ArrayOfArgs
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/ArrayShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getType(): string
public function getArgs(): array
{
return [
'fields' => $this->fields,
ArrayShapeRule::Fields => $this->fields,
];
}

Expand Down
1 change: 0 additions & 1 deletion src/Rules/ArrayShapeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
final class ArrayShapeRule implements Rule
{

/** @internal */
public const Fields = 'fields';

public function resolveArgs(array $args, ArgsFieldContext $context): ArrayShapeArgs
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/BackedEnumRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
final class BackedEnumRule implements Rule
{

private const
public const
ClassName = 'class',
AllowUnknown = 'allowUnknown';

Expand Down
4 changes: 2 additions & 2 deletions src/Rules/BackedEnumValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function getType(): string
public function getArgs(): array
{
return [
'class' => $this->class,
'allowUnknown' => $this->allowUnknown,
BackedEnumRule::ClassName => $this->class,
BackedEnumRule::AllowUnknown => $this->allowUnknown,
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/BoolRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
final class BoolRule implements Rule
{

private const CastBoolLike = 'castBoolLike';
public const CastBoolLike = 'castBoolLike';

private const CastMap = [
'true' => true,
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/BoolValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getType(): string
public function getArgs(): array
{
return [
'castBoolLike' => $this->castBoolLike,
BoolRule::CastBoolLike => $this->castBoolLike,
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/CompoundDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private function definitionsToRules(array $definitions): array
public function getArgs(): array
{
return [
'rules' => $this->rules,
CompoundRule::Rules => $this->rules,
];
}

Expand Down
1 change: 0 additions & 1 deletion src/Rules/CompoundRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
abstract class CompoundRule implements Rule
{

/** @internal */
public const Rules = 'rules';

public function resolveArgs(array $args, ArgsFieldContext $context): CompoundArgs
Expand Down
1 change: 0 additions & 1 deletion src/Rules/DateTimeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
final class DateTimeRule implements Rule
{

/** @internal */
public const
Format = 'format',
ClassName = 'class';
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/DateTimeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function getType(): string
public function getArgs(): array
{
return [
'class' => $this->class,
'format' => $this->format,
DateTimeRule::ClassName => $this->class,
DateTimeRule::Format => $this->format,
];
}

Expand Down
1 change: 0 additions & 1 deletion src/Rules/FloatRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
final class FloatRule implements Rule
{

/** @internal */
public const
Min = 'min',
Max = 'max',
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/FloatValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public function getType(): string
public function getArgs(): array
{
return [
'min' => $this->min,
'max' => $this->max,
'unsigned' => $this->unsigned,
'castNumericString' => $this->castNumericString,
FloatRule::Min => $this->min,
FloatRule::Max => $this->max,
FloatRule::Unsigned => $this->unsigned,
FloatRule::CastNumericString => $this->castNumericString,
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/InstanceOfRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
final class InstanceOfRule implements Rule
{

private const Type = 'type';
public const Type = 'type';

public function resolveArgs(array $args, ArgsFieldContext $context): InstanceOfArgs
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/InstanceOfValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getType(): string
public function getArgs(): array
{
return [
'type' => $this->type,
InstanceOfRule::Type => $this->type,
];
}

Expand Down
1 change: 0 additions & 1 deletion src/Rules/IntRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
final class IntRule implements Rule
{

/** @internal */
public const
Min = 'min',
Max = 'max',
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/IntValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public function getType(): string
public function getArgs(): array
{
return [
'min' => $this->min,
'max' => $this->max,
'unsigned' => $this->unsigned,
'castNumericString' => $this->castNumericString,
IntRule::Min => $this->min,
IntRule::Max => $this->max,
IntRule::Unsigned => $this->unsigned,
IntRule::CastNumericString => $this->castNumericString,
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/MappedObjectRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
final class MappedObjectRule implements Rule
{

private const ClassName = 'class';
public const ClassName = 'class';

/** @var array<string, null> */
private array $alreadyResolved = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/MappedObjectValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getType(): string
public function getArgs(): array
{
return [
'class' => $this->class,
MappedObjectRule::ClassName => $this->class,
];
}

Expand Down
8 changes: 4 additions & 4 deletions src/Rules/MultiValueDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public function __construct(
public function getArgs(): array
{
return [
'item' => $this->item,
'minItems' => $this->minItems,
'maxItems' => $this->maxItems,
'mergeDefaults' => $this->mergeDefaults,
MultiValueRule::ItemRule => $this->item,
MultiValueRule::MinItems => $this->minItems,
MultiValueRule::MaxItems => $this->maxItems,
MultiValueRule::MergeDefaults => $this->mergeDefaults,
];
}

Expand Down
1 change: 0 additions & 1 deletion src/Rules/MultiValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
abstract class MultiValueRule implements Rule
{

/** @internal */
public const
ItemRule = 'item',
MinItems = 'minItems',
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/NullRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
final class NullRule implements Rule
{

private const CastEmptyString = 'castEmptyString';
public const CastEmptyString = 'castEmptyString';

public function resolveArgs(array $args, ArgsFieldContext $context): NullArgs
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/NullValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getType(): string
public function getArgs(): array
{
return [
'castEmptyString' => $this->castEmptyString,
NullRule::CastEmptyString => $this->castEmptyString,
];
}

Expand Down
1 change: 0 additions & 1 deletion src/Rules/StringRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
final class StringRule implements Rule
{

/** @internal */
public const
Pattern = 'pattern',
MinLength = 'minLength',
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/StringValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public function getType(): string
public function getArgs(): array
{
return [
'pattern' => $this->pattern,
'minLength' => $this->minLength,
'maxLength' => $this->maxLength,
'notEmpty' => $this->notEmpty,
StringRule::Pattern => $this->pattern,
StringRule::MinLength => $this->minLength,
StringRule::MaxLength => $this->maxLength,
StringRule::NotEmpty => $this->notEmpty,
];
}

Expand Down

0 comments on commit e014ee2

Please sign in to comment.