AbstractText::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Ddeboer\Imap\Search\Text;
4
5
use Ddeboer\Imap\Search\AbstractCondition;
6
7
/**
8
 * Represents a text based condition. Text based conditions use a contains
9
 * restriction.
10
 */
11
abstract class AbstractText extends AbstractCondition
12
{
13
    /**
14
     * Text to be used for the condition.
15
     *
16
     * @var string
17
     */
18
    protected $text;
19
20
    /**
21
     * Constructor.
22
     *
23
     * @param string $text Optional text for the condition.
24
     */
25
    public function __construct($text = null)
26
    {
27
        if (!is_null($text) && strlen($text) > 0) {
28
            $this->setText($text);
29
        }
30
    }
31
32
    /**
33
     * Sets the text for the condition.
34
     *
35
     * @param string $text
36
     */
37
    public function setText($text)
38
    {
39
        $this->text = $text;
40
    }
41
42
    /**
43
     * Converts the condition to a string that can be sent to the IMAP server.
44
     *
45
     * @return string
46
     */
47
    public function __toString()
48
    {
49
        return $this->getKeyword() . ' "' . str_replace('"', '\\"', $this->text) . '"';
50
    }
51
}
52