AbstractEmail   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A setEmail() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace Ddeboer\Imap\Search\Email;
4
5
use Ddeboer\Imap\Search\AbstractCondition;
6
7
/**
8
 * Represents an email condition.
9
 */
10
abstract class AbstractEmail extends AbstractCondition
11
{
12
    /**
13
     * Email address for the condition.
14
     *
15
     * @var string
16
     */
17
    protected $email;
18
19
    /**
20
     * Constructor
21
     *
22
     * @param string $email Optional email address for the condition.
23
     */
24
    public function __construct($email = null)
25
    {
26
        if ($email) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $email of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
27
            $this->setEmail($email);
28
        }
29
    }
30
31
    /**
32
     * Sets the email address for the condition.
33
     *
34
     * @param string $email
35
     */
36
    public function setEmail($email)
37
    {
38
        $this->email = $email;
39
    }
40
41
    /**
42
     * Converts the condition to a string that can be sent to the IMAP server.
43
     *
44
     * @return string
45
     */
46
    public function __toString()
47
    {
48
        return $this->getKeyword() . ' "' . $this->email . '"';
49
    }
50
}
51