forked from Smile-SA/gdpr-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberBetween.php
50 lines (41 loc) · 1.17 KB
/
NumberBetween.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
namespace Smile\GdprDump\Converter\Generator;
use Smile\GdprDump\Converter\ConverterInterface;
use Smile\GdprDump\Converter\Parameters\Parameter;
use Smile\GdprDump\Converter\Parameters\ParameterProcessor;
use Smile\GdprDump\Converter\Parameters\ValidationException;
class NumberBetween implements ConverterInterface
{
/**
* @var int
*/
private $min;
/**
* @var int
*/
private $max;
/**
* @param array $parameters
* @throws ValidationException
*/
public function __construct(array $parameters = [])
{
$input = (new ParameterProcessor())
->addParameter('min', Parameter::TYPE_INT, true)
->addParameter('max', Parameter::TYPE_INT, true)
->process($parameters);
$this->min = $input->get('min');
$this->max = $input->get('max');
if ($this->min > $this->max) {
throw new ValidationException('The parameter "min" must be lower than the parameter "max".');
}
}
/**
* @inheritdoc
*/
public function convert($value, array $context = [])
{
return mt_rand($this->min, $this->max);
}
}