Passed
Push — master ( 3c388a...58b85c )
by Sebastian
05:02
created

Request_RefreshParams_Exclude_Callback   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
A isExcluded() 0 3 1
1
<?php
2
/**
3
 * File containing the {@link Request_RefreshParams_Exclude_Callback} class.
4
 * @package Application Utils
5
 * @subpackage Request
6
 * @see Request_RefreshParams_Exclude_Callback
7
 */
8
9
declare(strict_types=1);
10
11
namespace AppUtils;
12
13
/**
14
 * Excludes a request parameter by matching its name to 
15
 * a callback function.
16
 *
17
 * @package Application Utils
18
 * @subpackage Request
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Request_RefreshParams_Exclude_Callback extends Request_RefreshParams_Exclude
22
{
23
    const ERROR_INVALID_CALLBACK = 62101;
24
    
25
   /**
26
    * @var callable
27
    */
28
    private $callback;
29
    
30
    public function __construct($callback)
31
    {
32
        if(!is_callable($callback))
33
        {
34
            throw new Request_Exception(
35
                'Invalid exclusion callback',
36
                sprintf(
37
                    'The variable [%s] is not a valid callback.',
38
                    parseVariable($callback)->enableType()->toString()
39
                ),
40
                self::ERROR_INVALID_CALLBACK
41
            );
42
        }
43
        
44
        $this->callback = $callback;
45
    }
46
    
47
    public function isExcluded(string $paramName, $paramValue): bool
48
    {
49
        return call_user_func($this->callback, $paramName, $paramValue) === true;
50
    }
51
}
52