ProcessCallback   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 19
ccs 7
cts 7
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 4 2
A checkValue() 0 6 2
1
<?php
2
3
namespace kalanis\kw_rules\Rules;
4
5
6
use kalanis\kw_rules\Interfaces\IValidate;
7
use kalanis\kw_rules\Exceptions\RuleException;
8
9
10
/**
11
 * Class ProcessCallback
12
 * @package kalanis\kw_rules\Rules
13
 * Check if input is accepted by callback
14
 */
15
class ProcessCallback extends ARule
16
{
17
    /**
18
     * @param mixed $againstValue
19
     * @throws RuleException
20
     * @return callable
21
     */
22 9
    protected function checkValue($againstValue)
23
    {
24 9
        if (!is_callable($againstValue)) {
25 4
            throw new RuleException('Not callable. Need set call which returns boolean or throws RuleException!');
26
        }
27 5
        return $againstValue;
28
    }
29
30 11
    public function validate(IValidate $entry): void
31
    {
32 11
        if (!call_user_func(/** @scrutinizer ignore-type */ $this->againstValue, $entry->getValue())) {
33 6
            throw new RuleException($this->errorText);
34
        }
35 6
    }
36
}
37