| Total Complexity | 5 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class BooleanGuesser extends AbstractGuesser implements GuesserInterface |
||
| 6 | { |
||
| 7 | public function supports(array $mapping) |
||
| 8 | { |
||
| 9 | $mapping = array_merge([ 'type' => null ], $mapping); |
||
| 10 | |||
| 11 | return $mapping['type'] === 'boolean'; |
||
| 12 | } |
||
| 13 | |||
| 14 | public function transform($str, array $mapping = null) |
||
| 15 | { |
||
| 16 | $str = strtolower($str); |
||
| 17 | |||
| 18 | $formats = [ |
||
| 19 | 'active' => true, |
||
| 20 | 'activated' => true, |
||
| 21 | 'enabled' => true, |
||
| 22 | 'disabled' => false, |
||
| 23 | 'true' => true, |
||
| 24 | 'false' => false, |
||
| 25 | 'yes' => true, |
||
| 26 | 'no' => false, |
||
| 27 | '1' => true, |
||
| 28 | '0' => false, |
||
| 29 | ]; |
||
| 30 | |||
| 31 | if (false === array_key_exists($str, $formats)) { |
||
| 32 | throw new \Exception( |
||
| 33 | sprintf( |
||
| 34 | '"%s" is not a supported format. Supported format : [%s].', |
||
| 35 | $str, |
||
| 36 | implode(', ', array_keys($formats)) |
||
| 37 | ) |
||
| 38 | ); |
||
| 39 | } |
||
| 40 | |||
| 41 | return $formats[$str]; |
||
| 42 | } |
||
| 43 | |||
| 44 | public function fake(array $mapping) |
||
| 47 | } |
||
| 48 | |||
| 49 | public function getName() |
||
| 52 | } |
||
| 53 | } |
||
| 54 |