LogicalAssertion::assertion()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.2
cc 4
eloc 9
nc 4
nop 2
crap 4
1
<?php
2
/**
3
 * @author Sergii Bondarenko, <[email protected]>
4
 */
5
namespace Drupal\TqExtension\Utils;
6
7
/**
8
 * Trait LogicalAssertion.
9
 *
10
 * @package Drupal\TqExtension\Utils
11
 */
12
trait LogicalAssertion
13
{
14
    /**
15
     * @param mixed $value
16
     *   Value to check.
17
     * @param bool $negate
18
     *   Negate the condition.
19
     *
20
     * @return int
21
     *   - 0: Everything is fine.
22
     *   - 1: Value is found, but should not be.
23
     *   - 2: Value is not found, but should be.
24
     */
25 16
    public static function assertion($value, $negate)
26
    {
27 16
        $negate = (bool) $negate;
28
29 16
        if ($value) {
30 8
            if ($negate) {
31 4
                return 1;
32
            }
33 4
        } else {
34 8
            if (!$negate) {
35 4
                return 2;
36
            }
37
        }
38
39 8
        return 0;
40
    }
41
}
42