Gravatar::setEmailHash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\widgets;
12
13
class Gravatar extends \cebe\gravatar\Gravatar
14
{
15
    public $defaultImage = 'identicon';
16
17
    public $rating = 'pg';
18
19
    protected $_emailHash;
20
21
    public function setEmailHash($hash)
22
    {
23
        $this->_emailHash = $hash;
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function getEmailHash()
30
    {
31
        if (!$this->_emailHash) {
32
            $this->_emailHash = self::hashEmail($this->email);
33
        }
34
35
        return $this->_emailHash;
36
    }
37
38
    public static function hashEmail($email)
39
    {
40
        $email = strtolower(trim($email));
41
42
        return strpos($email, '@') === false ? $email : md5($email);
43
    }
44
45
    public function run()
46
    {
47
        if (!$this->emailHash) {
0 ignored issues
show
Bug introduced by
The property emailHash does not seem to exist. Did you mean _emailHash?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
48
            $this->defaultImage = '';
49
        }
50
51
        return parent::run();
52
    }
53
}
54