FlagCriterion   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 49
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 14 3
A negate() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Imap\Request\SearchCriteria;
5
6
use Genkgo\Mail\Protocol\Imap\Flag;
7
8
final class FlagCriterion implements CriterionInterface
9
{
10
    /**
11
     * @var Flag
12
     */
13
    private $flag;
14
15
    /**
16
     * @var bool
17
     */
18
    private $negate = false;
19
20
    /**
21
     * @param Flag $flag
22
     */
23 4
    public function __construct(Flag $flag)
24
    {
25 4
        $this->flag = $flag;
26 4
    }
27
28
    /**
29
     * @return string
30
     */
31 4
    public function __toString(): string
32
    {
33 4
        $prefix = $this->negate ? 'UN' : '';
34
35 4
        if ($this->flag->isKeyword()) {
36 2
            return \sprintf(
37 2
                '%sKEYWORD %s',
38 2
                $prefix,
39 2
                (string)$this->flag
40
            );
41
        }
42
43 2
        return $prefix . \strtoupper(\substr((string)$this->flag, 1));
44
    }
45
46
    /**
47
     * @param Flag $flag
48
     * @return FlagCriterion
49
     */
50 2
    public static function negate(Flag $flag): self
51
    {
52 2
        $criterion = new self($flag);
53 2
        $criterion->negate = true;
54 2
        return $criterion;
55
    }
56
}
57