Passed
Push — master ( 1ff8c3...d57d17 )
by Iman
03:06 queued 10s
created

Validator::otherwise()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 10
cc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Imanghafoori\HeyMan\Reactions;
4
5
use Imanghafoori\HeyMan\Core\Reaction;
6
7
final class Validator
8
{
9
    private $validationData;
10
11
    private $modifier;
12
13 9
    public function __construct(array $validationData)
14
    {
15 9
        $this->validationData = $validationData;
16 9
    }
17
18 1
    public function otherwise()
19
    {
20 1
        $rules = $this->validationData;
21 1
        $modifier = $this->modifier ?: function ($args) {
22 1
            return $args;
23 1
        };
24
25 1
        $result = resolve(ResponderFactory::class)->validationPassesCallback($modifier, $rules);
26
27 1
        resolve('heyman.chain')->set('condition', $result);
0 ignored issues
show
Bug introduced by
The method set() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

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

27
        resolve('heyman.chain')->/** @scrutinizer ignore-call */ set('condition', $result);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
29 1
        return resolve(Reaction::class);
30
    }
31
32 1
    public function beforeValidationModifyData($callable)
33
    {
34 1
        $this->modifier = $callable;
35 1
    }
36
37 8
    public function __destruct()
38
    {
39
        try {
40 8
            $chain = app('heyman.chain');
41 8
            $condition = $chain->get('condition');
42
43 8
            if (! $condition) {
44 8
                $data = $this->validationData;
45 8
                $modifier = $this->modifier ?: function ($args) {
46 4
                    return $args;
47 8
                };
48
49 8
                $condition = resolve(ResponderFactory::class)->validatorCallback($modifier, $data);
50 8
                $chain->set('condition', $condition);
51
            }
52
53 8
            resolve('heyman.chains')->commitChain();
0 ignored issues
show
Bug introduced by
The method commitChain() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

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

53
            resolve('heyman.chains')->/** @scrutinizer ignore-call */ commitChain();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
        } catch (\Throwable $throwable) {
55
            //
56
        }
57 8
    }
58
}
59