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

Request_Param_Validator_Valueslist   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultOptions() 0 4 1
A _validate() 0 14 4
1
<?php
2
/**
3
 * File containing the {@link Request_Param_Validator_Valueslist} class.
4
 *
5
 * @package Application Utils
6
 * @subpackage Request
7
 * @see Request_Param_Validator_Valueslist
8
 */
9
10
declare(strict_types=1);
11
12
namespace AppUtils;
13
14
/**
15
 * Makes sure that the value is an array.
16
 *
17
 * @package Application Utils
18
 * @subpackage Request
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Request_Param_Validator_Valueslist extends Request_Param_Validator
22
{
23
    public function getDefaultOptions() : array
24
    {
25
        return array(
26
            'values' => array()
27
        );
28
    }
29
    
30
    protected function _validate()
31
    {
32
        if(!is_array($this->value)) {
33
            return array();
34
        }
35
        
36
        $keep = array();
37
        foreach($this->value as $item) {
38
            if(in_array($item, $this->getArrayOption('values'))) {
39
                $keep[] = $item;
40
            }
41
        }
42
        
43
        return $keep;
44
    }
45
}
46