Mail   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 58
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A replaceTokens() 0 7 1
A tokenReplaceMap() 0 4 1
A __construct() 0 22 3
1
<?php
2
namespace FMUP;
3
4
/**
5
 * Class Mail - PHPMailer decorator
6
 * @package FMUP
7
 * @todo implement a real mail manager system
8
 */
9
class Mail extends \PHPMailer
10
{
11
    private $config;
12
13
    /**
14
     * @param Config\ConfigInterface $config
15
     * @param bool|false $exceptions
16
     */
17 2
    public function __construct(\FMUP\Config\ConfigInterface $config, $exceptions = false)
18
    {
19 2
        parent::__construct($exceptions);
20 2
        $this->config = $config;
21
22 2
        if ($config->get('smtp_serveur') != 'localhost') {
23 2
            $this->IsSMTP();
24
        }
25 2
        $this->IsHTML(true);
26 2
        $this->CharSet = "UTF-8";
27 2
        $this->SMTPAuth = $config->get('smtp_authentification');
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->get('smtp_authentification') can also be of type array or string. However, the property $SMTPAuth is declared as type boolean. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
28 2
        $this->SMTPSecure = $config->get('smtp_secure');
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->get('smtp_secure') can also be of type array. However, the property $SMTPSecure is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
29 2
        $this->SMTPAutoTLS = $config->get('smtp_secure') == 'tls';
30
31 2
        $this->Host = $config->get('smtp_serveur');
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->get('smtp_serveur') can also be of type array. However, the property $Host is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
32 2
        $this->Port = $config->get('smtp_port');
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->get('smtp_port') can also be of type array or string. However, the property $Port is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
33
34 2
        if ($config->get('smtp_authentification')) {
35 1
            $this->Username = $config->get('smtp_username'); // Gmail identifiant
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->get('smtp_username') can also be of type array. However, the property $Username is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
36 1
            $this->Password = $config->get('smtp_password'); // Gmail mot de passe
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->get('smtp_password') can also be of type array. However, the property $Password is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
37
        }
38 2
    }
39
40
    /**
41
     * Remplace tokens in a string
42
     * @param string $message Text to parse
43
     * @param array $tokens Associative array for tokens to replace
44
     * @return string treated message
45
     * @uses self::tokenReplaceMap
46
     */
47 1
    public static function replaceTokens($message = '', array $tokens = array())
48
    {
49 1
        $search = array_keys($tokens);
50 1
        $replace = array_values($tokens);
51 1
        $search = array_map(array(__CLASS__, 'tokenReplaceMap'), $search);
52 1
        return str_replace($search, $replace, $message);
53
    }
54
55
    /**
56
     * Replace map
57
     * @param string $o
58
     * @return string
59
     * @usedby self::replaceTokens
60
     * @SuppressWarnings(PMD.UnusedPrivateMethod)
61
     */
62 1
    private static function tokenReplaceMap($o)
63
    {
64 1
        return "{" . $o . "}";
65
    }
66
}
67