-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract tag count validation logic
- Loading branch information
1 parent
19ffca7
commit 3e8aba9
Showing
3 changed files
with
119 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Tags; | ||
|
||
use Flarum\Foundation\AbstractValidator; | ||
|
||
class TagCountValidator extends AbstractValidator | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $type; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $min; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $max; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getType() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* @return void | ||
*/ | ||
public function setType($type) | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
protected function getMin() | ||
{ | ||
return $this->min; | ||
} | ||
|
||
/** | ||
* @param int $min | ||
* @return void | ||
*/ | ||
public function setMin($min) | ||
{ | ||
$this->min = $min; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
protected function getMax() | ||
{ | ||
return $this->max; | ||
} | ||
|
||
/** | ||
* @param int $max | ||
* @return void | ||
*/ | ||
public function setMax($max) | ||
{ | ||
$this->max = $max; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getRules() | ||
{ | ||
$type = $this->type; | ||
$min = $this->min; | ||
$max = $this->max; | ||
|
||
return [ | ||
"tag_count_{$type}" => [ | ||
'numeric', | ||
"size:{$min}", | ||
"between:{$min},{$max}" | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters