diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ab1b4c3..4a0559d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,7 +6,6 @@ parameters: paths: - src - config - - database tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true diff --git a/src/Parsers/EnumParser.php b/src/Parsers/EnumParser.php index b889f71..bc9d28a 100644 --- a/src/Parsers/EnumParser.php +++ b/src/Parsers/EnumParser.php @@ -15,7 +15,7 @@ public function __invoke(string $attribute, FluentSchema $schema, array $validat [$rule, $args] = $ruleArgs; if ($rule instanceof EnumRule) { - $enumType = invade($rule)->type; + $enumType = invade($rule)->type; /** @phpstan-ignore property.protected */ $reflection = new ReflectionClass($enumType); diff --git a/src/Parsers/MiscPropertyParser.php b/src/Parsers/MiscPropertyParser.php index 3995b8d..13af21b 100644 --- a/src/Parsers/MiscPropertyParser.php +++ b/src/Parsers/MiscPropertyParser.php @@ -9,7 +9,6 @@ class MiscPropertyParser implements \LaravelRulesToSchema\Contracts\RuleParser { public function __invoke(string $attribute, FluentSchema $schema, array $validationRules, array $nestedRuleset): array|FluentSchema|null { - /** @var JsonSchemaType[] $schemaTypes */ $schemaTypes = $schema->getSchemaDTO()->type; foreach ($validationRules as $ruleArgs) { diff --git a/src/Parsers/TypeParser.php b/src/Parsers/TypeParser.php index 6490399..45ec15f 100644 --- a/src/Parsers/TypeParser.php +++ b/src/Parsers/TypeParser.php @@ -13,7 +13,7 @@ class TypeParser implements RuleParser { public function __invoke(string $attribute, FluentSchema $schema, array $validationRules, array $nestedRuleset): array|FluentSchema|null { - foreach ($validationRules as $ruleArgs) { + foreach($validationRules as $ruleArgs) { [$rule, $args] = $ruleArgs; $ruleName = is_object($rule) ? get_class($rule) : $rule; @@ -54,8 +54,10 @@ public function __invoke(string $attribute, FluentSchema $schema, array $validat protected function parseInRule(FluentSchema $schema, mixed $ruleName, ?array $args): void { + $values = null; + if (is_string($ruleName)) { - $values = array_map(function (mixed $value) { + $values = array_map(function(mixed $value) { if (is_numeric($value)) { if (ctype_digit($value)) { return intval($value); @@ -66,32 +68,32 @@ protected function parseInRule(FluentSchema $schema, mixed $ruleName, ?array $ar return $value; }, $args); - } else { - $values = invade($ruleName)->values; + } elseif ($ruleName instanceof InRule) { + $values = invade($ruleName)->values; /** @phpstan-ignore property.protected */ + } + + if (!$values) { + return; } $isString = true; $isInt = true; $isNumeric = true; - foreach ($values as $value) { + foreach($values as $value) { if (is_string($value)) { - $isString = $isString && true; $isInt = false; $isNumeric = false; } if (is_int($value)) { - $isString = false; - $isInt = $isInt && true; $isNumeric = false; } if (is_float($value)) { - $isString = false; - $isInt = false; - $isNumeric = $isNumeric && true; + $isString = false; + $isInt = false; } } @@ -108,7 +110,7 @@ protected function parseInRule(FluentSchema $schema, mixed $ruleName, ?array $ar protected function parseEnumRule(FluentSchema $schema, EnumRule $rule): void { - $enumType = invade($rule)->type; + $enumType = invade($rule)->type; /** @phpstan-ignore property.protected */ $reflection = new ReflectionClass($enumType); diff --git a/src/ValidationRuleNormalizer.php b/src/ValidationRuleNormalizer.php index b390d2d..11ca062 100644 --- a/src/ValidationRuleNormalizer.php +++ b/src/ValidationRuleNormalizer.php @@ -40,7 +40,7 @@ public function getRules(): array } /** - * @return array> + * @return array> */ protected function normalizeRuleset(array $rules): array {