-
-
Notifications
You must be signed in to change notification settings - Fork 837
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 696f6fd
Showing
2 changed files
with
140 additions
and
9 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,114 @@ | ||
<?php | ||
|
||
namespace Flarum\Tags; | ||
|
||
use Flarum\Foundation\AbstractValidator; | ||
|
||
class TagCountValidator extends AbstractValidator | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $type; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $min; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $max; | ||
|
||
// /** | ||
// * @var int | ||
// */ | ||
// protected $count; | ||
|
||
/** | ||
* @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; | ||
} | ||
|
||
// /** | ||
// * @return int | ||
// */ | ||
// protected function getCount() | ||
// { | ||
// return $this->count; | ||
// } | ||
|
||
// /** | ||
// * @param int $count | ||
// * @return void | ||
// */ | ||
// public function setCount($count) | ||
// { | ||
// $this->count = $count; | ||
// } | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getRules() | ||
{ | ||
$type = $this->type; | ||
$min = $this->min; | ||
$max = $this->max; | ||
|
||
return [ | ||
'tag_count_'.$type => [ | ||
'numeric', | ||
'size:'.$min, | ||
'between:'.$min,$max | ||
] | ||
]; | ||
} | ||
} |