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

NotCriterion::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1
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
}