Skip to content

Commit

Permalink
pass attribute to methods even though we aren't using it now
Browse files Browse the repository at this point in the history
  • Loading branch information
miken32 committed Oct 23, 2023
1 parent 473ed1c commit e4dfda2
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 18 deletions.
9 changes: 5 additions & 4 deletions src/Rules/BaseRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function extend(string $attribute, string $value, array $parameters, Vali
static::class
);

return $this->doValidation($value, ...$parameters);
return $this->doValidation($attribute, $value, ...$parameters);
}

/**
Expand All @@ -66,7 +66,7 @@ public function setValidator($validator): static
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (!$this->doValidation($value)) {
if (!$this->doValidation($attribute, $value)) {
$fail($this->message());
}
}
Expand All @@ -80,7 +80,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
*/
public function passes($attribute, $value): bool
{
return $this->doValidation($value);
return $this->doValidation($attribute, $value);
}

/**
Expand All @@ -101,11 +101,12 @@ public function replace(string $message, string $attribute, string $rule, array
/**
* Do the actual validation; used by both instance and extend methods
*
* @param string $attribute
* @param string $value the value to be checked
* @param mixed ...$parameters for string methods, the paramater array
* @return bool
*/
abstract public function doValidation(string $value, ...$parameters): bool;
abstract public function doValidation(string $attribute, string $value, ...$parameters): bool;

/**
* Return the validation error message
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/InNetwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(string|array|null $network = null)
$this->networks = Arr::wrap($network);
}

public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
if ($this->extended) {
$this->networks = $parameters;
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/IpOrNet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class IpOrNet extends BaseRule
{
public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
return Util::validIPAddress($value) || Util::validIPNetwork($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Netv4.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
{
}

public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
if ($this->extended) {
// called by string method
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Netv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(
{
}

public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
if ($this->extended) {
// called by string method
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/PrivateIp.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class PrivateIp extends BaseRule
{
public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
return Util::validPrivateIPAddress($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/PrivateIpv4.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class PrivateIpv4 extends BaseRule
{
public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
return Util::validPrivateIPv4Address($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/PrivateIpv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class PrivateIpv6 extends BaseRule
{
public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
return Util::validPrivateIPv6Address($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/PrivateNet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class PrivateNet extends BaseRule
{
public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
return Util::validPrivateIPNetwork($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RoutableIp.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class RoutableIp extends BaseRule
{
public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
return Util::validRoutableIPAddress($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RoutableIpv4.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class RoutableIpv4 extends BaseRule
{
public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
return Util::validRoutableIPv4Address($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RoutableIpv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class RoutableIpv6 extends BaseRule
{
public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
return Util::validRoutableIPv6Address($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RoutableNet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class RoutableNet extends BaseRule
{
public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
return Util::validRoutableIPNetwork($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RoutableNetv4.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(
{
}

public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
if ($this->extended) {
// called by string method
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/RoutableNetv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(
{
}

public function doValidation(string $value, ...$parameters): bool
public function doValidation(string $attribute, string $value, ...$parameters): bool
{
if ($this->extended) {
// called by string method
Expand Down

0 comments on commit e4dfda2

Please sign in to comment.