Completed
Pull Request — master (#42)
by Frederik
06:33
created

NotCriterion::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Imap\Request\SearchCriteria;
5
6
/**
7
 * Class NotCriterium
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
    public function __construct(Query $query)
23
    {
24
        if ($query->count() === 0) {
25
            throw new \InvalidArgumentException('NOT criterium expects query with at least one expression');
26
        }
27
28
        $this->query = $query;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function __toString(): string
35
    {
36
        return sprintf(
37
            '(NOT %s)',
38
            (string)$this->query
39
        );
40
    }
41
}