Skip to content

Commit

Permalink
refactor: refer to rule id using static id
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Waldstein committed Jul 31, 2023
1 parent 5a4385b commit de947e6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/Framework/FieldsAPI/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class File extends Field
use Concerns\HasEmailTag;
use Concerns\HasHelpText;
use Concerns\HasLabel;
use Concerns\AllowMultiple;

const TYPE = 'file';

Expand All @@ -30,9 +29,9 @@ class File extends Field
*/
public function maxSize(int $maxSize): File
{
if ($this->hasRule('file')) {
if ($this->hasRule(FileRule::id())) {
/** @var FileRule $rule */
$rule = $this->getRule('file');
$rule = $this->getRule(FileRule::id());
$rule->size($maxSize);
}

Expand All @@ -47,12 +46,12 @@ public function maxSize(int $maxSize): File
*/
public function getMaxSize(): int
{
if (!$this->hasRule('file')) {
if (!$this->hasRule(FileRule::id())) {
return wp_max_upload_size();
}

/** @var FileRule $rule */
$rule = $this->getRule('file');
$rule = $this->getRule(FileRule::id());

return $rule->getSize();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/ValidationRules/Rules/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function size(int $size): ValidationRule

return $this;
}

/**
* @unreleased
**/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Give\Framework\ValidationRules;

use Give\Framework\ValidationRules\Rules\AllowedTypes;
use Give\Framework\ValidationRules\Rules\File;
use Give\ServiceProviders\ServiceProvider;
use Give\Vendors\StellarWP\Validation\ValidationRulesRegistrar;

Expand All @@ -24,8 +23,7 @@ public function register()
public function boot()
{
give(ValidationRulesRegistrar::class)->register(
AllowedTypes::class,
File::class
AllowedTypes::class
);
}
}

0 comments on commit de947e6

Please sign in to comment.