Skip to content

Commit

Permalink
Update pint.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Riley Aven committed Aug 29, 2024
1 parent 4b2d305 commit 4835b0b
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 75 deletions.
14 changes: 14 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"preset": "laravel",
"exclude": [
"stubs"
],
"rules": {
"binary_operator_spaces": {
"operators": {
"=": "align_single_space",
"=>": "align_single_space"
}
}
}
}
2 changes: 1 addition & 1 deletion src/Parsers/ConfirmedParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __invoke(string $attribute, FluentSchema $schema, array $validat

if ($rule === 'confirmed') {
return [
$attribute => $schema,
$attribute => $schema,
"{$attribute}_confirmed" => clone $schema,
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/FormatParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __invoke(string $attribute, FluentSchema $schema, array $validat
// 'iri' => $schema->format()->iri(),
// 'uri-reference' => $schema->format()->uriReference(),
// 'uri' => $schema->format()->uri(),
'url' => $schema->format()->uri(),
'url' => $schema->format()->uri(),
'ipv4' => $schema->format()->ipv4(),
'ipv6' => $schema->format()->ipv6(),
// 'hostname' => $schema->format()->hostname(),
Expand Down
16 changes: 8 additions & 8 deletions src/Parsers/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,27 @@ protected function parseInRule(FluentSchema $schema, mixed $ruleName, ?array $ar
$values = invade($ruleName)->values;
}

$isString = true;
$isInt = true;
$isString = true;
$isInt = true;
$isNumeric = true;

foreach ($values as $value) {
if (is_string($value)) {
$isString = $isString && true;
$isInt = false;
$isString = $isString && true;
$isInt = false;
$isNumeric = false;
}

if (is_int($value)) {

$isString = false;
$isInt = $isInt && true;
$isString = false;
$isInt = $isInt && true;
$isNumeric = false;
}

if (is_float($value)) {
$isString = false;
$isInt = false;
$isString = false;
$isInt = false;
$isNumeric = $isNumeric && true;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/ValidationRuleNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function normalizeRuleset(array $rules): array

foreach ($rules as $rule) {
if (is_string($rule)) {
$result = $this->parseStringRuleArgs($rule);
$result = $this->parseStringRuleArgs($rule);
$normalized[] = $result;
} else {
$normalized[] = [$rule, null];
Expand All @@ -61,8 +61,8 @@ protected function normalizeRuleset(array $rules): array
protected function splitStringToRuleset(string $rules): array
{
$instance = new ValidationRuleParser([]);
$class = new ReflectionClass($instance);
$method = $class->getMethod('explodeExplicitRule');
$class = new ReflectionClass($instance);
$method = $class->getMethod('explodeExplicitRule');
$method->setAccessible(true);

return $method->invokeArgs($instance, [$rules, null]);
Expand All @@ -71,8 +71,8 @@ protected function splitStringToRuleset(string $rules): array
protected function parseStringRuleArgs(string $rule): array
{
$instance = new ValidationRuleParser([]);
$class = new ReflectionClass($instance);
$method = $class->getMethod('parseParameters');
$class = new ReflectionClass($instance);
$method = $class->getMethod('parseParameters');
$method->setAccessible(true);

$parameters = [];
Expand Down
18 changes: 9 additions & 9 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
Config::set('rules-to-schema.rule_type_map.exclude', ['custom_exclude_rule']);

$rules = [
'string' => ['custom_string_rule'],
'string' => ['custom_string_rule'],
'string_class' => [new CustomRule],
'integer' => ['custom_integer_rule'],
'number' => ['custom_number_rule'],
'boolean' => ['custom_boolean_rule'],
'array' => ['custom_array_rule'],
'nullable' => ['custom_nullable_rule'],
'exclude' => ['custom_exclude_rule'],
'integer' => ['custom_integer_rule'],
'number' => ['custom_number_rule'],
'boolean' => ['custom_boolean_rule'],
'array' => ['custom_array_rule'],
'nullable' => ['custom_nullable_rule'],
'exclude' => ['custom_exclude_rule'],
];

expect(LaravelRulesToSchema::parse($rules)->compile())
Expand All @@ -31,12 +31,12 @@

test('custom rule can have custom schema', function () {
Config::set('rules-to-schema.custom_rule_schemas', [
CustomRule::class => CustomRuleSchemaDefinition::class,
CustomRule::class => CustomRuleSchemaDefinition::class,
'custom_registered_rule' => CustomRuleSchemaDefinition::class,
]);

$rules = [
'custom_with_schema' => [new CustomRule],
'custom_with_schema' => [new CustomRule],
'custom_registered_rule' => ['custom_registered_rule'],
];

Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/TestIntBackedEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

enum TestIntBackedEnum: int
{
case One = 1;
case Two = 2;
case One = 1;
case Two = 2;
case Three = 3;
}
4 changes: 2 additions & 2 deletions tests/Fixtures/TestStringBackedEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

enum TestStringBackedEnum: string
{
case One = 'one';
case Two = 'two';
case One = 'one';
case Two = 'two';
case Three = 'three';
}
94 changes: 47 additions & 47 deletions tests/ParsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@

test('string types', function () {
$rules = [
'string_property' => ['string'],
'password_property' => ['password'],
'date_property' => ['date'],
'alpha_property' => ['alpha'],
'alpha_dash_property' => ['alpha_dash'],
'alpha_num_property' => ['alpha_num'],
'enum_property' => [new Enum(TestStringBackedEnum::class)],
'ip_property' => ['ip'],
'ipv4_property' => ['ipv4'],
'ipv6_property' => ['ipv6'],
'string_property' => ['string'],
'password_property' => ['password'],
'date_property' => ['date'],
'alpha_property' => ['alpha'],
'alpha_dash_property' => ['alpha_dash'],
'alpha_num_property' => ['alpha_num'],
'enum_property' => [new Enum(TestStringBackedEnum::class)],
'ip_property' => ['ip'],
'ipv4_property' => ['ipv4'],
'ipv6_property' => ['ipv6'],
'mac_address_property' => ['mac_address'],
'json_property' => ['json'],
'url_property' => ['url'],
'uuid_property' => ['uuid'],
'ulid_property' => ['ulid'],
'json_property' => ['json'],
'url_property' => ['url'],
'uuid_property' => ['uuid'],
'ulid_property' => ['ulid'],
];

expect(LaravelRulesToSchema::parse($rules)->compile())
Expand All @@ -43,8 +43,8 @@
test('integer types', function () {
$rules = [
'integer_property' => ['integer'],
'int_property' => ['int'],
'enum_property' => [new Enum(TestIntBackedEnum::class)],
'int_property' => ['int'],
'enum_property' => [new Enum(TestIntBackedEnum::class)],
];

expect(LaravelRulesToSchema::parse($rules)->compile())
Expand All @@ -63,7 +63,7 @@
test('boolean types', function () {
$rules = [
'boolean_property' => ['boolean'],
'bool_property' => ['bool'],
'bool_property' => ['bool'],
];

expect(LaravelRulesToSchema::parse($rules)->compile())
Expand All @@ -81,10 +81,10 @@

test('nullable objects and arrays', function () {
$rules = [
'nullable_object' => ['nullable'],
'nullable_object' => ['nullable'],
'nullable_object.myProperty' => ['string'],
'nullable_array' => ['nullable', 'array'],
'nullable_array.*' => ['string'],
'nullable_array' => ['nullable', 'array'],
'nullable_array.*' => ['string'],
];

expect(LaravelRulesToSchema::parse($rules)->compile())
Expand Down Expand Up @@ -121,10 +121,10 @@

test('nested arrays', function () {
$rules = [
'array' => ['array', 'one'],
'array.*' => ['array', 'two'],
'array.*.one' => ['array', 'three'],
'array.*.one.*' => ['string'],
'array' => ['array', 'one'],
'array.*' => ['array', 'two'],
'array.*.one' => ['array', 'three'],
'array.*.one.*' => ['string'],
'array.*.two.*.property1' => ['string'],
'array.*.two.*.property2' => ['string'],
];
Expand All @@ -136,9 +136,9 @@
test('excluded attributes are not displayed', function () {
$rules = [
'prohibited_property' => ['prohibited'],
'missing_property' => ['missing'],
'exclude_property' => ['exclude'],
'other_property' => ['string'],
'missing_property' => ['missing'],
'exclude_property' => ['exclude'],
'other_property' => ['string'],
];

// TODO: These can be prohibited in the schema using not
Expand All @@ -157,9 +157,9 @@

test('can infer type from in rule', function () {
$rules = [
'in_rule' => [Rule::in([1, 2, 3])],
'in_rule' => [Rule::in([1, 2, 3])],
'in_rule_str' => ['in:a,b,c'],
'in_mixed' => ['in:1,b,c'],
'in_mixed' => ['in:1,b,c'],
];

expect(LaravelRulesToSchema::parse($rules)->compile())
Expand All @@ -168,14 +168,14 @@

test('can infer type from exists rule', function () {
$rules = [
'exists_property' => [Rule::exists(TestModel::class)],
'exists_property' => [Rule::exists(TestModel::class)],
'exists_str_property' => ['exists:test_models,name'],
];
})->skip('Need to parse migration/schema doc');

test('required', function () {
$rules = [
'required_property' => ['required'],
'required_property' => ['required'],
'sometimes_required' => ['sometimes', 'required'],
];

Expand All @@ -185,18 +185,18 @@

test('format', function () {
$rules = [
'regex' => ['regex'],
'not_regex' => ['not_regex'],
'uuid' => ['uuid'],
'url' => ['url'],
'ipv4' => ['ipv4'],
'ipv6' => ['ipv6'],
'email' => ['email'],
'date' => ['date'],
'regex' => ['regex'],
'not_regex' => ['not_regex'],
'uuid' => ['uuid'],
'url' => ['url'],
'ipv4' => ['ipv4'],
'ipv6' => ['ipv6'],
'email' => ['email'],
'date' => ['date'],
'date_format' => ['date_format'],
'date_equals' => ['date_equals'],
'mimetypes' => ['mimetypes:application/json,image/png'],
'mimes' => ['mimes:png,jpg'],
'mimetypes' => ['mimetypes:application/json,image/png'],
'mimes' => ['mimes:png,jpg'],
];

expect(LaravelRulesToSchema::parse($rules)->compile())
Expand All @@ -205,10 +205,10 @@

test('rules apply other attributes', function () {
$rules = [
'str_min' => ['string', 'min:1'],
'str_max' => ['string', 'max:10'],
'int_min' => ['int', 'min:1'],
'int_max' => ['int', 'max:10'],
'str_min' => ['string', 'min:1'],
'str_max' => ['string', 'max:10'],
'int_min' => ['int', 'min:1'],
'int_max' => ['int', 'max:10'],
'float_min' => ['decimal', 'min:1'],
'float_max' => ['decimal', 'max:10'],
'array_min' => ['array', 'min:1'],
Expand All @@ -223,9 +223,9 @@

test('enum', function () {
$rules = [
'enum' => [new Enum(TestEnum::class)],
'enum' => [new Enum(TestEnum::class)],
'string_enum' => [new Enum(TestStringBackedEnum::class)],
'int_enum' => [new Enum(TestIntBackedEnum::class)],
'int_enum' => [new Enum(TestIntBackedEnum::class)],
];

expect(LaravelRulesToSchema::parse($rules)->compile())
Expand Down

0 comments on commit 4835b0b

Please sign in to comment.