getDefaultOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
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
    /**
32
     * @return mixed|NULL
33
     */
34
    protected function _validate()
35
    {
36
        $args = $this->getArrayOption('arguments');
37
        array_unshift($args, $this->value);
38
        
39
        $result = call_user_func_array($this->getOption('callback'), $args);
0 ignored issues
show
Bug introduced by
It seems like $this->getOption('callback') can also be of type null; however, parameter $callback of call_user_func_array() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        $result = call_user_func_array(/** @scrutinizer ignore-type */ $this->getOption('callback'), $args);
Loading history...
40
        if($result !== false) {
41
            return $this->value;
42
        }
43
        
44
        return null;
45
    }
46
}
47