| Total Complexity | 7 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class text extends base |
||
| 13 | { |
||
| 14 | /** @var int */ |
||
| 15 | protected $maxlength = 0; |
||
| 16 | |||
| 17 | 8 | /** |
|
| 18 | * @inheritdoc |
||
| 19 | 8 | */ |
|
| 20 | public function get_name() |
||
| 21 | { |
||
| 22 | return 'text'; |
||
| 23 | } |
||
| 24 | |||
| 25 | 5 | /** |
|
| 26 | * @inheritdoc |
||
| 27 | */ |
||
| 28 | 5 | public function get_default_props() |
|
| 29 | 5 | { |
|
| 30 | 5 | return array( |
|
| 31 | 'maxlength' => 255, |
||
| 32 | 'size' => 40, |
||
| 33 | ); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @inheritdoc |
||
| 38 | */ |
||
| 39 | public function get_validation_rules(array $data) |
||
| 40 | { |
||
| 41 | $this->maxlength = $data['field_props']['maxlength']; |
||
| 42 | |||
| 43 | return array( |
||
| 44 | 'filter' => FILTER_CALLBACK, |
||
| 45 | 'options' => array( |
||
| 46 | 'options' => array($this, 'is_valid'), |
||
| 47 | ), |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param string $value |
||
| 53 | * @return false|string |
||
| 54 | */ |
||
| 55 | protected function is_valid($value) |
||
| 56 | { |
||
| 57 | if ($this->maxlength && utf8_strlen($value) > $this->maxlength) |
||
|
|
|||
| 58 | { |
||
| 59 | return false; |
||
| 60 | } |
||
| 61 | |||
| 62 | return $value; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @inheritdoc |
||
| 67 | */ |
||
| 68 | public function get_error_message(array $data) |
||
| 71 | } |
||
| 72 | } |
||
| 73 |