Completed
Pull Request — master (#42)
by Frederik
02:26
created

NotCriterion::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Imap\Request\SearchCriteria;
5
6
/**
7
 * Class NotCriterion
8
 * @package Genkgo\Mail\Protocol\Imap\Request\SearchCriteria
9
 */
10
final class NotCriterion implements CriterionInterface
11
{
12
13
    /**
14
     * @var Query
15
     */
16
    private $query;
17
18
    /**
19
     * OrCriterium constructor.
20
     * @param Query $query
21
     */
22 2
    public function __construct(Query $query)
23
    {
24 2
        if ($query->count() === 0) {
25 1
            throw new \InvalidArgumentException('NOT criterium expects query with at least one expression');
26
        }
27
28 1
        $this->query = $query;
29 1
    }
30
31
    /**
32
     * @return string
33
     */
34 1
    public function __toString(): string
35
    {
36 1
        return sprintf(
37 1
            '(NOT %s)',
38 1
            (string)$this->query
39
        );
40
    }
41
}