LogicalAssertion   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertion() 0 16 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