Passed
Push — master ( 42367a...08368b )
by Sebastian
02:40
created

Request_Param_Validator_Callback::_validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * File containing the {@link Request_Param_Validator_Callback} class.
4
 *
5
 * @package Application Utils
6
 * @subpackage Request
7
 * @see Request_Param_Validator_Callback
8
 */
9
10
declare(strict_types=1);
11
12
namespace AppUtils;
13
14
/**
15
 * Validates a string containing only letters, lowercase and uppercase, and numbers.
16
 *
17
 * @package Application Utils
18
 * @subpackage Request
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Request_Param_Validator_Callback extends Request_Param_Validator
22
{
23
    public function getDefaultOptions() : array
24
    {
25
        return array(
26
            'arguments' => array(),
27
            'callback' => null
28
        );
29
    }
30
    
31
    protected function _validate()
32
    {
33
        $args = $this->getArrayOption('arguments');
34
        array_unshift($args, $this->value);
35
        
36
        $result = call_user_func_array($this->getOption('callback'), $args);
37
        if($result !== false) {
38
            return $this->value;
39
        }
40
        
41
        return null;
42
    }
43
}
44