| 1 | <?php |
||
| 5 | class IntGuesser extends AbstractGuesser implements GuesserInterface |
||
| 6 | { |
||
| 7 | public function supports(array $mapping) |
||
| 13 | |||
| 14 | public function transform($str, array $mapping = null) |
||
| 18 | |||
| 19 | public function fake(array $mapping) |
||
|
|
|||
| 20 | { |
||
| 21 | $min = 0; |
||
| 22 | $max = $this->determineMaxValue($mapping); |
||
| 23 | |||
| 24 | return current($this->fakers)->fake('numberBetween', [$min, $max]); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param array $mapping |
||
| 29 | * |
||
| 30 | * @return int |
||
| 31 | */ |
||
| 32 | private function determineMaxValue(array $mapping) |
||
| 33 | { |
||
| 34 | $defaultMax = 2000000000; |
||
| 35 | |||
| 36 | $lengthUndefined = !isset($mapping['length']); |
||
| 37 | if ($lengthUndefined) { |
||
| 38 | return $defaultMax; |
||
| 39 | } |
||
| 40 | |||
| 41 | $lengthInvalid = $mapping['length'] < 1 |
||
| 42 | || $mapping['length'] >= strlen($defaultMax); |
||
| 43 | if ($lengthInvalid) { |
||
| 44 | return $defaultMax; |
||
| 45 | } |
||
| 46 | |||
| 47 | $maxValue = (int)str_repeat('9', $mapping['length']); |
||
| 48 | |||
| 49 | return $maxValue; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function getName() |
||
| 56 | } |
||
| 57 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.