Completed
Pull Request — master (#42)
by Frederik
04:15 queued 01:07
created

Query::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Imap\Request\SearchCriteria;
5
6
/**
7
 * Class SearchCriteria
8
 * @package Genkgo\Mail\Protocol\Imap
9
 */
10
final class Query implements \Countable
11
{
12
    /**
13
     * @var array
14
     */
15
    private $criteria = [];
16
17
    /**
18
     * Query constructor.
19
     * @param array $criteria
20
     */
21 13
    public function __construct(array $criteria = [])
22
    {
23 13
        $this->criteria = $criteria;
24 13
    }
25
26
    /**
27
     * @param CriterionInterface $criterion
28
     * @return Query
29
     */
30 3
    public function with(CriterionInterface $criterion): self
31
    {
32 3
        $clone = clone $this;
33 3
        $clone->criteria[] = $criterion;
34 3
        return $clone;
35
    }
36
37
    /**
38
     * @return string
39
     */
40 6
    public function __toString(): string
41
    {
42 6
        return trim(implode(' ', $this->criteria));
43
    }
44
45
    /**
46
     * @return int
47
     */
48 7
    public function count()
49
    {
50 7
        return count($this->criteria);
51
    }
52
}