Passed
Push — master ( b2d39c...538fe0 )
by Stephen
01:06 queued 11s
created

ApplyWhen::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
cc 3
nc 4
nop 2
crap 3
1
<?php
2
3
namespace Monooso\Apposite\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class ApplyWhen extends ApplyMap implements Rule
8
{
9
    /**
10
     * Initialise the custom rule
11
     *
12
     * @param bool|callable $conditional
13
     * @param array|string  $rules
14
     */
15 5
    public function __construct($conditional, $rules)
16
    {
17 5
        $key = 'when';
18
19 5
        (bool)(is_callable($conditional) ? $conditional() : $conditional)
20 4
            ? parent::__construct($key, [$key => $rules])
21 1
            : parent::__construct($key, []);
22 5
    }
23
}
24