Completed
Push — master ( 3c8880...e2c218 )
by Dmitry
06:42 queued 02:46
created

Gravatar   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 37
ccs 0
cts 22
cp 0
rs 10
wmc 7
lcom 2
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setEmailHash() 0 4 1
A run() 0 7 2
A getEmailHash() 0 8 2
A hashEmail() 0 5 2
1
<?php
2
3
/*
4
 * HiPanel core package
5
 *
6
 * @link      https://hipanel.com/
7
 * @package   hipanel-core
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\widgets;
13
14
class Gravatar extends \cebe\gravatar\Gravatar
15
{
16
    public $defaultImage = 'identicon';
17
18
    protected $_emailHash;
19
20
    public function setEmailHash($hash)
21
    {
22
        $this->_emailHash = $hash;
23
    }
24
25
    /**
26
     * @return string
27
     */
28
    public function getEmailHash()
29
    {
30
        if (!$this->_emailHash) {
31
            $this->_emailHash = self::hashEmail($this->email);
32
        }
33
34
        return $this->_emailHash;
35
    }
36
37
    public static function hashEmail($email)
38
    {
39
        $email = strtolower(trim($email));
40
        return strpos($email, '@') === false ? $email : md5($email);
41
    }
42
43
    public function run()
44
    {
45
        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...
46
            $this->defaultImage = '';
47
        }
48
        return parent::run();
49
    }
50
}
51