Skip to content

Commit

Permalink
Merge pull request #523 from BadJacky/bugfix/update-attribute-target-…
Browse files Browse the repository at this point in the history
…property-parameter

enhance: Add TARGET_PARAMETER to Attribute for improved Validation
  • Loading branch information
rubenvanassche authored Aug 4, 2023
2 parents 731a0b1 + e4990c3 commit 41b9d45
Show file tree
Hide file tree
Showing 80 changed files with 138 additions and 125 deletions.
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Accepted.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Accepted extends StringValidationAttribute
{
public static function keyword(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/AcceptedIf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Spatie\LaravelData\Support\Validation\References\FieldReference;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class AcceptedIf extends StringValidationAttribute
{
protected FieldReference $field;
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/ActiveUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class ActiveUrl extends StringValidationAttribute
{
public static function keyword(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/After.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use DateTimeInterface;
use Spatie\LaravelData\Support\Validation\References\FieldReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class After extends StringValidationAttribute
{
public function __construct(protected string|DateTimeInterface|FieldReference $date)
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/AfterOrEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use DateTimeInterface;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class AfterOrEqual extends StringValidationAttribute
{
public function __construct(protected string|DateTimeInterface|RouteParameterReference $date)
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Alpha.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Alpha extends StringValidationAttribute
{
public static function keyword(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/AlphaDash.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class AlphaDash extends StringValidationAttribute
{
public static function keyword(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/AlphaNumeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class AlphaNumeric extends StringValidationAttribute
{
public static function keyword(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Arr;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class ArrayType extends StringValidationAttribute
{
protected array $keys;
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Bail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Bail extends StringValidationAttribute
{
public static function keyword(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Before.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Spatie\LaravelData\Support\Validation\References\FieldReference;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Before extends StringValidationAttribute
{
public function __construct(protected string|DateTimeInterface|RouteParameterReference|FieldReference $date)
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/BeforeOrEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use DateTimeInterface;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class BeforeOrEqual extends StringValidationAttribute
{
public function __construct(protected string | DateTimeInterface|RouteParameterReference $date)
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Attribute;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Between extends StringValidationAttribute
{
public function __construct(protected int|float|RouteParameterReference $min, protected int|float|RouteParameterReference $max)
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/BooleanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class BooleanType extends StringValidationAttribute
{
public static function keyword(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Confirmed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Confirmed extends StringValidationAttribute
{
public static function keyword(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/CurrentPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;
use Spatie\LaravelData\Tests\Fakes\Enums\DummyBackedEnum;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class CurrentPassword extends StringValidationAttribute
{
public function __construct(protected null|string|DummyBackedEnum|RouteParameterReference $guard = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Date extends StringValidationAttribute
{
public static function keyword(): string
Expand Down
4 changes: 2 additions & 2 deletions src/Attributes/Validation/DateEquals.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use DateTimeInterface;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class DateEquals extends StringValidationAttribute
{
public function __construct(protected string | DateTimeInterface|RouteParameterReference $date)
public function __construct(protected string|DateTimeInterface|RouteParameterReference $date)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/DateFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class DateFormat extends StringValidationAttribute
{
public function __construct(protected string $format)
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Different.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Attribute;
use Spatie\LaravelData\Support\Validation\References\FieldReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Different extends StringValidationAttribute
{
protected FieldReference $field;
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Digits.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Attribute;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Digits extends StringValidationAttribute
{
public function __construct(protected int|RouteParameterReference $value)
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/DigitsBetween.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Attribute;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class DigitsBetween extends StringValidationAttribute
{
public function __construct(protected int|RouteParameterReference $min, protected int|RouteParameterReference $max)
Expand Down
19 changes: 10 additions & 9 deletions src/Attributes/Validation/Dimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;
use Spatie\LaravelData\Support\Validation\ValidationPath;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Dimensions extends ObjectValidationAttribute
{
protected BaseDimensions $rule;

public function __construct(
null|int|RouteParameterReference $minWidth = null,
null|int|RouteParameterReference $minHeight = null,
null|int|RouteParameterReference $maxWidth = null,
null|int|RouteParameterReference $maxHeight = null,
null|int|RouteParameterReference $minWidth = null,
null|int|RouteParameterReference $minHeight = null,
null|int|RouteParameterReference $maxWidth = null,
null|int|RouteParameterReference $maxHeight = null,
null|float|string|RouteParameterReference $ratio = null,
null|int|RouteParameterReference $width = null,
null|int|RouteParameterReference $height = null,
null|BaseDimensions $rule = null,
) {
null|int|RouteParameterReference $width = null,
null|int|RouteParameterReference $height = null,
null|BaseDimensions $rule = null,
)
{
$minWidth = $this->normalizePossibleRouteReferenceParameter($minWidth);
$minHeight = $this->normalizePossibleRouteReferenceParameter($minHeight);
$maxWidth = $this->normalizePossibleRouteReferenceParameter($maxWidth);
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Distinct.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\LaravelData\Exceptions\CannotBuildValidationRule;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Distinct extends StringValidationAttribute
{
public const Strict = 'strict';
Expand Down
8 changes: 4 additions & 4 deletions src/Attributes/Validation/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Spatie\LaravelData\Exceptions\CannotBuildValidationRule;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Email extends StringValidationAttribute
{
public const RfcValidation = 'rfc';
Expand All @@ -32,15 +32,15 @@ public static function keyword(): string
public function parameters(): array
{
return collect($this->modes)
->whenEmpty(fn (Collection $modes) => $modes->add(self::RfcValidation))
->filter(fn (string $mode) => in_array($mode, [
->whenEmpty(fn(Collection $modes) => $modes->add(self::RfcValidation))
->filter(fn(string $mode) => in_array($mode, [
self::RfcValidation,
self::NoRfcWarningsValidation,
self::DnsCheckValidation,
self::SpoofCheckValidation,
self::FilterEmailValidation,
]))
->whenEmpty(fn () => throw CannotBuildValidationRule::create("Email validation rule needs at least one valid mode."))
->whenEmpty(fn() => throw CannotBuildValidationRule::create("Email validation rule needs at least one valid mode."))
->all();
}
}
2 changes: 1 addition & 1 deletion src/Attributes/Validation/EndsWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Arr;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class EndsWith extends StringValidationAttribute
{
protected string|array $values;
Expand Down
4 changes: 2 additions & 2 deletions src/Attributes/Validation/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;
use Spatie\LaravelData\Support\Validation\ValidationPath;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Enum extends ObjectValidationAttribute
{
protected EnumRule $rule;
Expand All @@ -16,7 +16,7 @@ public function __construct(string|EnumRule|RouteParameterReference $enum)
{
$this->rule = $enum instanceof EnumRule
? $enum
: new EnumRule((string) $enum);
: new EnumRule((string)$enum);
}

public static function keyword(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Exclude.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Validation\Rules\ExcludeIf;
use Spatie\LaravelData\Support\Validation\ValidationPath;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Exclude extends ObjectValidationAttribute
{
public function __construct(protected ExcludeIf $rule)
Expand Down
7 changes: 4 additions & 3 deletions src/Attributes/Validation/ExcludeIf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
use Spatie\LaravelData\Support\Validation\References\FieldReference;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class ExcludeIf extends StringValidationAttribute
{
protected FieldReference $field;

public function __construct(
string|FieldReference $field,
string|FieldReference $field,
protected string|int|float|bool|BackedEnum|RouteParameterReference $value
) {
)
{
$this->field = $this->parseFieldReference($field);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Attributes/Validation/ExcludeUnless.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
use Spatie\LaravelData\Support\Validation\References\FieldReference;
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class ExcludeUnless extends StringValidationAttribute
{
protected FieldReference $field;

public function __construct(
string|FieldReference $field,
string|FieldReference $field,
protected string|int|float|bool|BackedEnum|RouteParameterReference $value
) {
)
{
$this->field = $this->parseFieldReference($field);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Attributes/Validation/ExcludeWithout.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
use Attribute;
use Spatie\LaravelData\Support\Validation\References\FieldReference;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class ExcludeWithout extends StringValidationAttribute
{
protected FieldReference $field;

public function __construct(
string|FieldReference $field,
) {
)
{
$this->field = $this->parseFieldReference($field);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Spatie\LaravelData\Support\Validation\References\RouteParameterReference;
use Spatie\LaravelData\Support\Validation\ValidationPath;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Exists extends ObjectValidationAttribute
{
protected BaseExists $rule;
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class File extends StringValidationAttribute
{
public static function keyword(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Validation/Filled.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Filled extends StringValidationAttribute
{
public static function keyword(): string
Expand Down
Loading

0 comments on commit 41b9d45

Please sign in to comment.