MailHelper::getMailboxHash()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Helper;
13
14
use Jitamin\Foundation\Base;
15
16
/**
17
 * Class MailHelper.
18
 */
19
class MailHelper extends Base
20
{
21
    /**
22
     * Get the mailbox hash from an email address.
23
     *
24
     * @param string $email
25
     *
26
     * @return string
27
     */
28
    public function getMailboxHash($email)
29
    {
30
        if (!strpos($email, '@') || !strpos($email, '+')) {
31
            return '';
32
        }
33
34
        list($localPart) = explode('@', $email);
35
        list(, $identifier) = explode('+', $localPart);
36
37
        return $identifier;
38
    }
39
40
    /**
41
     * Filter mail subject.
42
     *
43
     * @param string $subject
44
     *
45
     * @return string
46
     */
47
    public function filterSubject($subject)
48
    {
49
        $subject = str_replace('RE: ', '', $subject);
50
        $subject = str_replace('FW: ', '', $subject);
51
52
        return $subject;
53
    }
54
55
    /**
56
     * Get mail sender address.
57
     *
58
     * @return string
59
     */
60
    public function getMailSenderAddress()
61
    {
62
        $email = $this->settingModel->get('mail_sender_address');
0 ignored issues
show
Documentation introduced by
The property settingModel does not exist on object<Jitamin\Helper\MailHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
63
64
        if (!empty($email)) {
65
            return $email;
66
        }
67
68
        return MAIL_FROM;
69
    }
70
71
    /**
72
     * Get mail sender address.
73
     *
74
     * @return string
75
     */
76
    public function getMailTransport()
77
    {
78
        $transport = $this->settingModel->get('mail_transport');
0 ignored issues
show
Documentation introduced by
The property settingModel does not exist on object<Jitamin\Helper\MailHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
79
80
        if (!empty($transport)) {
81
            return $transport;
82
        }
83
84
        return MAIL_TRANSPORT;
85
    }
86
}
87