Completed
Pull Request — master (#152)
by
unknown
05:44
created

MailerConfiguration::setEncrypt()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.2
c 0
b 0
f 0
cc 4
eloc 4
nc 2
nop 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 * 
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 * 
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\CoreBundle\Entity;
14
15
/**
16
 * Class MailerConfiguration
17
 *
18
 * @author  Adam Piotrowski <[email protected]>
19
 */
20
class MailerConfiguration
21
{
22
    protected $from = '';
23
    protected $host = '';
24
    protected $port = 587;
25
    protected $encrypt = 'tls';
26
    protected $user = '';
27
    protected $pass = '';
28
    protected $bcc  = '';
29
    
30
    public function getFrom(): string
31
    {
32
        return $this->from;
33
    }
34
    
35
    public function setFrom(string $from)
36
    {
37
        $this->from = $from;
38
    }
39
    
40
    public function getHost(): string
41
    {
42
        return $this->host;
43
    }
44
    
45
    public function setHost(string $host)
46
    {
47
        $this->host = $host;
48
    }
49
    
50
    public function getPort(): int
51
    {
52
        return $this->port;
53
    }
54
    
55
    public function setPort(int $port)
56
    {
57
        $this->port = $port;
58
    }
59
    
60
    public function getUser(): string
61
    {
62
        return $this->user;
63
    }
64
    
65
    public function setUser(string $user)
66
    {
67
        $this->user = $user;
68
    }
69
    
70
    public function getPass(): string
71
    {
72
        return $this->pass;
73
    }
74
    
75
    public function setPass(string $pass)
76
    {
77
        $this->pass = $pass;
78
    }
79
    
80
    public function getBcc(): string
81
    {
82
        return $this->bcc;
83
    }
84
    
85
    public function setBcc(string $bcc)
86
    {
87
        $this->bcc = $bcc;
88
    }
89
90
    public function getEncrypt() : mixed
91
    {
92
        return $this->encrypt;
93
    }
94
95
    public function setEncrypt(mixed $encrypt)
96
    {
97
        if(!$encrypt or ($encrypt != 'ssl' and $encrypt != 'tls')){
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
98
            $encrypt = null;
99
        }
100
101
        $this->encrypt = $encrypt;
0 ignored issues
show
Documentation Bug introduced by
It seems like $encrypt can also be of type object<WellCommerce\Bund...oreBundle\Entity\mixed>. However, the property $encrypt 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...
102
    }
103
104
105
}
106