Completed
Push — 5.x ( 4f2fea...f62ac5 )
by Lars
04:38
created

Swift_Mime_IdGenerator::setIdRight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of SwiftMailer.
5
 * (c) 2004-2009 Chris Corbyn
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
/**
12
 * Message ID generator.
13
 */
14
class Swift_Mime_IdGenerator implements Swift_IdGenerator
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
15
{
16
    /**
17
     * @param string $idRight
18
     */
19
    public function __construct($idRight)
20
    {
21
        $this->idRight = $idRight;
0 ignored issues
show
Bug introduced by
The property idRight does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
    }
23
24
    /**
25
     * Returns the right-hand side of the "@" used in all generated IDs.
26
     *
27
     * @return string
28
     */
29
    public function getIdRight()
30
    {
31
        return $this->idRight;
32
    }
33
34
    /**
35
     * Sets the right-hand side of the "@" to use in all generated IDs.
36
     *
37
     * @param string $idRight
38
     */
39
    public function setIdRight($idRight)
40
    {
41
        $this->idRight = $idRight;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function generateId()
48
    {
49
        $idLeft = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
50
51
        return $idLeft.'@'.$this->idRight;
52
    }
53
}
54